/// <summary>
        /// Process the SASL reponse message.
        /// </summary>
        /// <param name="response">The server reponse</param>
        /// <returns>
        /// The client response.
        /// </returns>
        /// <exception cref="XmppException">
        /// SASL Authrization failed. Incorrect challenge received from server
        /// or
        /// SASL Authrization failed. Incorrect challenge received from server
        /// or
        /// SASL Authrization failed. Incorrect challenge received from server
        /// </exception>
        public SaslResponse ProcessResponse(SaslResponse response)
        {
            // Verify received Digest-Challenge

            // Check that the nonce setting is pressent
            if (!this.digestChallenge.ContainsKey("nonce"))
            {
                throw new XmppException("SASL Authrization failed. Incorrect challenge received from server");
            }

            // Check that the charset is correct
            if (this.digestChallenge.ContainsKey("charset") &&
                this.digestChallenge["charset"] != "utf-8")
            {
                throw new XmppException("SASL Authrization failed. Incorrect challenge received from server");
            }

            // Check that the mechanims is correct
            if (!this.digestChallenge.ContainsKey("algorithm") ||
                this.digestChallenge["algorithm"] != "md5-sess")
            {
                throw new XmppException("SASL Authrization failed. Incorrect challenge received from server");
            }

            return(new SaslResponse {
                Value = this.BuildDigestRespose()
            });
        }
示例#2
0
        private void SendStorageRootKey()
        {
            var response = new SaslResponse {
                Response = new ArraySegment <byte>(CreateStorageRootKeyMessage())
            };

            Negotiator.WriteFrame(response, true);
        }
示例#3
0
        private void SendInterimResponse()
        {
            var response = new SaslResponse {
                Response = new ArraySegment <byte>(EmptyByte)
            };

            Negotiator.WriteFrame(response, true);
        }
        private void SendLastResponse()
        {
            //Notes: The _encodedNonce from service would soon change to non base64 string
            var sasBytes = _security.Sign(Convert.FromBase64String(_encodedNonceStringBuilder.ToString()));
            var sas      = Convert.ToBase64String(sasBytes);

            var responseBuffer = new byte[sas.Length + 1];

            responseBuffer[0] = 0x0;
            Buffer.BlockCopy(Encoding.UTF8.GetBytes(sas), 0, responseBuffer, 1, sas.Length);

            var response = new SaslResponse {
                Response = new ArraySegment <byte>(responseBuffer)
            };

            Negotiator.WriteFrame(response, true);
        }
        private void SendLastResponse()
        {
            string sas = ProvisioningSasBuilder.ExtractServiceAuthKey(
                _security,
                _hostName,
                _nonceBuffer);

            byte[] responseBuffer = new byte[sas.Length + 1];
            responseBuffer[0] = 0x0;
            Buffer.BlockCopy(Encoding.UTF8.GetBytes(sas), 0, responseBuffer, 1, sas.Length);

            var response = new SaslResponse {
                Response = new ArraySegment <byte>(responseBuffer)
            };

            Negotiator.WriteFrame(response, true);
        }
示例#6
0
 public override void OnResponse(SaslResponse response)
 {
     //This method is only implemented on the server
     Debug.Fail("OnResponse is not implemented on client");
 }
示例#7
0
 /// <summary>
 /// Process the SASL reponse message.
 /// </summary>
 /// <param name="response">The server reponse</param>
 /// <returns>
 /// The client response.
 /// </returns>
 public SaslResponse ProcessResponse(SaslResponse response)
 {
     return(null);
 }
示例#8
0
文件: XMPP.cs 项目: remobjects/ipxmpp
        private Element CreateNode(XmlNodeResult nd, Element parent)
        {
            string ens;

            if (nd.Prefix != null)
            {
                RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == "xmlns" && a.Name == nd.Prefix);
                if (at == null)
                {
                    Element el = parent;
                    ens = string.Empty;
                    while (el != null)
                    {
                        RemObjects.InternetPack.XMPP.Elements.Attribute els = el.Attributes.Where(a => a.Prefix == "xmlns" && a.Name == nd.Prefix).FirstOrDefault();
                        if (els != null)
                        {
                            ens = els.Value;
                            break;
                        }
                        el = el.Parent;
                    }
                }
                else
                {
                    ens = at.Value;
                }
            }
            else
            {
                RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns");
                if (at == null)
                {
                    ens = string.Empty;
                }
                else
                {
                    ens = at.Value;
                }
            }
            Element res = null;

            switch (ens)
            {
            case Namespaces.ClientStreamNamespace:
            case Namespaces.ServerStreamNamespace:
            case "":
                if (ens == null && parent != null && parent.Type == ElementType.IQ && nd.Name == "error")
                {
                    res = new IQError();
                }
                else
                {
                    switch (nd.Name)
                    {
                    case "iq":
                        res = new IQ();
                        break;

                    case "presence":
                        res = new Presence();
                        break;

                    case "message":
                        res = new Message();
                        break;
                    }
                }
                break;

            case Namespaces.StreamNamespace:
                switch (nd.Name)
                {
                case "stream":

                    RemObjects.InternetPack.XMPP.Elements.Attribute att = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns");
                    if (att == null || att.Value == Namespaces.ClientStreamNamespace)
                    {
                        res = new ClientStream();
                    }
                    else
                    {
                        res = new ServerStream();
                    }
                    break;

                case "features":
                    res = new StreamFeatures();
                    break;

                case "error":
                    res = new StreamError();
                    break;
                }
                break;

            case Namespaces.StartTLSNamespace:
                switch (nd.Name)
                {
                case "starttls":
                    res = new StartTLS();
                    break;

                case "failure":
                    res = new StartTLSFailure();
                    break;

                case "proceed":
                    res = new StartTLSProceed();
                    break;
                }

                break;

            case Namespaces.SaslNamespace:
                switch (nd.Name)
                {
                case "mechanisms":
                    res = new Mechanisms();
                    break;

                case "auth":
                    res = new SaslAuth();
                    break;

                case "challenge":
                    res = new SaslChallenge();
                    break;

                case "response":
                    res = new SaslResponse();
                    break;

                case "abort":
                    res = new SaslAbort();
                    break;

                case "success":
                    res = new SaslSuccess();
                    break;

                case "failure":
                    res = new SaslFailure();
                    break;
                }
                break;
            }
            if (res == null)
            {
                res = new UnknownElement();
            }
            else
            {
                res.Attributes.Clear(); // default ones shouldn't be here during the reading process
            }
            if (parent != null)
            {
                res.Parent = parent;
                if (parent != fServerRoot)
                {
                    parent.Elements.Add(res);
                }
            }
            res.Prefix = nd.Prefix;
            res.Name   = nd.Name;
            foreach (var el in nd.Attribute)
            {
                res.Attributes.Add(el);
            }
            return(res);
        }