< prev index next >

src/java.base/share/classes/sun/security/ssl/ECDHKeyExchange.java

Print this page
rev 54061 : 8226374: Restrict TLS signature schemes and named groups
Reviewed-by: mullan

*** 34,52 **** import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.interfaces.ECPublicKey; - import java.security.spec.ECGenParameterSpec; import java.security.spec.ECParameterSpec; import java.security.spec.ECPoint; import java.security.spec.ECPublicKeySpec; import java.util.EnumSet; import javax.crypto.KeyAgreement; import javax.crypto.SecretKey; import javax.net.ssl.SSLHandshakeException; ! import sun.security.ssl.NamedGroup.NamedGroupType; import sun.security.ssl.SupportedGroupsExtension.SupportedGroups; import sun.security.ssl.X509Authentication.X509Credentials; import sun.security.ssl.X509Authentication.X509Possession; import sun.security.ssl.XDHKeyExchange.XDHECredentials; import sun.security.ssl.XDHKeyExchange.XDHEPossession; --- 34,51 ---- import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.interfaces.ECPublicKey; import java.security.spec.ECParameterSpec; import java.security.spec.ECPoint; import java.security.spec.ECPublicKeySpec; import java.util.EnumSet; import javax.crypto.KeyAgreement; import javax.crypto.SecretKey; import javax.net.ssl.SSLHandshakeException; ! import sun.security.ssl.NamedGroup.NamedGroupSpec; import sun.security.ssl.SupportedGroupsExtension.SupportedGroups; import sun.security.ssl.X509Authentication.X509Credentials; import sun.security.ssl.X509Authentication.X509Possession; import sun.security.ssl.XDHKeyExchange.XDHECredentials; import sun.security.ssl.XDHKeyExchange.XDHEPossession;
*** 86,109 **** } static ECDHECredentials valueOf(NamedGroup namedGroup, byte[] encodedPoint) throws IOException, GeneralSecurityException { ! if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) { throw new RuntimeException( "Credentials decoding: Not ECDHE named group"); } if (encodedPoint == null || encodedPoint.length == 0) { return null; } ECParameterSpec parameters = ! JsseJce.getECParameterSpec(namedGroup.oid); ! if (parameters == null) { ! return null; ! } ECPoint point = JsseJce.decodePoint( encodedPoint, parameters.getCurve()); KeyFactory factory = JsseJce.getKeyFactory("EC"); ECPublicKey publicKey = (ECPublicKey)factory.generatePublic( --- 85,105 ---- } static ECDHECredentials valueOf(NamedGroup namedGroup, byte[] encodedPoint) throws IOException, GeneralSecurityException { ! if (namedGroup.spec != NamedGroupSpec.NAMED_GROUP_ECDHE) { throw new RuntimeException( "Credentials decoding: Not ECDHE named group"); } if (encodedPoint == null || encodedPoint.length == 0) { return null; } ECParameterSpec parameters = ! (ECParameterSpec)namedGroup.keAlgParamSpec; ECPoint point = JsseJce.decodePoint( encodedPoint, parameters.getCurve()); KeyFactory factory = JsseJce.getKeyFactory("EC"); ECPublicKey publicKey = (ECPublicKey)factory.generatePublic(
*** 118,130 **** final NamedGroup namedGroup; ECDHEPossession(NamedGroup namedGroup, SecureRandom random) { try { KeyPairGenerator kpg = JsseJce.getKeyPairGenerator("EC"); ! ECGenParameterSpec params = ! (ECGenParameterSpec)namedGroup.getParameterSpec(); ! kpg.initialize(params, random); KeyPair kp = kpg.generateKeyPair(); privateKey = kp.getPrivate(); publicKey = (ECPublicKey)kp.getPublic(); } catch (GeneralSecurityException e) { throw new RuntimeException( --- 114,124 ---- final NamedGroup namedGroup; ECDHEPossession(NamedGroup namedGroup, SecureRandom random) { try { KeyPairGenerator kpg = JsseJce.getKeyPairGenerator("EC"); ! kpg.initialize(namedGroup.keAlgParamSpec, random); KeyPair kp = kpg.generateKeyPair(); privateKey = kp.getPrivate(); publicKey = (ECPublicKey)kp.getPublic(); } catch (GeneralSecurityException e) { throw new RuntimeException(
*** 246,266 **** if ((context.clientRequestedNamedGroups != null) && (!context.clientRequestedNamedGroups.isEmpty())) { preferableNamedGroup = SupportedGroups.getPreferredGroup( context.negotiatedProtocol, context.algorithmConstraints, ! new NamedGroupType[] { ! NamedGroupType.NAMED_GROUP_ECDHE, ! NamedGroupType.NAMED_GROUP_XDH }, context.clientRequestedNamedGroups); } else { preferableNamedGroup = SupportedGroups.getPreferredGroup( context.negotiatedProtocol, context.algorithmConstraints, ! new NamedGroupType[] { ! NamedGroupType.NAMED_GROUP_ECDHE, ! NamedGroupType.NAMED_GROUP_XDH }); } if (preferableNamedGroup != null) { return preferableNamedGroup.createPossession( context.sslContext.getSecureRandom()); --- 240,260 ---- if ((context.clientRequestedNamedGroups != null) && (!context.clientRequestedNamedGroups.isEmpty())) { preferableNamedGroup = SupportedGroups.getPreferredGroup( context.negotiatedProtocol, context.algorithmConstraints, ! new NamedGroupSpec[] { ! NamedGroupSpec.NAMED_GROUP_ECDHE, ! NamedGroupSpec.NAMED_GROUP_XDH }, context.clientRequestedNamedGroups); } else { preferableNamedGroup = SupportedGroups.getPreferredGroup( context.negotiatedProtocol, context.algorithmConstraints, ! new NamedGroupSpec[] { ! NamedGroupSpec.NAMED_GROUP_ECDHE, ! NamedGroupSpec.NAMED_GROUP_XDH }); } if (preferableNamedGroup != null) { return preferableNamedGroup.createPossession( context.sslContext.getSecureRandom());
*** 306,316 **** continue; } NamedGroup ng = NamedGroup.valueOf(params); if (ng == null) { ! // unlikely, have been checked during cipher suite negotiation. throw shc.conContext.fatal(Alert.ILLEGAL_PARAMETER, "Unsupported EC server cert for ECDH key exchange"); } for (SSLCredentials cred : shc.handshakeCredentials) { --- 300,311 ---- continue; } NamedGroup ng = NamedGroup.valueOf(params); if (ng == null) { ! // unlikely, have been checked during cipher suite ! // negotiation. throw shc.conContext.fatal(Alert.ILLEGAL_PARAMETER, "Unsupported EC server cert for ECDH key exchange"); } for (SSLCredentials cred : shc.handshakeCredentials) {
*** 478,488 **** "No sufficient ECDHE/XDH key agreement " + "parameters negotiated"); } String alg; ! switch (namedGroup.type) { case NAMED_GROUP_ECDHE: alg = "ECDH"; break; case NAMED_GROUP_XDH: alg = "XDH"; --- 473,483 ---- "No sufficient ECDHE/XDH key agreement " + "parameters negotiated"); } String alg; ! switch (namedGroup.spec) { case NAMED_GROUP_ECDHE: alg = "ECDH"; break; case NAMED_GROUP_XDH: alg = "XDH";
< prev index next >