mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8282723: Add constructors taking a cause to JSSE exceptions
Reviewed-by: wetmore, iris
This commit is contained in:
parent
3f923b82c3
commit
4df67426ed
30 changed files with 343 additions and 132 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -122,22 +122,15 @@ enum Alert {
|
|||
reason = (cause != null) ? cause.getMessage() : "";
|
||||
}
|
||||
|
||||
SSLException ssle;
|
||||
if (cause instanceof IOException) {
|
||||
ssle = new SSLException(reason);
|
||||
return new SSLException(reason, cause);
|
||||
} else if ((this == UNEXPECTED_MESSAGE)) {
|
||||
ssle = new SSLProtocolException(reason);
|
||||
return new SSLProtocolException(reason, cause);
|
||||
} else if (handshakeOnly) {
|
||||
ssle = new SSLHandshakeException(reason);
|
||||
return new SSLHandshakeException(reason, cause);
|
||||
} else {
|
||||
ssle = new SSLException(reason);
|
||||
return new SSLException(reason, cause);
|
||||
}
|
||||
|
||||
if (cause != null) {
|
||||
ssle.initCause(cause);
|
||||
}
|
||||
|
||||
return ssle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -295,8 +295,8 @@ final class DHClientKeyExchange {
|
|||
shc.handshakeCredentials.add(
|
||||
new DHECredentials(peerPublicKey, namedGroup));
|
||||
} catch (GeneralSecurityException | java.io.IOException e) {
|
||||
throw (SSLHandshakeException)(new SSLHandshakeException(
|
||||
"Could not generate DHPublicKey").initCause(e));
|
||||
throw new SSLHandshakeException(
|
||||
"Could not generate DHPublicKey", e);
|
||||
}
|
||||
|
||||
// update the states
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -160,8 +160,7 @@ final class ECDHKeyExchange {
|
|||
ka.doPhase(peerPublicKey, true);
|
||||
return ka.generateSecret("TlsPremasterSecret");
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(e);
|
||||
throw new SSLHandshakeException("Could not generate secret", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,8 +176,7 @@ final class ECDHKeyExchange {
|
|||
PublicKey peerPublicKey = kf.generatePublic(spec);
|
||||
return getAgreedSecret(peerPublicKey);
|
||||
} catch (GeneralSecurityException | java.io.IOException e) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(e);
|
||||
throw new SSLHandshakeException("Could not generate secret", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,8 +200,8 @@ final class ECDHKeyExchange {
|
|||
"ECPublicKey does not comply to algorithm constraints");
|
||||
}
|
||||
} catch (GeneralSecurityException | java.io.IOException e) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate ECPublicKey").initCause(e);
|
||||
throw new SSLHandshakeException(
|
||||
"Could not generate ECPublicKey", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -88,8 +88,7 @@ public class KAKeyDerivation implements SSLKeyDerivation {
|
|||
context, preMasterSecret);
|
||||
return kd.deriveKey("MasterSecret", params);
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,8 +124,7 @@ public class KAKeyDerivation implements SSLKeyDerivation {
|
|||
// derive handshake secret
|
||||
return hkdf.extract(saltSecret, sharedSecret, algorithm);
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -302,8 +302,7 @@ final class NewSessionTicket {
|
|||
return hkdf.expand(resumptionMasterSecret, hkdfInfo,
|
||||
hashAlg.hashLength, "TlsPreSharedKey");
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not derive PSK").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not derive PSK", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -52,8 +52,7 @@ final class SSLBasicKeyDerivation implements SSLKeyDerivation {
|
|||
return hkdf.expand(secret, hkdfInfo,
|
||||
((SecretSizeSpec)keySpec).length, algorithm);
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1167,17 +1167,13 @@ final class SSLEngineImpl extends SSLEngine implements SSLTransport {
|
|||
if (taskThrown instanceof RuntimeException) {
|
||||
throw new RuntimeException(msg, taskThrown);
|
||||
} else if (taskThrown instanceof SSLHandshakeException) {
|
||||
return (SSLHandshakeException)
|
||||
new SSLHandshakeException(msg).initCause(taskThrown);
|
||||
return new SSLHandshakeException(msg, taskThrown);
|
||||
} else if (taskThrown instanceof SSLKeyException) {
|
||||
return (SSLKeyException)
|
||||
new SSLKeyException(msg).initCause(taskThrown);
|
||||
return new SSLKeyException(msg, taskThrown);
|
||||
} else if (taskThrown instanceof SSLPeerUnverifiedException) {
|
||||
return (SSLPeerUnverifiedException)
|
||||
new SSLPeerUnverifiedException(msg).initCause(taskThrown);
|
||||
return new SSLPeerUnverifiedException(msg, taskThrown);
|
||||
} else if (taskThrown instanceof SSLProtocolException) {
|
||||
return (SSLProtocolException)
|
||||
new SSLProtocolException(msg).initCause(taskThrown);
|
||||
return new SSLProtocolException(msg, taskThrown);
|
||||
} else if (taskThrown instanceof SSLException) {
|
||||
return (SSLException)taskThrown;
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -242,8 +242,7 @@ final class SSLEngineInputRecord extends InputRecord implements SSLRecord {
|
|||
} catch (BadPaddingException bpe) {
|
||||
throw bpe;
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLProtocolException)(new SSLProtocolException(
|
||||
"Unexpected exception")).initCause(gse);
|
||||
throw new SSLProtocolException("Unexpected exception", gse);
|
||||
} finally {
|
||||
// consume a complete record
|
||||
packet.limit(srcLim);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -113,8 +113,7 @@ final class SSLSecretDerivation implements SSLKeyDerivation {
|
|||
HKDF hkdf = new HKDF(hashAlg.name);
|
||||
return hkdf.expand(secret, hkdfInfo, hashAlg.hashLength, algorithm);
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1709,19 +1709,13 @@ public final class SSLSocketImpl
|
|||
|
||||
private Plaintext handleEOF(EOFException eofe) throws IOException {
|
||||
if (requireCloseNotify || conContext.handshakeContext != null) {
|
||||
SSLException ssle;
|
||||
if (conContext.handshakeContext != null) {
|
||||
ssle = new SSLHandshakeException(
|
||||
"Remote host terminated the handshake");
|
||||
throw new SSLHandshakeException(
|
||||
"Remote host terminated the handshake", eofe);
|
||||
} else {
|
||||
ssle = new SSLProtocolException(
|
||||
"Remote host terminated the connection");
|
||||
throw new SSLProtocolException(
|
||||
"Remote host terminated the connection", eofe);
|
||||
}
|
||||
|
||||
if (eofe != null) {
|
||||
ssle.initCause(eofe);
|
||||
}
|
||||
throw ssle;
|
||||
} else {
|
||||
// treat as if we had received a close_notify
|
||||
conContext.isInputCloseNotified = true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
|
@ -263,8 +263,7 @@ final class SSLSocketInputRecord extends InputRecord implements SSLRecord {
|
|||
} catch (BadPaddingException bpe) {
|
||||
throw bpe;
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLProtocolException)(new SSLProtocolException(
|
||||
"Unexpected exception")).initCause(gse);
|
||||
throw new SSLProtocolException("Unexpected exception", gse);
|
||||
}
|
||||
|
||||
if (contentType != ContentType.HANDSHAKE.id &&
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -154,8 +154,8 @@ enum SSLTrafficKeyDerivation implements SSLKeyDerivationGenerator {
|
|||
ks.getKeyLength(cs),
|
||||
ks.getAlgorithm(cs, algorithm));
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException)(new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse));
|
||||
throw new SSLHandshakeException(
|
||||
"Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1205,8 +1205,7 @@ final class ServerHello {
|
|||
hc.handshakeKeyDerivation =
|
||||
new SSLSecretDerivation(hc, earlySecret);
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw (SSLHandshakeException) new SSLHandshakeException(
|
||||
"Could not generate secret").initCause(gse);
|
||||
throw new SSLHandshakeException("Could not generate secret", gse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -135,9 +135,8 @@ final class ServerNameExtension {
|
|||
nameType + "), name=" +
|
||||
(new String(encoded, StandardCharsets.UTF_8)) +
|
||||
", value={" +
|
||||
Utilities.toHexString(encoded) + "}");
|
||||
throw hc.conContext.fatal(Alert.ILLEGAL_PARAMETER,
|
||||
(SSLProtocolException)spe.initCause(iae));
|
||||
Utilities.toHexString(encoded) + "}", iae);
|
||||
throw hc.conContext.fatal(Alert.ILLEGAL_PARAMETER, spe);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
@ -146,9 +145,8 @@ final class ServerNameExtension {
|
|||
SSLProtocolException spe = new SSLProtocolException(
|
||||
"Illegal server name, type=(" + nameType +
|
||||
"), value={" +
|
||||
Utilities.toHexString(encoded) + "}");
|
||||
throw hc.conContext.fatal(Alert.ILLEGAL_PARAMETER,
|
||||
(SSLProtocolException)spe.initCause(iae));
|
||||
Utilities.toHexString(encoded) + "}", iae);
|
||||
throw hc.conContext.fatal(Alert.ILLEGAL_PARAMETER, spe);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue