Skip to content

Commit 4ea8979

Browse files
committed
8365953: Key manager returns no certificates when handshakeSession is not an ExtendedSSLSession
Reviewed-by: djelinski, wetmore
1 parent 56f2f7a commit 4ea8979

File tree

3 files changed

+436
-44
lines changed

3 files changed

+436
-44
lines changed

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,17 @@ protected AlgorithmConstraints getAlgorithmConstraints(Socket socket) {
167167
return null;
168168
}
169169

170-
if (socket != null && socket.isConnected() &&
171-
socket instanceof SSLSocket sslSocket) {
172-
170+
if (socket instanceof SSLSocket sslSocket && sslSocket.isConnected()) {
173171
SSLSession session = sslSocket.getHandshakeSession();
174172

175-
if (session != null) {
176-
if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
177-
String[] peerSupportedSignAlgs = null;
178-
179-
if (session instanceof ExtendedSSLSession extSession) {
180-
// Peer supported certificate signature algorithms
181-
// sent with "signature_algorithms_cert" TLS extension.
182-
peerSupportedSignAlgs =
183-
extSession.getPeerSupportedSignatureAlgorithms();
184-
}
185-
186-
return SSLAlgorithmConstraints.forSocket(
187-
sslSocket, peerSupportedSignAlgs, true);
188-
}
173+
if (session instanceof ExtendedSSLSession extSession
174+
&& ProtocolVersion.useTLS12PlusSpec(
175+
extSession.getProtocol())) {
176+
// Use peer supported certificate signature algorithms
177+
// sent with "signature_algorithms_cert" TLS extension.
178+
return SSLAlgorithmConstraints.forSocket(sslSocket,
179+
extSession.getPeerSupportedSignatureAlgorithms(),
180+
true);
189181
}
190182

191183
return SSLAlgorithmConstraints.forSocket(sslSocket, true);
@@ -203,20 +195,15 @@ protected AlgorithmConstraints getAlgorithmConstraints(SSLEngine engine) {
203195

204196
if (engine != null) {
205197
SSLSession session = engine.getHandshakeSession();
206-
if (session != null) {
207-
if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
208-
String[] peerSupportedSignAlgs = null;
209-
210-
if (session instanceof ExtendedSSLSession extSession) {
211-
// Peer supported certificate signature algorithms
212-
// sent with "signature_algorithms_cert" TLS extension.
213-
peerSupportedSignAlgs =
214-
extSession.getPeerSupportedSignatureAlgorithms();
215-
}
216198

217-
return SSLAlgorithmConstraints.forEngine(
218-
engine, peerSupportedSignAlgs, true);
219-
}
199+
if (session instanceof ExtendedSSLSession extSession
200+
&& ProtocolVersion.useTLS12PlusSpec(
201+
extSession.getProtocol())) {
202+
// Use peer supported certificate signature algorithms
203+
// sent with "signature_algorithms_cert" TLS extension.
204+
return SSLAlgorithmConstraints.forEngine(engine,
205+
extSession.getPeerSupportedSignatureAlgorithms(),
206+
true);
220207
}
221208
}
222209

test/jdk/sun/security/ssl/X509KeyManager/AlgorithmConstraintsCheck.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@
5757
* @modules java.base/sun.security.x509
5858
* java.base/sun.security.util
5959
* @library /test/lib
60-
* @run main/othervm AlgorithmConstraintsCheck false SunX509 SHA256withRSA
61-
* @run main/othervm AlgorithmConstraintsCheck true SunX509 SHA256withRSA
62-
* @run main/othervm AlgorithmConstraintsCheck false PKIX SHA256withRSA
63-
* @run main/othervm AlgorithmConstraintsCheck true PKIX SHA256withRSA
60+
* @run main/othervm AlgorithmConstraintsCheck false SunX509
61+
* @run main/othervm AlgorithmConstraintsCheck true SunX509
62+
* @run main/othervm AlgorithmConstraintsCheck false PKIX
63+
* @run main/othervm AlgorithmConstraintsCheck true PKIX
6464
*/
6565

6666
public class AlgorithmConstraintsCheck {
6767

68-
private static final String CERT_ALIAS = "testalias";
69-
private static final String KEY_TYPE = "RSA";
68+
protected static final String CERT_ALIAS = "testalias";
69+
protected static final String KEY_TYPE = "EC";
70+
protected static final String CERT_SIG_ALG = "SHA256withECDSA";
7071

7172
public static void main(String[] args) throws Exception {
72-
if (args.length != 3) {
73+
if (args.length != 2) {
7374
throw new RuntimeException("Wrong number of arguments");
7475
}
7576

7677
String enabled = args[0];
7778
String kmAlg = args[1];
78-
String certSignatureAlg = args[2];
7979

8080
System.setProperty("jdk.tls.SunX509KeyManager.certChecking", enabled);
81-
SecurityUtils.addToDisabledTlsAlgs(certSignatureAlg);
81+
SecurityUtils.addToDisabledTlsAlgs(CERT_SIG_ALG);
8282

8383
X509ExtendedKeyManager km = (X509ExtendedKeyManager) getKeyManager(
84-
kmAlg, certSignatureAlg);
84+
kmAlg, KEY_TYPE, CERT_SIG_ALG);
8585
String serverAlias = km.chooseServerAlias(KEY_TYPE, null, null);
8686
String engineServerAlias = km.chooseEngineServerAlias(
8787
KEY_TYPE, null, null);
@@ -108,13 +108,13 @@ public static void main(String[] args) throws Exception {
108108
}
109109

110110
// PKIX KeyManager adds a cache prefix to an alias.
111-
private static String normalizeAlias(String alias) {
111+
protected static String normalizeAlias(String alias) {
112112
return alias.substring(alias.lastIndexOf(".") + 1);
113113
}
114114

115-
private static X509KeyManager getKeyManager(String kmAlg,
116-
String certSignatureAlg) throws Exception {
117-
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KEY_TYPE);
115+
protected static X509KeyManager getKeyManager(String kmAlg,
116+
String keyAlg, String certSignatureAlg) throws Exception {
117+
KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlg);
118118
KeyPair caKeys = kpg.generateKeyPair();
119119
KeyPair endpointKeys = kpg.generateKeyPair();
120120

0 commit comments

Comments
 (0)