@Test public void wasMessageTransmittedSecurely_withNoHeaders_shouldReturnUnknown() throws MessagingException { String[] noReceivedHeaders = new String[]{}; Message unknownMessage = mock(Message.class); when(unknownMessage.getHeader("Received")).thenReturn(noReceivedHeaders); assertEquals(SecureTransportError.UNKNOWN, ReceivedHeaders.wasMessageTransmittedSecurely(unknownMessage).getErrorType()); }
public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.trim(); Matcher matcher = fromPattern.matcher(header); if(matcher.find()) fromAddress = matcher.group(1); matcher = byPattern.matcher(header); if(matcher.find()) toAddress = matcher.group(1); matcher = usingPattern.matcher(header); if(matcher.find()) { sslVersion = matcher.group(1); cipher = matcher.group(2); bits = matcher.group(3); } if (fromAddress.equals("localhost") || fromAddress.equals("127.0.0.1") || toAddress.equals("localhost") || toAddress.equals("127.0.0.1")) { continue; } if (sslVersion == null || sslVersion.startsWith("SSL")) { return new SecureTransportState(SecureTransportError.INSECURELY_ENCRYPTED, R.string.transport_crypto_insecure_ssl_version); } return new SecureTransportState(SecureTransportError.SECURELY_ENCRYPTED); } return new SecureTransportState(SecureTransportError.UNKNOWN); }
ReceivedHeaders { public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.trim(); Matcher matcher = fromPattern.matcher(header); if(matcher.find()) fromAddress = matcher.group(1); matcher = byPattern.matcher(header); if(matcher.find()) toAddress = matcher.group(1); matcher = usingPattern.matcher(header); if(matcher.find()) { sslVersion = matcher.group(1); cipher = matcher.group(2); bits = matcher.group(3); } if (fromAddress.equals("localhost") || fromAddress.equals("127.0.0.1") || toAddress.equals("localhost") || toAddress.equals("127.0.0.1")) { continue; } if (sslVersion == null || sslVersion.startsWith("SSL")) { return new SecureTransportState(SecureTransportError.INSECURELY_ENCRYPTED, R.string.transport_crypto_insecure_ssl_version); } return new SecureTransportState(SecureTransportError.SECURELY_ENCRYPTED); } return new SecureTransportState(SecureTransportError.UNKNOWN); } }
ReceivedHeaders { public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.trim(); Matcher matcher = fromPattern.matcher(header); if(matcher.find()) fromAddress = matcher.group(1); matcher = byPattern.matcher(header); if(matcher.find()) toAddress = matcher.group(1); matcher = usingPattern.matcher(header); if(matcher.find()) { sslVersion = matcher.group(1); cipher = matcher.group(2); bits = matcher.group(3); } if (fromAddress.equals("localhost") || fromAddress.equals("127.0.0.1") || toAddress.equals("localhost") || toAddress.equals("127.0.0.1")) { continue; } if (sslVersion == null || sslVersion.startsWith("SSL")) { return new SecureTransportState(SecureTransportError.INSECURELY_ENCRYPTED, R.string.transport_crypto_insecure_ssl_version); } return new SecureTransportState(SecureTransportError.SECURELY_ENCRYPTED); } return new SecureTransportState(SecureTransportError.UNKNOWN); }  }
ReceivedHeaders { public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.trim(); Matcher matcher = fromPattern.matcher(header); if(matcher.find()) fromAddress = matcher.group(1); matcher = byPattern.matcher(header); if(matcher.find()) toAddress = matcher.group(1); matcher = usingPattern.matcher(header); if(matcher.find()) { sslVersion = matcher.group(1); cipher = matcher.group(2); bits = matcher.group(3); } if (fromAddress.equals("localhost") || fromAddress.equals("127.0.0.1") || toAddress.equals("localhost") || toAddress.equals("127.0.0.1")) { continue; } if (sslVersion == null || sslVersion.startsWith("SSL")) { return new SecureTransportState(SecureTransportError.INSECURELY_ENCRYPTED, R.string.transport_crypto_insecure_ssl_version); } return new SecureTransportState(SecureTransportError.SECURELY_ENCRYPTED); } return new SecureTransportState(SecureTransportError.UNKNOWN); }  static SecureTransportState wasMessageTransmittedSecurely(Message message); static SPFState isEmailPotentialSpoof(Message message); static DKIMState isEmailIntegrityValid(Message message); }
ReceivedHeaders { public static SecureTransportState wasMessageTransmittedSecurely(Message message) { String[] headers = message.getHeader(RECEIVED); Timber.d("Received headers: " + headers.length); for(String header: headers) { String fromAddress = "", toAddress = "", sslVersion = null, cipher, bits; header = header.trim(); Matcher matcher = fromPattern.matcher(header); if(matcher.find()) fromAddress = matcher.group(1); matcher = byPattern.matcher(header); if(matcher.find()) toAddress = matcher.group(1); matcher = usingPattern.matcher(header); if(matcher.find()) { sslVersion = matcher.group(1); cipher = matcher.group(2); bits = matcher.group(3); } if (fromAddress.equals("localhost") || fromAddress.equals("127.0.0.1") || toAddress.equals("localhost") || toAddress.equals("127.0.0.1")) { continue; } if (sslVersion == null || sslVersion.startsWith("SSL")) { return new SecureTransportState(SecureTransportError.INSECURELY_ENCRYPTED, R.string.transport_crypto_insecure_ssl_version); } return new SecureTransportState(SecureTransportError.SECURELY_ENCRYPTED); } return new SecureTransportState(SecureTransportError.UNKNOWN); }  static SecureTransportState wasMessageTransmittedSecurely(Message message); static SPFState isEmailPotentialSpoof(Message message); static DKIMState isEmailIntegrityValid(Message message); static final String RECEIVED; static Pattern fromPattern; static Pattern byPattern; static Pattern usingPattern; static final String AUTHENTICATION_RESULTS; static Pattern spfPattern; static Pattern dkimPattern; }