@Test(expected = UnsupportedOperationException.class) public void testUnresolvableKeyExchangeReno() { AlgorithmResolver.getKeyExchangeAlgorithm(CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV); }
public static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite) { if (cipherSuite.isTLS13()) { return null; } String cipher = cipherSuite.toString().toUpperCase(); if (cipher.contains("TLS_RSA_WITH") || cipher.contains("TLS_RSA_EXPORT")) { return KeyExchangeAlgorithm.RSA; } else if (cipher.contains("TLS_RSA_PSK_")) { return KeyExchangeAlgorithm.PSK_RSA; } else if (cipher.startsWith("TLS_DH_DSS_")) { return KeyExchangeAlgorithm.DH_DSS; } else if (cipher.startsWith("TLS_DH_RSA_")) { return KeyExchangeAlgorithm.DH_RSA; } else if (cipher.startsWith("TLS_DHE_DSS_")) { return KeyExchangeAlgorithm.DHE_DSS; } else if (cipher.contains("TLS_DHE_RSA_")) { return KeyExchangeAlgorithm.DHE_RSA; } else if (cipher.contains("TLS_DHE_PSK") || cipher.contains("TLS_PSK_DHE")) { return KeyExchangeAlgorithm.DHE_PSK; } else if (cipher.startsWith("TLS_DH_ANON_")) { return KeyExchangeAlgorithm.DH_ANON; } else if (cipher.contains("TLS_ECDHE_RSA")) { return KeyExchangeAlgorithm.ECDHE_RSA; } else if (cipher.contains("TLS_ECDHE_ECDSA")) { return KeyExchangeAlgorithm.ECDHE_ECDSA; } else if (cipher.contains("TLS_ECDH_ANON")) { return KeyExchangeAlgorithm.ECDH_ANON; } else if (cipher.contains("TLS_ECDH_ECDSA")) { return KeyExchangeAlgorithm.ECDH_ECDSA; } else if (cipher.contains("TLS_ECDH_RSA")) { return KeyExchangeAlgorithm.ECDH_RSA; } else if (cipher.contains("TLS_ECDHE_PSK")) { return KeyExchangeAlgorithm.ECDHE_PSK; } else if (cipher.startsWith("TLS_NULL_")) { return KeyExchangeAlgorithm.NULL; } else if (cipher.startsWith("TLS_KRB5_")) { return KeyExchangeAlgorithm.KRB5; } else if (cipher.contains("TLS_PSK_")) { return KeyExchangeAlgorithm.PSK; } else if (cipher.startsWith("TLS_SRP_SHA_RSA")) { return KeyExchangeAlgorithm.SRP_SHA_RSA; } else if (cipher.startsWith("TLS_SRP_SHA_DSS")) { return KeyExchangeAlgorithm.SRP_SHA_DSS; } else if (cipher.startsWith("TLS_SRP_SHA")) { return KeyExchangeAlgorithm.SRP_SHA; } else if (cipher.startsWith("TLS_GOSTR341001_")) { return KeyExchangeAlgorithm.VKO_GOST01; } else if (cipher.startsWith("TLS_GOSTR341112_")) { return KeyExchangeAlgorithm.VKO_GOST12; } else if (cipher.startsWith("TLS_CECPQ1_")) { return KeyExchangeAlgorithm.CECPQ1_ECDSA; } else if (cipher.contains("SSL_FORTEZZA_KEA")) { return KeyExchangeAlgorithm.FORTEZZA_KEA; } else if (cipher.contains("ECMQV_ECNRA")) { return KeyExchangeAlgorithm.ECMQV_ECNRA; } else if (cipher.contains("ECMQV_ECDSA")) { return KeyExchangeAlgorithm.ECMQV_ECDSA; } else if (cipher.contains("ECDH_ECNRA")) { return KeyExchangeAlgorithm.ECDH_ECNRA; } else if (cipher.contains("ECCPWD")) { return KeyExchangeAlgorithm.ECCPWD; } if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV || cipherSuite == CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { throw new UnsupportedOperationException("The CipherSuite:" + cipherSuite.name() + " does not specify a KeyExchangeAlgorithm"); } throw new UnsupportedOperationException("The key exchange algorithm in " + cipherSuite.toString() + " is not supported yet."); }
AlgorithmResolver { public static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite) { if (cipherSuite.isTLS13()) { return null; } String cipher = cipherSuite.toString().toUpperCase(); if (cipher.contains("TLS_RSA_WITH") || cipher.contains("TLS_RSA_EXPORT")) { return KeyExchangeAlgorithm.RSA; } else if (cipher.contains("TLS_RSA_PSK_")) { return KeyExchangeAlgorithm.PSK_RSA; } else if (cipher.startsWith("TLS_DH_DSS_")) { return KeyExchangeAlgorithm.DH_DSS; } else if (cipher.startsWith("TLS_DH_RSA_")) { return KeyExchangeAlgorithm.DH_RSA; } else if (cipher.startsWith("TLS_DHE_DSS_")) { return KeyExchangeAlgorithm.DHE_DSS; } else if (cipher.contains("TLS_DHE_RSA_")) { return KeyExchangeAlgorithm.DHE_RSA; } else if (cipher.contains("TLS_DHE_PSK") || cipher.contains("TLS_PSK_DHE")) { return KeyExchangeAlgorithm.DHE_PSK; } else if (cipher.startsWith("TLS_DH_ANON_")) { return KeyExchangeAlgorithm.DH_ANON; } else if (cipher.contains("TLS_ECDHE_RSA")) { return KeyExchangeAlgorithm.ECDHE_RSA; } else if (cipher.contains("TLS_ECDHE_ECDSA")) { return KeyExchangeAlgorithm.ECDHE_ECDSA; } else if (cipher.contains("TLS_ECDH_ANON")) { return KeyExchangeAlgorithm.ECDH_ANON; } else if (cipher.contains("TLS_ECDH_ECDSA")) { return KeyExchangeAlgorithm.ECDH_ECDSA; } else if (cipher.contains("TLS_ECDH_RSA")) { return KeyExchangeAlgorithm.ECDH_RSA; } else if (cipher.contains("TLS_ECDHE_PSK")) { return KeyExchangeAlgorithm.ECDHE_PSK; } else if (cipher.startsWith("TLS_NULL_")) { return KeyExchangeAlgorithm.NULL; } else if (cipher.startsWith("TLS_KRB5_")) { return KeyExchangeAlgorithm.KRB5; } else if (cipher.contains("TLS_PSK_")) { return KeyExchangeAlgorithm.PSK; } else if (cipher.startsWith("TLS_SRP_SHA_RSA")) { return KeyExchangeAlgorithm.SRP_SHA_RSA; } else if (cipher.startsWith("TLS_SRP_SHA_DSS")) { return KeyExchangeAlgorithm.SRP_SHA_DSS; } else if (cipher.startsWith("TLS_SRP_SHA")) { return KeyExchangeAlgorithm.SRP_SHA; } else if (cipher.startsWith("TLS_GOSTR341001_")) { return KeyExchangeAlgorithm.VKO_GOST01; } else if (cipher.startsWith("TLS_GOSTR341112_")) { return KeyExchangeAlgorithm.VKO_GOST12; } else if (cipher.startsWith("TLS_CECPQ1_")) { return KeyExchangeAlgorithm.CECPQ1_ECDSA; } else if (cipher.contains("SSL_FORTEZZA_KEA")) { return KeyExchangeAlgorithm.FORTEZZA_KEA; } else if (cipher.contains("ECMQV_ECNRA")) { return KeyExchangeAlgorithm.ECMQV_ECNRA; } else if (cipher.contains("ECMQV_ECDSA")) { return KeyExchangeAlgorithm.ECMQV_ECDSA; } else if (cipher.contains("ECDH_ECNRA")) { return KeyExchangeAlgorithm.ECDH_ECNRA; } else if (cipher.contains("ECCPWD")) { return KeyExchangeAlgorithm.ECCPWD; } if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV || cipherSuite == CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { throw new UnsupportedOperationException("The CipherSuite:" + cipherSuite.name() + " does not specify a KeyExchangeAlgorithm"); } throw new UnsupportedOperationException("The key exchange algorithm in " + cipherSuite.toString() + " is not supported yet."); } }
AlgorithmResolver { public static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite) { if (cipherSuite.isTLS13()) { return null; } String cipher = cipherSuite.toString().toUpperCase(); if (cipher.contains("TLS_RSA_WITH") || cipher.contains("TLS_RSA_EXPORT")) { return KeyExchangeAlgorithm.RSA; } else if (cipher.contains("TLS_RSA_PSK_")) { return KeyExchangeAlgorithm.PSK_RSA; } else if (cipher.startsWith("TLS_DH_DSS_")) { return KeyExchangeAlgorithm.DH_DSS; } else if (cipher.startsWith("TLS_DH_RSA_")) { return KeyExchangeAlgorithm.DH_RSA; } else if (cipher.startsWith("TLS_DHE_DSS_")) { return KeyExchangeAlgorithm.DHE_DSS; } else if (cipher.contains("TLS_DHE_RSA_")) { return KeyExchangeAlgorithm.DHE_RSA; } else if (cipher.contains("TLS_DHE_PSK") || cipher.contains("TLS_PSK_DHE")) { return KeyExchangeAlgorithm.DHE_PSK; } else if (cipher.startsWith("TLS_DH_ANON_")) { return KeyExchangeAlgorithm.DH_ANON; } else if (cipher.contains("TLS_ECDHE_RSA")) { return KeyExchangeAlgorithm.ECDHE_RSA; } else if (cipher.contains("TLS_ECDHE_ECDSA")) { return KeyExchangeAlgorithm.ECDHE_ECDSA; } else if (cipher.contains("TLS_ECDH_ANON")) { return KeyExchangeAlgorithm.ECDH_ANON; } else if (cipher.contains("TLS_ECDH_ECDSA")) { return KeyExchangeAlgorithm.ECDH_ECDSA; } else if (cipher.contains("TLS_ECDH_RSA")) { return KeyExchangeAlgorithm.ECDH_RSA; } else if (cipher.contains("TLS_ECDHE_PSK")) { return KeyExchangeAlgorithm.ECDHE_PSK; } else if (cipher.startsWith("TLS_NULL_")) { return KeyExchangeAlgorithm.NULL; } else if (cipher.startsWith("TLS_KRB5_")) { return KeyExchangeAlgorithm.KRB5; } else if (cipher.contains("TLS_PSK_")) { return KeyExchangeAlgorithm.PSK; } else if (cipher.startsWith("TLS_SRP_SHA_RSA")) { return KeyExchangeAlgorithm.SRP_SHA_RSA; } else if (cipher.startsWith("TLS_SRP_SHA_DSS")) { return KeyExchangeAlgorithm.SRP_SHA_DSS; } else if (cipher.startsWith("TLS_SRP_SHA")) { return KeyExchangeAlgorithm.SRP_SHA; } else if (cipher.startsWith("TLS_GOSTR341001_")) { return KeyExchangeAlgorithm.VKO_GOST01; } else if (cipher.startsWith("TLS_GOSTR341112_")) { return KeyExchangeAlgorithm.VKO_GOST12; } else if (cipher.startsWith("TLS_CECPQ1_")) { return KeyExchangeAlgorithm.CECPQ1_ECDSA; } else if (cipher.contains("SSL_FORTEZZA_KEA")) { return KeyExchangeAlgorithm.FORTEZZA_KEA; } else if (cipher.contains("ECMQV_ECNRA")) { return KeyExchangeAlgorithm.ECMQV_ECNRA; } else if (cipher.contains("ECMQV_ECDSA")) { return KeyExchangeAlgorithm.ECMQV_ECDSA; } else if (cipher.contains("ECDH_ECNRA")) { return KeyExchangeAlgorithm.ECDH_ECNRA; } else if (cipher.contains("ECCPWD")) { return KeyExchangeAlgorithm.ECCPWD; } if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV || cipherSuite == CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { throw new UnsupportedOperationException("The CipherSuite:" + cipherSuite.name() + " does not specify a KeyExchangeAlgorithm"); } throw new UnsupportedOperationException("The key exchange algorithm in " + cipherSuite.toString() + " is not supported yet."); } private  AlgorithmResolver(); }
AlgorithmResolver { public static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite) { if (cipherSuite.isTLS13()) { return null; } String cipher = cipherSuite.toString().toUpperCase(); if (cipher.contains("TLS_RSA_WITH") || cipher.contains("TLS_RSA_EXPORT")) { return KeyExchangeAlgorithm.RSA; } else if (cipher.contains("TLS_RSA_PSK_")) { return KeyExchangeAlgorithm.PSK_RSA; } else if (cipher.startsWith("TLS_DH_DSS_")) { return KeyExchangeAlgorithm.DH_DSS; } else if (cipher.startsWith("TLS_DH_RSA_")) { return KeyExchangeAlgorithm.DH_RSA; } else if (cipher.startsWith("TLS_DHE_DSS_")) { return KeyExchangeAlgorithm.DHE_DSS; } else if (cipher.contains("TLS_DHE_RSA_")) { return KeyExchangeAlgorithm.DHE_RSA; } else if (cipher.contains("TLS_DHE_PSK") || cipher.contains("TLS_PSK_DHE")) { return KeyExchangeAlgorithm.DHE_PSK; } else if (cipher.startsWith("TLS_DH_ANON_")) { return KeyExchangeAlgorithm.DH_ANON; } else if (cipher.contains("TLS_ECDHE_RSA")) { return KeyExchangeAlgorithm.ECDHE_RSA; } else if (cipher.contains("TLS_ECDHE_ECDSA")) { return KeyExchangeAlgorithm.ECDHE_ECDSA; } else if (cipher.contains("TLS_ECDH_ANON")) { return KeyExchangeAlgorithm.ECDH_ANON; } else if (cipher.contains("TLS_ECDH_ECDSA")) { return KeyExchangeAlgorithm.ECDH_ECDSA; } else if (cipher.contains("TLS_ECDH_RSA")) { return KeyExchangeAlgorithm.ECDH_RSA; } else if (cipher.contains("TLS_ECDHE_PSK")) { return KeyExchangeAlgorithm.ECDHE_PSK; } else if (cipher.startsWith("TLS_NULL_")) { return KeyExchangeAlgorithm.NULL; } else if (cipher.startsWith("TLS_KRB5_")) { return KeyExchangeAlgorithm.KRB5; } else if (cipher.contains("TLS_PSK_")) { return KeyExchangeAlgorithm.PSK; } else if (cipher.startsWith("TLS_SRP_SHA_RSA")) { return KeyExchangeAlgorithm.SRP_SHA_RSA; } else if (cipher.startsWith("TLS_SRP_SHA_DSS")) { return KeyExchangeAlgorithm.SRP_SHA_DSS; } else if (cipher.startsWith("TLS_SRP_SHA")) { return KeyExchangeAlgorithm.SRP_SHA; } else if (cipher.startsWith("TLS_GOSTR341001_")) { return KeyExchangeAlgorithm.VKO_GOST01; } else if (cipher.startsWith("TLS_GOSTR341112_")) { return KeyExchangeAlgorithm.VKO_GOST12; } else if (cipher.startsWith("TLS_CECPQ1_")) { return KeyExchangeAlgorithm.CECPQ1_ECDSA; } else if (cipher.contains("SSL_FORTEZZA_KEA")) { return KeyExchangeAlgorithm.FORTEZZA_KEA; } else if (cipher.contains("ECMQV_ECNRA")) { return KeyExchangeAlgorithm.ECMQV_ECNRA; } else if (cipher.contains("ECMQV_ECDSA")) { return KeyExchangeAlgorithm.ECMQV_ECDSA; } else if (cipher.contains("ECDH_ECNRA")) { return KeyExchangeAlgorithm.ECDH_ECNRA; } else if (cipher.contains("ECCPWD")) { return KeyExchangeAlgorithm.ECCPWD; } if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV || cipherSuite == CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { throw new UnsupportedOperationException("The CipherSuite:" + cipherSuite.name() + " does not specify a KeyExchangeAlgorithm"); } throw new UnsupportedOperationException("The key exchange algorithm in " + cipherSuite.toString() + " is not supported yet."); } 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); }
AlgorithmResolver { public static KeyExchangeAlgorithm getKeyExchangeAlgorithm(CipherSuite cipherSuite) { if (cipherSuite.isTLS13()) { return null; } String cipher = cipherSuite.toString().toUpperCase(); if (cipher.contains("TLS_RSA_WITH") || cipher.contains("TLS_RSA_EXPORT")) { return KeyExchangeAlgorithm.RSA; } else if (cipher.contains("TLS_RSA_PSK_")) { return KeyExchangeAlgorithm.PSK_RSA; } else if (cipher.startsWith("TLS_DH_DSS_")) { return KeyExchangeAlgorithm.DH_DSS; } else if (cipher.startsWith("TLS_DH_RSA_")) { return KeyExchangeAlgorithm.DH_RSA; } else if (cipher.startsWith("TLS_DHE_DSS_")) { return KeyExchangeAlgorithm.DHE_DSS; } else if (cipher.contains("TLS_DHE_RSA_")) { return KeyExchangeAlgorithm.DHE_RSA; } else if (cipher.contains("TLS_DHE_PSK") || cipher.contains("TLS_PSK_DHE")) { return KeyExchangeAlgorithm.DHE_PSK; } else if (cipher.startsWith("TLS_DH_ANON_")) { return KeyExchangeAlgorithm.DH_ANON; } else if (cipher.contains("TLS_ECDHE_RSA")) { return KeyExchangeAlgorithm.ECDHE_RSA; } else if (cipher.contains("TLS_ECDHE_ECDSA")) { return KeyExchangeAlgorithm.ECDHE_ECDSA; } else if (cipher.contains("TLS_ECDH_ANON")) { return KeyExchangeAlgorithm.ECDH_ANON; } else if (cipher.contains("TLS_ECDH_ECDSA")) { return KeyExchangeAlgorithm.ECDH_ECDSA; } else if (cipher.contains("TLS_ECDH_RSA")) { return KeyExchangeAlgorithm.ECDH_RSA; } else if (cipher.contains("TLS_ECDHE_PSK")) { return KeyExchangeAlgorithm.ECDHE_PSK; } else if (cipher.startsWith("TLS_NULL_")) { return KeyExchangeAlgorithm.NULL; } else if (cipher.startsWith("TLS_KRB5_")) { return KeyExchangeAlgorithm.KRB5; } else if (cipher.contains("TLS_PSK_")) { return KeyExchangeAlgorithm.PSK; } else if (cipher.startsWith("TLS_SRP_SHA_RSA")) { return KeyExchangeAlgorithm.SRP_SHA_RSA; } else if (cipher.startsWith("TLS_SRP_SHA_DSS")) { return KeyExchangeAlgorithm.SRP_SHA_DSS; } else if (cipher.startsWith("TLS_SRP_SHA")) { return KeyExchangeAlgorithm.SRP_SHA; } else if (cipher.startsWith("TLS_GOSTR341001_")) { return KeyExchangeAlgorithm.VKO_GOST01; } else if (cipher.startsWith("TLS_GOSTR341112_")) { return KeyExchangeAlgorithm.VKO_GOST12; } else if (cipher.startsWith("TLS_CECPQ1_")) { return KeyExchangeAlgorithm.CECPQ1_ECDSA; } else if (cipher.contains("SSL_FORTEZZA_KEA")) { return KeyExchangeAlgorithm.FORTEZZA_KEA; } else if (cipher.contains("ECMQV_ECNRA")) { return KeyExchangeAlgorithm.ECMQV_ECNRA; } else if (cipher.contains("ECMQV_ECDSA")) { return KeyExchangeAlgorithm.ECMQV_ECDSA; } else if (cipher.contains("ECDH_ECNRA")) { return KeyExchangeAlgorithm.ECDH_ECNRA; } else if (cipher.contains("ECCPWD")) { return KeyExchangeAlgorithm.ECCPWD; } if (cipherSuite == CipherSuite.TLS_FALLBACK_SCSV || cipherSuite == CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { throw new UnsupportedOperationException("The CipherSuite:" + cipherSuite.name() + " does not specify a KeyExchangeAlgorithm"); } throw new UnsupportedOperationException("The key exchange algorithm in " + cipherSuite.toString() + " is not supported yet."); } 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);  }