Exemple #1
0
        private void JabberClient_OnSASLStart(Object sender, SASLProcessor proc)
        {
            BaseState s = null;

            lock (StateLock)
            {
                s = State;
            }

            // HACK: fire OnSASLStart with state of NonSASLAuthState to initiate old-style auth.
            if (s == NonSASLAuthState.Instance)
            {
                if ((bool)this[Options.AUTO_LOGIN_THISPASS])
                {
                    Login();
                }
                else
                {
                    LoginRequired(ManualLoginState.Instance);
                }
            }
            else
            {
                if ((bool)this[Options.AUTO_LOGIN_THISPASS])
                {
                    // TODO: integrate SASL params into XmppStream params
                    proc[SASLProcessor.USERNAME] = User;
                    proc[SASLProcessor.PASSWORD] = Password;
                    proc[MD5Processor.REALM]     = this.Server;
                    object creds = this[KerbProcessor.USE_WINDOWS_CREDS];
                    if (creds == null)
                    {
                        creds = false;
                    }
                    proc[KerbProcessor.USE_WINDOWS_CREDS] = creds.ToString();
                }
                else
                {
                    LoginRequired(ManualSASLLoginState.Instance);
                }
            }
        }
Exemple #2
0
        private void JabberService_OnSASLStart(object sender, SASLProcessor proc)
        {
            BaseState s = null;

            lock (StateLock)
            {
                s = State;
            }

            if (s == NonSASLAuthState.Instance)
            {
                lock (StateLock)
                {
                    State = HandshakingState.Instance;
                }

                if (this.Type == ComponentType.Accept)
                {
                    Handshake hand = new Handshake(this.Document);
                    hand.SetAuth(this.Secret, StreamID);
                    Write(hand);
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data">
        /// A <see cref="Tag"/>
        /// </param>
        public override void Execute(Tag data = null)
        {
            Features f;

            if (data is Stream)
            {
                var s = data as Stream;
                if (!s.Version.StartsWith("1."))
                {
                    Errors.SendError(this, ErrorType.WrongProtocolVersion, "Expecting stream:features from 1.x server");
                    return;
                }
                f = s.Features;
            }
            else
            {
                f = data as Features;
            }

            if (f != null)
            {
                if (f.StartTLS != null && UbietySettings.SSL)
                {
                    ProtocolState.State = new StartTLSState();
                    var tls = TagRegistry.GetTag <StartTLS>("starttls", Namespaces.StartTLS);
                    ProtocolState.Socket.Write(tls);
                    return;
                }

                if (!ProtocolState.Authenticated)
                {
                    Logger.Debug(this, "Creating SASL Processor");
                    ProtocolState.Processor = SASLProcessor.CreateProcessor(f.StartSASL.SupportedTypes);
                    if (ProtocolState.Processor == null)
                    {
                        Logger.Debug(this, "No allowed type available. Allow more authentication options.");
                        ProtocolState.State = new DisconnectState();
                        ProtocolState.State.Execute();
                        return;
                    }
                    Logger.Debug(this, "Sending auth with mechanism type");
                    ProtocolState.Socket.Write(ProtocolState.Processor.Initialize());

                    ProtocolState.State = new SASLState();
                    return;
                }

                // Takes place after authentication according to XEP-0170
                if (!ProtocolState.Compressed && CompressionRegistry.AlgorithmsAvailable && !UbietySettings.SSL && f.Compression != null)
                {
                    Logger.Info(this, "Starting compression");
                    // Do we have a stream for any of the compressions supported by the server?
                    foreach (var algorithm in
                             f.Compression.Algorithms.Where(CompressionRegistry.SupportsAlgorithm))
                    {
                        Logger.DebugFormat(this, "Using {0} for compression", algorithm);
                        var c = TagRegistry.GetTag <GenericTag>("compress", Namespaces.CompressionProtocol);
                        var m = TagRegistry.GetTag <GenericTag>("method", Namespaces.CompressionProtocol);

                        m.InnerText = ProtocolState.Algorithm = algorithm;
                        c.AddChildTag(m);
                        ProtocolState.Socket.Write(c);
                        ProtocolState.State = new CompressedState();
                        return;
                    }
                }
            }

            Logger.Debug(this, "Authenticated");
            ProtocolState.State = new BindingState();
            ProtocolState.State.Execute();
        }