提交 0cdcee61 编写于 作者: C coffeys

8153531: Improve exception messaging for RSAClientKeyExchange

Reviewed-by: xuelei
上级 f57a7560
...@@ -812,8 +812,9 @@ class DH_ServerKeyExchange extends ServerKeyExchange ...@@ -812,8 +812,9 @@ class DH_ServerKeyExchange extends ServerKeyExchange
if (!localSupportedSignAlgs.contains( if (!localSupportedSignAlgs.contains(
preferableSignatureAlgorithm)) { preferableSignatureAlgorithm)) {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"Unsupported SignatureAndHashAlgorithm in " + "Unsupported SignatureAndHashAlgorithm in " +
"ServerKeyExchange message"); "ServerKeyExchange message: " +
preferableSignatureAlgorithm);
} }
} else { } else {
this.preferableSignatureAlgorithm = null; this.preferableSignatureAlgorithm = null;
...@@ -846,7 +847,8 @@ class DH_ServerKeyExchange extends ServerKeyExchange ...@@ -846,7 +847,8 @@ class DH_ServerKeyExchange extends ServerKeyExchange
sig = RSASignature.getInstance(); sig = RSASignature.getInstance();
break; break;
default: default:
throw new SSLKeyException("neither an RSA or a DSA key"); throw new SSLKeyException(
"neither an RSA or a DSA key: " + algorithm);
} }
} }
...@@ -1096,7 +1098,8 @@ class ECDH_ServerKeyExchange extends ServerKeyExchange { ...@@ -1096,7 +1098,8 @@ class ECDH_ServerKeyExchange extends ServerKeyExchange {
preferableSignatureAlgorithm)) { preferableSignatureAlgorithm)) {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"Unsupported SignatureAndHashAlgorithm in " + "Unsupported SignatureAndHashAlgorithm in " +
"ServerKeyExchange message"); "ServerKeyExchange message: " +
preferableSignatureAlgorithm);
} }
} }
...@@ -1136,7 +1139,8 @@ class ECDH_ServerKeyExchange extends ServerKeyExchange { ...@@ -1136,7 +1139,8 @@ class ECDH_ServerKeyExchange extends ServerKeyExchange {
case "RSA": case "RSA":
return RSASignature.getInstance(); return RSASignature.getInstance();
default: default:
throw new NoSuchAlgorithmException("neither an RSA or a EC key"); throw new NoSuchAlgorithmException(
"neither an RSA or a EC key : " + keyAlgorithm);
} }
} }
...@@ -1343,7 +1347,8 @@ class CertificateRequest extends HandshakeMessage ...@@ -1343,7 +1347,8 @@ class CertificateRequest extends HandshakeMessage
algorithmsLen = input.getInt16(); algorithmsLen = input.getInt16();
if (algorithmsLen < 2) { if (algorithmsLen < 2) {
throw new SSLProtocolException( throw new SSLProtocolException(
"Invalid supported_signature_algorithms field"); "Invalid supported_signature_algorithms field: " +
algorithmsLen);
} }
algorithms = new ArrayList<SignatureAndHashAlgorithm>(); algorithms = new ArrayList<SignatureAndHashAlgorithm>();
...@@ -1362,7 +1367,8 @@ class CertificateRequest extends HandshakeMessage ...@@ -1362,7 +1367,8 @@ class CertificateRequest extends HandshakeMessage
if (remains != 0) { if (remains != 0) {
throw new SSLProtocolException( throw new SSLProtocolException(
"Invalid supported_signature_algorithms field"); "Invalid supported_signature_algorithms field. remains: " +
remains);
} }
} else { } else {
algorithms = new ArrayList<SignatureAndHashAlgorithm>(); algorithms = new ArrayList<SignatureAndHashAlgorithm>();
...@@ -1379,7 +1385,8 @@ class CertificateRequest extends HandshakeMessage ...@@ -1379,7 +1385,8 @@ class CertificateRequest extends HandshakeMessage
} }
if (len != 0) { if (len != 0) {
throw new SSLProtocolException("Bad CertificateRequest DN length"); throw new SSLProtocolException(
"Bad CertificateRequest DN length: " + len);
} }
authorities = v.toArray(new DistinguishedName[v.size()]); authorities = v.toArray(new DistinguishedName[v.size()]);
...@@ -1609,8 +1616,8 @@ static final class CertificateVerify extends HandshakeMessage { ...@@ -1609,8 +1616,8 @@ static final class CertificateVerify extends HandshakeMessage {
if (!localSupportedSignAlgs.contains( if (!localSupportedSignAlgs.contains(
preferableSignatureAlgorithm)) { preferableSignatureAlgorithm)) {
throw new SSLHandshakeException( throw new SSLHandshakeException(
"Unsupported SignatureAndHashAlgorithm in " + "Unsupported SignatureAndHashAlgorithm in " +
"CertificateVerify message"); "CertificateVerify message: " + preferableSignatureAlgorithm);
} }
} }
...@@ -1977,7 +1984,8 @@ static final class Finished extends HandshakeMessage { ...@@ -1977,7 +1984,8 @@ static final class Finished extends HandshakeMessage {
SecretKey prfKey = kg.generateKey(); SecretKey prfKey = kg.generateKey();
if ("RAW".equals(prfKey.getFormat()) == false) { if ("RAW".equals(prfKey.getFormat()) == false) {
throw new ProviderException( throw new ProviderException(
"Invalid PRF output, format must be RAW"); "Invalid PRF output, format must be RAW. " +
"Format received: " + prfKey.getFormat());
} }
byte[] finished = prfKey.getEncoded(); byte[] finished = prfKey.getEncoded();
return finished; return finished;
......
...@@ -67,7 +67,8 @@ final class RSAClientKeyExchange extends HandshakeMessage { ...@@ -67,7 +67,8 @@ final class RSAClientKeyExchange extends HandshakeMessage {
ProtocolVersion maxVersion, ProtocolVersion maxVersion,
SecureRandom generator, PublicKey publicKey) throws IOException { SecureRandom generator, PublicKey publicKey) throws IOException {
if (publicKey.getAlgorithm().equals("RSA") == false) { if (publicKey.getAlgorithm().equals("RSA") == false) {
throw new SSLKeyException("Public key not of type RSA"); throw new SSLKeyException("Public key not of type RSA: " +
publicKey.getAlgorithm());
} }
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
...@@ -98,7 +99,8 @@ final class RSAClientKeyExchange extends HandshakeMessage { ...@@ -98,7 +99,8 @@ final class RSAClientKeyExchange extends HandshakeMessage {
int messageSize, PrivateKey privateKey) throws IOException { int messageSize, PrivateKey privateKey) throws IOException {
if (privateKey.getAlgorithm().equals("RSA") == false) { if (privateKey.getAlgorithm().equals("RSA") == false) {
throw new SSLKeyException("Private key not of type RSA"); throw new SSLKeyException("Private key not of type RSA: " +
privateKey.getAlgorithm());
} }
if (currentVersion.v >= ProtocolVersion.TLS10.v) { if (currentVersion.v >= ProtocolVersion.TLS10.v) {
...@@ -159,8 +161,8 @@ final class RSAClientKeyExchange extends HandshakeMessage { ...@@ -159,8 +161,8 @@ final class RSAClientKeyExchange extends HandshakeMessage {
} }
} catch (InvalidKeyException ibk) { } catch (InvalidKeyException ibk) {
// the message is too big to process with RSA // the message is too big to process with RSA
throw new SSLProtocolException( throw new SSLException(
"Unable to process PreMasterSecret, may be too big"); "Unable to process PreMasterSecret", ibk);
} catch (Exception e) { } catch (Exception e) {
// unlikely to happen, otherwise, must be a provider exception // unlikely to happen, otherwise, must be a provider exception
if (debug != null && Debug.isOn("handshake")) { if (debug != null && Debug.isOn("handshake")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册