コード例 #1
0
        /// <summary>
        /// Verifies the SASL success message if needed.
        /// </summary>
        /// <param name="success">The server success response</param>
        /// <returns>
        ///   <b>true</b> if the reponse has been verified; otherwise <b>false</b>
        /// </returns>
        public bool ProcessSuccess(SaslSuccess success)
        {
            // The server verifies the nonce and the proof, verifies that the
            // authorization identity (if supplied by the client in the first
            // message) is authorized to act as the authentication identity, and,
            // finally, it responds with a "server-final-message", concluding the
            // authentication exchange.
            var decoded            = Convert.FromBase64String(success.Value);
            var serverFinalMessage = XmppEncoding.Utf8.GetString(decoded, 0, decoded.Length);
            var tokens             = SaslTokenizer.ToDictionary(serverFinalMessage);
            var serverSignature    = tokens["v"];

            return(serverSignature == this.serverSignature);
        }
コード例 #2
0
ファイル: XmppTransport.cs プロジェクト: pietpukkel/conversa
        private async Task OnSaslSuccessAsync(SaslSuccess success)
        {
            if (this.saslMechanism.ProcessSuccess(success))
            {
                this.State         = XmppTransportState.Authenticated;
                this.saslMechanism = null;

                await this.transport.ResetStreamAsync().ConfigureAwait(false);
            }
            else
            {
                this.OnSaslFailure("Server reponse cannot be verified.");
            }
        }
コード例 #3
0
 /// <summary>
 /// Verifies the SASL success message if needed.
 /// </summary>
 /// <param name="success">The server success response</param>
 /// <returns>
 ///   <b>true</b> if the reponse has been verified; otherwise <b>false</b>
 /// </returns>
 public bool ProcessSuccess(SaslSuccess success)
 {
     return(true);
 }
コード例 #4
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);
        }