Beispiel #1
0
 public override void Execute(Tag data = null)
 {
     tags.streams.stream stream = new tags.streams.stream();
     stream.version = "1.0";
     stream.to      = Manager.Settings.Id.Server;
     stream.xmlns   = tags.jabber.client.Namespace.Name;
     stream.lang    = "en";
     Manager.Connection.Send("<?xml version='1.0' encoding='UTF-8'?>" + stream.StartTag);
     Manager.State = new ServerFeaturesState(Manager);
 }
Beispiel #2
0
		public override void Execute(Tag data = null)
		{
            tags.streams.stream stream = new tags.streams.stream();
			stream.version = "1.0";
			stream.to = Manager.Settings.Id.Server;
            stream.xmlns = tags.jabber.client.Namespace.Name;
			stream.lang = "en";
            Manager.Connection.Send("<?xml version='1.0' encoding='UTF-8'?>" + stream.StartTag);
            Manager.State = new ServerFeaturesState(Manager);
		}
Beispiel #3
0
        public override void Execute(Tag data = null)
        {
            tags.streams.features features = null;

            if (data is tags.streams.stream)
            {
                tags.streams.stream stream = data as tags.streams.stream;
                if (!stream.version.StartsWith("1."))
                {
                    Manager.Events.Error(this, ErrorType.XMPPVersionNotSupported, ErrorPolicyType.Deactivate, "Expecting stream:features from 1.x server");
                    return;
                }
                features = stream.features;
            }
            else if (data is tags.streams.error)
            {
                var    error   = data as tags.streams.error;
                string message = string.Empty;

                if (error.HasElements)
                {
                    var text = error.Element <tags.xmpp_streams.text>(tags.xmpp_streams.Namespace.text);
                    if (text != null)
                    {
                        message = text.Value;
                    }
                    else if (error.Elements().Count() > 0)
                    {
                        var element = error.Elements().First();
                        if (element != null)
                        {
                            message = element.Name.LocalName;
                        }
                    }
                }

                Manager.Events.Error(this, ErrorType.ServerError, ErrorPolicyType.Reconnect, message);
                return;
            }
            else if (data is tags.streams.features)
            {
                features = data as tags.streams.features;
            }

            if (features != null)
            {
                if (features.starttls != null && Manager.Settings.SSL)
                {
                    Manager.State = new StartTLSState(Manager);
                    tags.xmpp_tls.starttls tls = new tags.xmpp_tls.starttls();
                    Manager.Connection.Send(tls);
                    return;
                }

                if (!Manager.IsAuthenticated)
                {
#if DEBUG
                    Manager.Events.LogMessage(this, LogType.Debug, "Creating SASL Processor");
#endif
                    if ((features.mechanisms.Types & MechanismType.XOAUTH2 & Manager.Settings.AuthenticationTypes) == MechanismType.XOAUTH2)
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "Creating XOAUTH2 processor");
#endif
                        Manager.SASLProcessor = new XOAUTH2Processor(Manager);
                    }
                    else if ((features.mechanisms.Types & MechanismType.SCRAM & Manager.Settings.AuthenticationTypes) == MechanismType.SCRAM)
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "Creating SCRAM-SHA-1 Processor");
#endif
                        Manager.SASLProcessor = new SCRAMProcessor(Manager);
                    }
                    else if ((features.mechanisms.Types & MechanismType.DigestMD5 & Manager.Settings.AuthenticationTypes) == MechanismType.DigestMD5)
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "Creating DIGEST-MD5 Processor");
#endif
                        Manager.SASLProcessor = new MD5Processor(Manager);
                    }
                    else if ((features.mechanisms.Types & MechanismType.External & Manager.Settings.AuthenticationTypes) == MechanismType.External)
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "External Not Supported");
#endif
                    }
                    else if ((features.mechanisms.Types & MechanismType.Plain & Manager.Settings.AuthenticationTypes) == MechanismType.Plain)
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "Creating PLAIN SASL processor");
#endif
                        Manager.SASLProcessor = new PlainProcessor(Manager);
                    }
                    else
                    {
                        Manager.SASLProcessor = null;

                        string supported = string.Empty;
                        foreach (var element in features.mechanisms.mechanismElements)
                        {
                            if (!string.IsNullOrEmpty(supported))
                            {
                                supported += ", ";
                            }

                            supported += element.Value;
                        }

                        Manager.Events.Error(this, ErrorType.NoSupportedAuthenticationMethod, ErrorPolicyType.Deactivate, supported);
                        return;
                    }
#if DEBUG
                    Manager.Events.LogMessage(this, LogType.Debug, "Sending auth with mechanism type");
#endif
                    Manager.State = new SASLState(Manager);

                    Manager.Connection.Send(Manager.SASLProcessor.Initialize());

                    return;
                }

                // Takes place after authentication according to XEP-0170
                if (!Manager.IsCompressed && Static.CompressionRegistry.AlgorithmsAvailable && !Manager.Settings.SSL && features.compression != null)
                {
#if DEBUG
                    Manager.Events.LogMessage(this, LogType.Info, "Starting compression");
#endif
                    // Do we have a stream for any of the compressions supported by the server?
                    foreach (var algorithm in
                             features.compression.methods.Where(Static.CompressionRegistry.SupportsAlgorithm))
                    {
#if DEBUG
                        Manager.Events.LogMessage(this, LogType.Debug, "Using {0} for compression", algorithm);
#endif
                        var c = new tags.jabber.protocol.compress.compress();
                        var m = new tags.jabber.protocol.compress.method();

                        m.Value = Manager.CompressionAlgorithm = algorithm;
                        c.Add(m);
                        Manager.Connection.Send(c);
                        Manager.State = new CompressedState(Manager);
                        return;
                    }
                }
#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Authenticated");
#endif
                Manager.State = new BindingState(Manager);
                Manager.State.Execute();
            }
        }