@Test public void wasMessageTransmittedSecurely_forSecureMessage_shouldReturnTrue() throws MessagingException { String[] secureReceivedHeaders = new String[]{ " from localhost (localhost [127.0.0.1])\n" + "by scarlet.richardwhiuk.com (Postfix)\n " + "with ESMTP id BB1057BA98\n " + "for <philip@whiuk.com>; Fri, 25 Mar 2016 10:38:29 +0000 (GMT)", " from scarlet.richardwhiuk.com ([127.0.0.1])\n" + "by localhost (scarlet.richardwhiuk.com [127.0.0.1]) (amavisd-new, port 10024)\n" + "with ESMTP id kEaYiQPLCxiT for <philip@whiuk.com>; Fri, 25 Mar 2016 10:38:27 +0000 (GMT)\n", " from serpentine.unitedhosting.co.uk (serpentine.unitedhosting.co.uk [83.223.125.16])\n" + "(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\n" + "(No client certificate requested)\n" + "by scarlet.richardwhiuk.com (Postfix)\n" + "with ESMTPS id C19917A8E9\n" + "for <philip@whiuk.com>; Fri, 25 Mar 2016 10:38:27 +0000 (GMT)\n", " from serpentine.unitedhosting.co.uk ([83.223.125.16]:56654 helo=serpentine.org.uk)\n" + "by serpentine.unitedhosting.co.uk\n" + "with esmtp (Exim 4.86_1) (envelope-from <list-bounces@serpentine.org.uk>)\n" + "id 1ajOr6-00020j-MM\n" + "for philip@whiuk.com; Fri, 25 Mar 2016 10:20:36 +0000\n" }; Message secureMessage = mock(Message.class); when(secureMessage.getHeader("Received")).thenReturn(secureReceivedHeaders); assertEquals(SecureTransportError.SECURELY_ENCRYPTED, ReceivedHeaders.wasMessageTransmittedSecurely(secureMessage).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; }