private void login() throws MessagingException { executeSimpleCommand(USER_COMMAND + " " + mUsername); try { executeSimpleCommand(PASS_COMMAND + " " + mPassword, true); } catch (Pop3ErrorResponse e) { throw new AuthenticationFailedException( "POP3 login authentication failed: " + e.getMessage(), e); } }
private void authCramMD5() throws MessagingException { String b64Nonce = executeSimpleCommand("AUTH CRAM-MD5").replace("+ ", ""); String b64CRAM = Authentication.computeCramMd5(mUsername, mPassword, b64Nonce); try { executeSimpleCommand(b64CRAM, true); } catch (Pop3ErrorResponse e) { throw new AuthenticationFailedException( "POP3 CRAM-MD5 authentication failed: " + e.getMessage(), e); } }
private void authPlain() throws MessagingException { executeSimpleCommand("AUTH PLAIN"); try { byte[] encodedBytes = Base64.encodeBase64(("\000" + mUsername + "\000" + mPassword).getBytes()); executeSimpleCommand(new String(encodedBytes), true); } catch (Pop3ErrorResponse e) { throw new AuthenticationFailedException( "POP3 SASL auth PLAIN authentication failed: " + e.getMessage(), e); } }
private void authExternal() throws MessagingException { try { executeSimpleCommand(String.format("AUTH EXTERNAL %s", Base64.encode(mUsername)), false); } catch (Pop3ErrorResponse e) { /* * Provide notification to the user of a problem authenticating * using client certificates. We don't use an * AuthenticationFailedException because that would trigger a * "Username or password incorrect" notification in * AccountSetupCheckSettings. */ throw new CertificateValidationException( "POP3 client certificate authentication failed: " + e.getMessage(), e); } }
private void authAPOP(String serverGreeting) throws MessagingException { // regex based on RFC 2449 (3.) "Greeting" String timestamp = serverGreeting.replaceFirst("^\\+OK *(?:\\[[^\\]]+\\])?[^<]*(<[^>]*>)?[^<]*$", "$1"); if ("".equals(timestamp)) { throw new MessagingException("APOP authentication is not supported"); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new MessagingException("MD5 failure during POP3 auth APOP", e); } byte[] digest = md.digest((timestamp + mPassword).getBytes()); String hexDigest = new String(Hex.encodeHex(digest)); try { executeSimpleCommand("APOP " + mUsername + " " + hexDigest, true); } catch (Pop3ErrorResponse e) { throw new AuthenticationFailedException( "POP3 APOP authentication failed: " + e.getMessage(), e); } }