AlgorithmResolver { public static DigestAlgorithm getDigestAlgorithm(ProtocolVersion protocolVersion, CipherSuite cipherSuite) { DigestAlgorithm result; if (protocolVersion == ProtocolVersion.SSL3 || protocolVersion == ProtocolVersion.SSL2) { throw new UnsupportedOperationException("SSL3 and SSL2 PRF currently not supported"); } if (cipherSuite.usesGOSTR3411()) { result = DigestAlgorithm.GOSTR3411; } else if (cipherSuite.usesGOSTR34112012()) { result = DigestAlgorithm.GOSTR34112012_256; } else if (protocolVersion == ProtocolVersion.TLS10 || protocolVersion == ProtocolVersion.TLS11 || protocolVersion == ProtocolVersion.DTLS10) { result = DigestAlgorithm.LEGACY; } else if (cipherSuite.usesSHA384()) { result = DigestAlgorithm.SHA384; } else { result = DigestAlgorithm.SHA256; } LOGGER.debug("Using the following Digest Algorithm: {}", result); return result; } private  AlgorithmResolver(); static PRFAlgorithm getPRFAlgorithm(ProtocolVersion protocolVersion, CipherSuite cipherSuite); static DigestAlgorithm getDigestAlgorithm(ProtocolVersion protocolVersion, CipherSuite cipherSuite); static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite); static Set<PublicKeyAlgorithm> getRequiredKeystoreAlgorithms(CipherSuite cipherSuite); static CipherAlgorithm getCipher(CipherSuite cipherSuite); static BulkCipherAlgorithm getBulkCipherAlgorithm(CipherSuite cipherSuite); static CipherType getCipherType(CipherSuite cipherSuite); static MacAlgorithm getMacAlgorithm(ProtocolVersion protocolVersion, CipherSuite cipherSuite); static HKDFAlgorithm getHKDFAlgorithm(CipherSuite cipherSuite);  }
@Test(expected = UnsupportedOperationException.class) public void testGetDigestUnsupportedProtocolVersionSSL2() { AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.SSL2, CipherSuite.TLS_FALLBACK_SCSV); }
@Test(expected = UnsupportedOperationException.class) public void testGetDigestUnsupportedProtocolVersionSSL3() { AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.SSL3, CipherSuite.TLS_FALLBACK_SCSV); }
@Test public void testGetDigestAlgorithm() { for (CipherSuite suite : CipherSuite.values()) { if (suite.name().contains("GOST")) { continue; } assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS10, suite) == DigestAlgorithm.LEGACY); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS11, suite) == DigestAlgorithm.LEGACY); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.DTLS10, suite) == DigestAlgorithm.LEGACY); } assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384) == DigestAlgorithm.SHA384); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.DTLS12, CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384) == DigestAlgorithm.SHA384); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.DTLS12, CipherSuite.TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.DTLS12, CipherSuite.TLS_DHE_PSK_WITH_AES_256_CCM) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_DH_anon_EXPORT_WITH_RC4_40_MD5) == DigestAlgorithm.SHA256); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_GOSTR341094_WITH_28147_CNT_IMIT) == DigestAlgorithm.GOSTR3411); assertTrue(AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS12, CipherSuite.TLS_GOSTR341112_256_WITH_28147_CNT_IMIT) == DigestAlgorithm.GOSTR34112012_256); }