Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk13u-dev Public archive

Commit 239e727

Browse files
Alexey BakhtinYuri Nesterenko
Alexey Bakhtin
authored and
Yuri Nesterenko
committed
8206925: Support the certificate_authorities extension
Backport-of: 17a2989
1 parent c8350fc commit 239e727

File tree

8 files changed

+1089
-98
lines changed

8 files changed

+1089
-98
lines changed

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

+408
Large diffs are not rendered by default.

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, 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
@@ -200,14 +200,13 @@ String[] getKeyTypes() {
200200
}
201201

202202
X500Principal[] getAuthorities() {
203-
List<X500Principal> principals =
204-
new ArrayList<>(authorities.size());
203+
X500Principal[] principals = new X500Principal[authorities.size()];
204+
int i = 0;
205205
for (byte[] encoded : authorities) {
206-
X500Principal principal = new X500Principal(encoded);
207-
principals.add(principal);
206+
principals[i++] = new X500Principal(encoded);
208207
}
209208

210-
return principals.toArray(new X500Principal[0]);
209+
return principals;
211210
}
212211

213212
@Override
@@ -504,14 +503,13 @@ String[] getKeyTypes() {
504503
}
505504

506505
X500Principal[] getAuthorities() {
507-
List<X500Principal> principals =
508-
new ArrayList<>(authorities.size());
506+
X500Principal[] principals = new X500Principal[authorities.size()];
507+
int i = 0;
509508
for (byte[] encoded : authorities) {
510-
X500Principal principal = new X500Principal(encoded);
511-
principals.add(principal);
509+
principals[i++] = new X500Principal(encoded);
512510
}
513511

514-
return principals.toArray(new X500Principal[0]);
512+
return principals;
515513
}
516514

517515
@Override

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

+65-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,27 @@ enum SSLExtension implements SSLStringizer {
407407
null,
408408
PskKeyExchangeModesExtension.chOnTradeAbsence,
409409
PskKeyExchangeModesExtension.pkemStringizer),
410-
CERTIFICATE_AUTHORITIES (0x002F, "certificate_authorities"),
410+
411+
CH_CERTIFICATE_AUTHORITIES (0x002F, "certificate_authorities",
412+
SSLHandshake.CLIENT_HELLO,
413+
ProtocolVersion.PROTOCOLS_OF_13,
414+
CertificateAuthoritiesExtension.chNetworkProducer,
415+
CertificateAuthoritiesExtension.chOnLoadConsumer,
416+
null,
417+
null,
418+
null,
419+
CertificateAuthoritiesExtension.ssStringizer),
420+
421+
CR_CERTIFICATE_AUTHORITIES (0x002F, "certificate_authorities",
422+
SSLHandshake.CERTIFICATE_REQUEST,
423+
ProtocolVersion.PROTOCOLS_OF_13,
424+
CertificateAuthoritiesExtension.crNetworkProducer,
425+
CertificateAuthoritiesExtension.crOnLoadConsumer,
426+
null,
427+
null,
428+
null,
429+
CertificateAuthoritiesExtension.ssStringizer),
430+
411431
OID_FILTERS (0x0030, "oid_filters"),
412432
POST_HANDSHAKE_AUTH (0x0030, "post_handshake_auth"),
413433

@@ -725,6 +745,50 @@ static final class ClientExtensions {
725745
extensions.remove(CH_MAX_FRAGMENT_LENGTH);
726746
}
727747

748+
// To switch on certificate_authorities extension in ClientHello.
749+
//
750+
// Note: Please be careful to enable this extension in ClientHello.
751+
//
752+
// In practice, if the server certificate cannot be validated by
753+
// the underlying programs, the user may manually check the
754+
// certificate in order to access the service. The certificate
755+
// could be accepted manually, and the handshake continues. For
756+
// example, the browsers provide the manual option to accept
757+
// untrusted server certificate. If this extension is enabled in
758+
// the ClientHello handshake message, and the server's certificate
759+
// does not chain back to any of the CAs in the extension, then the
760+
// server will terminate the handshake and close the connection.
761+
// There is no chance for the client to perform the manual check.
762+
// Therefore, enabling this extension in ClientHello may lead to
763+
// unexpected compatibility issues for such cases.
764+
//
765+
// According to TLS 1.3 specification [RFC 8446] the maximum size
766+
// of the certificate_authorities extension is 2^16 bytes. The
767+
// maximum TLS record size is 2^14 bytes. If the handshake
768+
// message is bigger than maximum TLS record size, it should be
769+
// splitted into several records. In fact, some server
770+
// implementations do not allow ClientHello messages bigger than
771+
// the maximum TLS record size and will immediately abort the
772+
// connection with a fatal alert. Therefore, if the client trusts
773+
// too many certificate authorities, there may be unexpected
774+
// interoperability issues.
775+
//
776+
// Furthermore, if the client trusts more CAs such that it exceeds
777+
// the size limit of the extension, enabling this extension in
778+
// client side does not really make sense any longer as there is
779+
// no way to indicate the server certificate selection accurately.
780+
//
781+
// In general, a server does not use multiple certificates issued
782+
// from different CAs. It is not expected to use this extension a
783+
// lot in practice. When there is a need to use this extension
784+
// in ClientHello handshake message, please take care of the
785+
// potential compatibility and interoperability issues above.
786+
enableExtension = Utilities.getBooleanProperty(
787+
"jdk.tls.client.enableCAExtension", false);
788+
if (!enableExtension) {
789+
extensions.remove(CH_CERTIFICATE_AUTHORITIES);
790+
}
791+
728792
defaults = Collections.unmodifiableCollection(extensions);
729793
}
730794
}

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, 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
@@ -230,12 +230,14 @@ private SSLPossession createClientPossession(
230230
if (chc.conContext.transport instanceof SSLSocketImpl) {
231231
clientAlias = km.chooseClientAlias(
232232
new String[] { keyType },
233-
chc.peerSupportedAuthorities,
233+
chc.peerSupportedAuthorities == null ? null :
234+
chc.peerSupportedAuthorities.clone(),
234235
(SSLSocket)chc.conContext.transport);
235236
} else if (chc.conContext.transport instanceof SSLEngineImpl) {
236237
clientAlias = km.chooseEngineClientAlias(
237238
new String[] { keyType },
238-
chc.peerSupportedAuthorities,
239+
chc.peerSupportedAuthorities == null ? null :
240+
chc.peerSupportedAuthorities.clone(),
239241
(SSLEngine)chc.conContext.transport);
240242
}
241243

@@ -284,10 +286,14 @@ private SSLPossession createServerPossession(
284286
String serverAlias = null;
285287
if (shc.conContext.transport instanceof SSLSocketImpl) {
286288
serverAlias = km.chooseServerAlias(keyType,
287-
null, (SSLSocket)shc.conContext.transport);
289+
shc.peerSupportedAuthorities == null ? null :
290+
shc.peerSupportedAuthorities.clone(),
291+
(SSLSocket)shc.conContext.transport);
288292
} else if (shc.conContext.transport instanceof SSLEngineImpl) {
289293
serverAlias = km.chooseEngineServerAlias(keyType,
290-
null, (SSLEngine)shc.conContext.transport);
294+
shc.peerSupportedAuthorities == null ? null :
295+
shc.peerSupportedAuthorities.clone(),
296+
(SSLEngine)shc.conContext.transport);
291297
}
292298

293299
if (serverAlias == null) {

0 commit comments

Comments
 (0)