Skip to content

Commit 328360c

Browse files
committed
BCJSSE: Separate client/server properties for max chain length
- jdk.tls.client.maxInboundCertificateChainLength - jdk.tls.server.maxInboundCertificateChainLength
1 parent b85889f commit 328360c

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

tls/src/main/java/org/bouncycastle/jsse/provider/JsseUtils.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ abstract class JsseUtils
7272
PropertyUtils.getBooleanSystemProperty("jdk.tls.allowLegacyMasterSecret", true);
7373
private static final boolean provTlsAllowLegacyResumption =
7474
PropertyUtils.getBooleanSystemProperty("jdk.tls.allowLegacyResumption", false);
75-
private static final int provTlsMaxCertificateChainLength =
76-
PropertyUtils.getIntegerSystemProperty("jdk.tls.maxCertificateChainLength", 10, 1, Integer.MAX_VALUE);
7775
private static final int provTlsMaxHandshakeMessageSize =
7876
PropertyUtils.getIntegerSystemProperty("jdk.tls.maxHandshakeMessageSize", 32768, 1024, Integer.MAX_VALUE);
7977
private static final boolean provTlsRequireCloseNotify =
@@ -84,6 +82,9 @@ abstract class JsseUtils
8482
private static final boolean provTlsUseExtendedMasterSecret =
8583
PropertyUtils.getBooleanSystemProperty("jdk.tls.useExtendedMasterSecret", true);
8684

85+
private static final int provTlsClientMaxInboundCertChainLen;
86+
private static final int provTlsServerMaxInboundCertChainLen;
87+
8788
static final Set<BCCryptoPrimitive> KEY_AGREEMENT_CRYPTO_PRIMITIVES_BC =
8889
Collections.unmodifiableSet(EnumSet.of(BCCryptoPrimitive.KEY_AGREEMENT));
8990
static final Set<BCCryptoPrimitive> KEY_ENCAPSULATION_CRYPTO_PRIMITIVES_BC =
@@ -102,6 +103,25 @@ static class BCUnknownServerName extends BCSNIServerName
102103
}
103104
}
104105

106+
static
107+
{
108+
int clientDefaultValue = 10;
109+
int serverDefaultValue = 8;
110+
111+
int provTlsMaxCertificateChainLength = PropertyUtils.getIntegerSystemProperty(
112+
"jdk.tls.maxCertificateChainLength", 0, 1, Integer.MAX_VALUE);
113+
if (provTlsMaxCertificateChainLength > 0)
114+
{
115+
clientDefaultValue = provTlsMaxCertificateChainLength;
116+
serverDefaultValue = provTlsMaxCertificateChainLength;
117+
}
118+
119+
provTlsClientMaxInboundCertChainLen = PropertyUtils.getIntegerSystemProperty(
120+
"jdk.tls.client.maxInboundCertificateChainLength", clientDefaultValue, 1, Integer.MAX_VALUE);
121+
provTlsServerMaxInboundCertChainLen = PropertyUtils.getIntegerSystemProperty(
122+
"jdk.tls.server.maxInboundCertificateChainLength", serverDefaultValue, 1, Integer.MAX_VALUE);
123+
}
124+
105125
static boolean allowLegacyMasterSecret()
106126
{
107127
return provTlsAllowLegacyMasterSecret;
@@ -270,14 +290,19 @@ static boolean equals(Object a, Object b)
270290
return a == b || (null != a && null != b && a.equals(b));
271291
}
272292

273-
static int getMaxCertificateChainLength()
293+
static int getMaxHandshakeMessageSize()
274294
{
275-
return provTlsMaxCertificateChainLength;
295+
return provTlsMaxHandshakeMessageSize;
276296
}
277297

278-
static int getMaxHandshakeMessageSize()
298+
static int getMaxInboundCertChainLenClient()
279299
{
280-
return provTlsMaxHandshakeMessageSize;
300+
return provTlsClientMaxInboundCertChainLen;
301+
}
302+
303+
static int getMaxInboundCertChainLenServer()
304+
{
305+
return provTlsServerMaxInboundCertChainLen;
281306
}
282307

283308
static ASN1ObjectIdentifier getNamedCurveOID(PublicKey publicKey)

tls/src/main/java/org/bouncycastle/jsse/provider/ProvTlsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public JcaTlsCrypto getCrypto()
396396
@Override
397397
public int getMaxCertificateChainLength()
398398
{
399-
return JsseUtils.getMaxCertificateChainLength();
399+
return JsseUtils.getMaxInboundCertChainLenClient();
400400
}
401401

402402
@Override

tls/src/main/java/org/bouncycastle/jsse/provider/ProvTlsServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public boolean allowLegacyResumption()
446446
@Override
447447
public int getMaxCertificateChainLength()
448448
{
449-
return JsseUtils.getMaxCertificateChainLength();
449+
return JsseUtils.getMaxInboundCertChainLenServer();
450450
}
451451

452452
@Override

0 commit comments

Comments
 (0)