public AuthMechanismProcessorStatus ProcessResponse(string data) { if (data != null) { 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 = ServerUtility.DecodeBase64(data); State = States.Completed; Credentials = new LoginAuthenticationCredentials(_username, password); AuthenticationResult result = Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection, Credentials); switch (result) { case AuthenticationResult.Success: return(AuthMechanismProcessorStatus.Success); break; default: return(AuthMechanismProcessorStatus.Failed); break; } default: throw new NotImplementedException(); } }
public AuthMechanismProcessorStatus ProcessResponse(string data) { if (_challenge == null) { StringBuilder challenge = new StringBuilder(); challenge.Append(_random.GenerateRandomInteger(0, Int16.MaxValue)); challenge.Append("."); challenge.Append(_dateTimeProvider.GetCurrentDateTime().Ticks.ToString()); challenge.Append("@"); challenge.Append(Connection.Server.Behaviour.DomainName); _challenge = challenge.ToString(); string base64Challenge = Convert.ToBase64String(Encoding.ASCII.GetBytes(challenge.ToString())); Connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationContinue, base64Challenge)); return(AuthMechanismProcessorStatus.Continue); } else { string response = ServerUtility.DecodeBase64(data); string[] responseparts = response.Split(' '); if (responseparts.Length != 2) { throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure, "Response in incorrect format - should be USERNAME RESPONSE")); } string username = responseparts[0]; string hash = responseparts[1]; Credentials = new CramMd5AuthenticationCredentials(username, _challenge, hash); AuthenticationResult result = Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection, Credentials); switch (result) { case AuthenticationResult.Success: return(AuthMechanismProcessorStatus.Success); break; default: return(AuthMechanismProcessorStatus.Failed); break; } } }
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 = ServerUtility.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 PlainAuthenticationCredentials(username, password); AuthenticationResult result = Connection.Server.Behaviour.ValidateAuthenticationCredentials(Connection, Credentials); switch (result) { case AuthenticationResult.Success: return(AuthMechanismProcessorStatus.Success); break; default: return(AuthMechanismProcessorStatus.Failed); break; } }