11/*
2- * Copyright (c) 2018, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2023 , 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
@@ -108,9 +108,11 @@ final class SSLConfiguration implements Cloneable {
108108 static final int maxHandshakeMessageSize = GetIntegerAction .privilegedGetProperty (
109109 "jdk.tls.maxHandshakeMessageSize" , 32768 );
110110
111- // Set the max certificate chain length to 10
112- static final int maxCertificateChainLength = GetIntegerAction .privilegedGetProperty (
113- "jdk.tls.maxCertificateChainLength" , 10 );
111+ // Limit the certificate chain length accepted from clients
112+ static final int maxInboundClientCertChainLen ;
113+
114+ // Limit the certificate chain length accepted from servers
115+ static final int maxInboundServerCertChainLen ;
114116
115117 // To switch off the supported_groups extension for DHE cipher suite.
116118 static final boolean enableFFDHE =
@@ -133,6 +135,55 @@ final class SSLConfiguration implements Cloneable {
133135 useExtendedMasterSecret = supportExtendedMasterSecret ;
134136 }
135137
138+ static {
139+ boolean globalPropSet = false ;
140+
141+ // jdk.tls.maxCertificateChainLength property has no default
142+ Integer maxCertificateChainLength = GetIntegerAction .privilegedGetProperty (
143+ "jdk.tls.maxCertificateChainLength" );
144+ if (maxCertificateChainLength != null && maxCertificateChainLength >= 0 ) {
145+ globalPropSet = true ;
146+ }
147+
148+ /*
149+ * If either jdk.tls.server.maxInboundCertificateChainLength or
150+ * jdk.tls.client.maxInboundCertificateChainLength is set, it will
151+ * override jdk.tls.maxCertificateChainLength, regardless of whether
152+ * jdk.tls.maxCertificateChainLength is set or not.
153+ * If neither jdk.tls.server.maxInboundCertificateChainLength nor
154+ * jdk.tls.client.maxInboundCertificateChainLength is set, the behavior
155+ * depends on the setting of jdk.tls.maxCertificateChainLength. If
156+ * jdk.tls.maxCertificateChainLength is set, it falls back to that
157+ * value; otherwise, it defaults to 8 for
158+ * jdk.tls.server.maxInboundCertificateChainLength
159+ * and 10 for jdk.tls.client.maxInboundCertificateChainLength.
160+ * Users can independently set either
161+ * jdk.tls.server.maxInboundCertificateChainLength or
162+ * jdk.tls.client.maxInboundCertificateChainLength.
163+ */
164+ Integer inboundClientLen = GetIntegerAction .privilegedGetProperty (
165+ "jdk.tls.server.maxInboundCertificateChainLength" );
166+
167+ // Default for jdk.tls.server.maxInboundCertificateChainLength is 8
168+ if (inboundClientLen == null || inboundClientLen < 0 ) {
169+ maxInboundClientCertChainLen = globalPropSet ?
170+ maxCertificateChainLength : 8 ;
171+ } else {
172+ maxInboundClientCertChainLen = inboundClientLen ;
173+ }
174+
175+ Integer inboundServerLen = GetIntegerAction .privilegedGetProperty (
176+ "jdk.tls.client.maxInboundCertificateChainLength" );
177+
178+ // Default for jdk.tls.client.maxInboundCertificateChainLength is 10
179+ if (inboundServerLen == null || inboundServerLen < 0 ) {
180+ maxInboundServerCertChainLen = globalPropSet ?
181+ maxCertificateChainLength : 10 ;
182+ } else {
183+ maxInboundServerCertChainLen = inboundServerLen ;
184+ }
185+ }
186+
136187 SSLConfiguration (SSLContextImpl sslContext , boolean isClientMode ) {
137188
138189 // Configurations with SSLParameters, default values.
0 commit comments