You need to sign in or sign up before continuing.
提交 a44ced8a 编写于 作者: R robm

8042982: Unexpected RuntimeExceptions being thrown by SSLEngine

Reviewed-by: wetmore, xuelei
上级 ae503985
/* /*
* Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -188,7 +188,7 @@ final class DHCrypt { ...@@ -188,7 +188,7 @@ final class DHCrypt {
* the same size as the Diffie-Hellman modulus. * the same size as the Diffie-Hellman modulus.
*/ */
SecretKey getAgreedSecret(BigInteger peerPublicValue, SecretKey getAgreedSecret(BigInteger peerPublicValue,
boolean keyIsValidated) throws IOException { boolean keyIsValidated) throws SSLHandshakeException {
try { try {
KeyFactory kf = JsseJce.getKeyFactory("DiffieHellman"); KeyFactory kf = JsseJce.getKeyFactory("DiffieHellman");
DHPublicKeySpec spec = DHPublicKeySpec spec =
...@@ -211,7 +211,8 @@ final class DHCrypt { ...@@ -211,7 +211,8 @@ final class DHCrypt {
ka.doPhase(publicKey, true); ka.doPhase(publicKey, true);
return ka.generateSecret("TlsPremasterSecret"); return ka.generateSecret("TlsPremasterSecret");
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new RuntimeException("Could not generate secret", e); throw (SSLHandshakeException) new SSLHandshakeException(
"Could not generate secret").initCause(e);
} }
} }
......
/* /*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,6 +31,7 @@ import java.security.spec.*; ...@@ -31,6 +31,7 @@ import java.security.spec.*;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.KeyAgreement; import javax.crypto.KeyAgreement;
import javax.net.ssl.SSLHandshakeException;
/** /**
* Helper class for the ECDH key exchange. It generates the appropriate * Helper class for the ECDH key exchange. It generates the appropriate
...@@ -88,19 +89,20 @@ final class ECDHCrypt { ...@@ -88,19 +89,20 @@ final class ECDHCrypt {
} }
// called by ClientHandshaker with either the server's static or ephemeral public key // called by ClientHandshaker with either the server's static or ephemeral public key
SecretKey getAgreedSecret(PublicKey peerPublicKey) { SecretKey getAgreedSecret(PublicKey peerPublicKey) throws SSLHandshakeException {
try { try {
KeyAgreement ka = JsseJce.getKeyAgreement("ECDH"); KeyAgreement ka = JsseJce.getKeyAgreement("ECDH");
ka.init(privateKey); ka.init(privateKey);
ka.doPhase(peerPublicKey, true); ka.doPhase(peerPublicKey, true);
return ka.generateSecret("TlsPremasterSecret"); return ka.generateSecret("TlsPremasterSecret");
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new RuntimeException("Could not generate secret", e); throw (SSLHandshakeException) new SSLHandshakeException(
"Could not generate secret").initCause(e);
} }
} }
// called by ServerHandshaker // called by ServerHandshaker
SecretKey getAgreedSecret(byte[] encodedPoint) { SecretKey getAgreedSecret(byte[] encodedPoint) throws SSLHandshakeException {
try { try {
ECParameterSpec params = publicKey.getParams(); ECParameterSpec params = publicKey.getParams();
ECPoint point = JsseJce.decodePoint(encodedPoint, params.getCurve()); ECPoint point = JsseJce.decodePoint(encodedPoint, params.getCurve());
...@@ -108,10 +110,9 @@ final class ECDHCrypt { ...@@ -108,10 +110,9 @@ final class ECDHCrypt {
ECPublicKeySpec spec = new ECPublicKeySpec(point, params); ECPublicKeySpec spec = new ECPublicKeySpec(point, params);
PublicKey peerPublicKey = kf.generatePublic(spec); PublicKey peerPublicKey = kf.generatePublic(spec);
return getAgreedSecret(peerPublicKey); return getAgreedSecret(peerPublicKey);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException | java.io.IOException e) {
throw new RuntimeException("Could not generate secret", e); throw (SSLHandshakeException) new SSLHandshakeException(
} catch (java.io.IOException e) { "Could not generate secret").initCause(e);
throw new RuntimeException("Could not generate secret", e);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册