Example #1
0
        public AuthMechanismProcessorStatus ProcessResponse(string data)
        {
            string username = null;

            if (State == States.Initial && !String.IsNullOrEmpty(data))
            {
                State = States.WaitingForUsername;
            }

            switch (State)
            {
            case States.Initial:
                Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue,
                                                          Convert.ToBase64String(
                                                              Encoding.ASCII.GetBytes("Username:"******"Password:"))));
                State = States.WaitingForPassword;
                return(AuthMechanismProcessorStatus.Continue);

            case States.WaitingForPassword:
                string password = DecodeBase64(data);
                State = States.Completed;

                Credentials = new UsernameAndPasswordAuthenticationRequest(username, password);

                AuthenticationResult result =
                    Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection,
                                                                                  Credentials);

                switch (result)
                {
                case AuthenticationResult.Success:
                    return(AuthMechanismProcessorStatus.Success);

                default:
                    return(AuthMechanismProcessorStatus.Failed);
                }

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
        public AuthMechanismProcessorStatus ProcessResponse(string data)
        {
            string username = null;

            if (State == States.Initial && !String.IsNullOrEmpty(data))
            {
                State = States.WaitingForUsername;
            }

            switch (State)
            {
                case States.Initial:
                    Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue,
                                                                       Convert.ToBase64String(
                                                                           Encoding.ASCII.GetBytes("Username:"******"Password:"))));
                    State = States.WaitingForPassword;
                    return AuthMechanismProcessorStatus.Continue;

                case States.WaitingForPassword:
                    string password = DecodeBase64(data);
                    State = States.Completed;

                    Credentials = new UsernameAndPasswordAuthenticationRequest(username, password);

                    AuthenticationResult result =
                        Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection,
                                                                                           Credentials);

                    switch (result)
                    {
                        case AuthenticationResult.Success:
                            return AuthMechanismProcessorStatus.Success;
                        default:
                            return AuthMechanismProcessorStatus.Failed;
                    }

                default:
                    throw new NotImplementedException();
            }
        }
Example #3
0
        public AuthMechanismProcessorStatus ProcessResponse(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                if (State == States.AwaitingResponse)
                {
                    throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                                   "Missing auth data"));
                }

                Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue, ""));
                State = States.AwaitingResponse;
                return(AuthMechanismProcessorStatus.Continue);
            }

            string decodedData = DecodeBase64(data);

            string[] decodedDataParts = decodedData.Split('\0');

            if (decodedDataParts.Length != 3)
            {
                throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                               "Auth data in incorrect format"));
            }

            string username = decodedDataParts[1];
            string password = decodedDataParts[2];

            Credentials = new UsernameAndPasswordAuthenticationRequest(username, password);

            AuthenticationResult result =
                Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection, Credentials);

            switch (result)
            {
            case AuthenticationResult.Success:
                return(AuthMechanismProcessorStatus.Success);

                break;

            default:
                return(AuthMechanismProcessorStatus.Failed);

                break;
            }
        }
Example #4
0
        public AuthMechanismProcessorStatus ProcessResponse(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                if (State == States.AwaitingResponse)
                {
                    throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                                   "Missing auth data"));
                }

                Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue, ""));
                State = States.AwaitingResponse;
                return AuthMechanismProcessorStatus.Continue;
            }

            string decodedData = DecodeBase64(data);
            string[] decodedDataParts = decodedData.Split('\0');

            if (decodedDataParts.Length != 3)
            {
                throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                               "Auth data in incorrect format"));
            }

            string username = decodedDataParts[1];
            string password = decodedDataParts[2];

            Credentials = new UsernameAndPasswordAuthenticationRequest(username, password);

            AuthenticationResult result =
                Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection, Credentials);
            switch (result)
            {
                case AuthenticationResult.Success:
                    return AuthMechanismProcessorStatus.Success;
                default:
                    return AuthMechanismProcessorStatus.Failed;
            }
        }