private byte[] CreateSaslInitMessage(SaslInit init)
        {
            init.HostName = _hostName;
            var responseBuffer = new byte[_endorsementKey.Length + 1];

            responseBuffer[0] = 0x0;
            Buffer.BlockCopy(_endorsementKey, 0, responseBuffer, 1, _endorsementKey.Length);
            return(responseBuffer);
        }
Esempio n. 2
0
            protected override DescribedList OnCommand(DescribedList command)
            {
                if (command.Descriptor.Code == Codec.SaslInit.Code)
                {
                    SaslInit init = (SaslInit)command;
                    SaslCode code = this.ValidateCredentials(init);
                    return(new SaslOutcome()
                    {
                        Code = code
                    });
                }

                throw new AmqpException(ErrorCode.NotAllowed, command.ToString());
            }
        private byte[] CreateSaslInitMessage(SaslInit init)
        {
            init.HostName = _hostName;
            var initContent = new StringBuilder();

            initContent.Append(_idScope);
            initContent.Append('\0');
            initContent.Append(_security.GetRegistrationID());
            initContent.Append('\0');

            byte[] initContentInBytes = Encoding.UTF8.GetBytes(initContent.ToString());

            byte[] responseBuffer = new byte[initContentInBytes.Length + _endorsementKey.Length + 1];
            responseBuffer[0] = 0x0;
            Buffer.BlockCopy(initContentInBytes, 0, responseBuffer, 1, initContentInBytes.Length);
            Buffer.BlockCopy(_endorsementKey, 0, responseBuffer, initContentInBytes.Length + 1, _endorsementKey.Length);
            return(responseBuffer);
        }
Esempio n. 4
0
            SaslCode ValidateCredentials(SaslInit init)
            {
                byte[] response = init.InitialResponse;
                if (response.Length > 0)
                {
                    string   message = Encoding.UTF8.GetString(response, 0, response.Length);
                    string[] items   = message.Split('\0');
                    if (items.Length == 3 &&
                        string.Equals(this.mechanism.user, items[1], StringComparison.OrdinalIgnoreCase) &&
                        string.Equals(this.mechanism.password, items[2], StringComparison.Ordinal))
                    {
                        this.Principal = new GenericPrincipal(
                            new GenericIdentity(string.IsNullOrEmpty(items[2]) ? items[0] : items[2], this.mechanism.Name),
                            new string[0]);

                        return(SaslCode.Ok);
                    }
                }

                return(SaslCode.Auth);
            }
Esempio n. 5
0
 private void SendSaslInitMessage(SaslInit init)
 {
     init.InitialResponse = new ArraySegment <byte>(CreateSaslInitMessage(init));
     Negotiator.WriteFrame(init, true);
 }
Esempio n. 6
0
 protected override void OnStart(SaslInit init, bool isClient)
 {
     Debug.Assert(isClient);
     SendSaslInitMessage(init);
 }