Skip to content

Commit 99b4bab

Browse files
author
John Jiang
committed
8263188: JSSE should fail fast if there isn't supported signature algorithm
Reviewed-by: xuelei
1 parent 6678b01 commit 99b4bab

File tree

6 files changed

+494
-13
lines changed

6 files changed

+494
-13
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -689,13 +689,16 @@ public void consume(ConnectionContext context,
689689
chc.handshakeProducers.put(SSLHandshake.CERTIFICATE.id,
690690
SSLHandshake.CERTIFICATE);
691691

692-
List<SignatureScheme> sss = new LinkedList<>();
693-
for (int id : crm.algorithmIds) {
694-
SignatureScheme ss = SignatureScheme.valueOf(id);
695-
if (ss != null) {
696-
sss.add(ss);
697-
}
692+
List<SignatureScheme> sss =
693+
SignatureScheme.getSupportedAlgorithms(
694+
chc.sslConfig,
695+
chc.algorithmConstraints, chc.negotiatedProtocol,
696+
crm.algorithmIds);
697+
if (sss == null || sss.isEmpty()) {
698+
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
699+
"No supported signature algorithm");
698700
}
701+
699702
chc.peerRequestedSignatureSchemes = sss;
700703
chc.peerRequestedCertSignSchemes = sss; // use the same schemes
701704
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ public void consume(ConnectionContext context,
279279
shc.sslConfig,
280280
shc.algorithmConstraints, shc.negotiatedProtocol,
281281
spec.signatureSchemes);
282+
if (sss == null || sss.isEmpty()) {
283+
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
284+
"No supported signature algorithm");
285+
}
282286
shc.peerRequestedSignatureSchemes = sss;
283287

284288
// If no "signature_algorithms_cert" extension is present, then
@@ -330,7 +334,7 @@ public void absent(ConnectionContext context,
330334
if (shc.negotiatedProtocol.useTLS13PlusSpec()) {
331335
throw shc.conContext.fatal(Alert.MISSING_EXTENSION,
332336
"No mandatory signature_algorithms extension in the " +
333-
"received CertificateRequest handshake message");
337+
"received ClientHello handshake message");
334338
}
335339
}
336340
}
@@ -503,6 +507,10 @@ public void consume(ConnectionContext context,
503507
chc.sslConfig,
504508
chc.algorithmConstraints, chc.negotiatedProtocol,
505509
spec.signatureSchemes);
510+
if (sss == null || sss.isEmpty()) {
511+
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
512+
"No supported signature algorithm");
513+
}
506514
chc.peerRequestedSignatureSchemes = sss;
507515

508516
// If no "signature_algorithms_cert" extension is present, then

test/jdk/javax/net/ssl/templates/SSLContextTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -478,7 +478,7 @@ private SSLContext createSSLContext(
478478
/*
479479
* Create an instance of KeyManager with the specified key materials.
480480
*/
481-
private KeyManager createKeyManager(
481+
static KeyManager createKeyManager(
482482
String[] keyMaterialCerts,
483483
String[] keyMaterialKeys,
484484
String[] keyMaterialKeyAlgs,
@@ -534,7 +534,7 @@ private KeyManager createKeyManager(
534534
/*
535535
* Create an instance of TrustManager with the specified trust materials.
536536
*/
537-
private TrustManager createTrustManager(
537+
static TrustManager createTrustManager(
538538
String[] trustedMaterials,
539539
ContextParameters params) throws Exception {
540540

test/jdk/javax/net/ssl/templates/SSLEngineTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void runTest() throws Exception {
197197
}
198198
}
199199

200-
private static boolean isOpen(SSLEngine engine) {
200+
static boolean isOpen(SSLEngine engine) {
201201
return (!engine.isOutboundDone() || !engine.isInboundDone());
202202
}
203203

@@ -240,7 +240,7 @@ protected static void runDelegatedTasks(SSLEngine engine) throws Exception {
240240
}
241241

242242
// Simple check to make sure everything came across as expected.
243-
private static void checkTransfer(ByteBuffer a, ByteBuffer b)
243+
static void checkTransfer(ByteBuffer a, ByteBuffer b)
244244
throws Exception {
245245
a.flip();
246246
b.flip();

0 commit comments

Comments
 (0)