Skip to content

Commit

Permalink
Allow to change the limit for the maximum size of the certificate cha…
Browse files Browse the repository at this point in the history
…in. (#13355)


Motivation:

Sometimes large certificate chains are used which might be larger then the default maximum size.

Modifications:

- Allow to configure the limit
- Add unit test

Result:

Be able to adjust limit
  • Loading branch information
normanmaurer committed Apr 24, 2023
1 parent 97a7ed0 commit b2afca4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

<properties>
<!-- Keep in sync with ../pom.xml -->
<tcnative.version>2.0.59.Final</tcnative.version>
<tcnative.version>2.0.60.Final</tcnative.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ private OpenSslContextOption(String name) {
*/
public static final OpenSslContextOption<OpenSslCertificateCompressionConfig> CERTIFICATE_COMPRESSION_ALGORITHMS =
new OpenSslContextOption<OpenSslCertificateCompressionConfig>("CERTIFICATE_COMPRESSION_ALGORITHMS");

/**
* Set the maximum number of bytes that is allowed during the handshake for certificate chain.
*/
public static final OpenSslContextOption<Integer> MAX_CERTIFICATE_LIST_BYTES =
new OpenSslContextOption<Integer>("MAX_CERTIFICATE_LIST_BYTES");
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene
OpenSslPrivateKeyMethod privateKeyMethod = null;
OpenSslAsyncPrivateKeyMethod asyncPrivateKeyMethod = null;
OpenSslCertificateCompressionConfig certCompressionConfig = null;
Integer maxCertificateList = null;

if (ctxOptions != null) {
for (Map.Entry<SslContextOption<?>, Object> ctxOpt : ctxOptions) {
Expand All @@ -242,6 +243,8 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene
asyncPrivateKeyMethod = (OpenSslAsyncPrivateKeyMethod) ctxOpt.getValue();
} else if (option == OpenSslContextOption.CERTIFICATE_COMPRESSION_ALGORITHMS) {
certCompressionConfig = (OpenSslCertificateCompressionConfig) ctxOpt.getValue();
} else if (option == OpenSslContextOption.MAX_CERTIFICATE_LIST_BYTES) {
maxCertificateList = (Integer) ctxOpt.getValue();
} else {
logger.debug("Skipping unsupported " + SslContextOption.class.getSimpleName()
+ ": " + ctxOpt.getKey());
Expand Down Expand Up @@ -416,6 +419,9 @@ public ApplicationProtocolConfig.SelectedListenerFailureBehavior selectedListene
}
}
}
if (maxCertificateList != null) {
SSLContext.setMaxCertList(ctx, maxCertificateList);
}
// Set the curves.
SSLContext.setCurvesList(ctx, OpenSsl.NAMED_GROUPS);
success = true;
Expand Down
39 changes: 39 additions & 0 deletions handler/src/test/java/io/netty/handler/ssl/OpenSslEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1601,4 +1601,43 @@ public void testExtraDataInLastSrcBufferForClientUnwrapNonjdkCompatabilityMode()
wrapEngine(clientSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine()),
wrapEngine(serverSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine()));
}

@MethodSource("newTestParams")
@ParameterizedTest
public void testMaxCertificateList(final SSLEngineTestParam param) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
clientSslCtx = wrapContext(param, SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.keyManager(ssc.certificate(), ssc.privateKey())
.sslProvider(sslClientProvider())
.sslContextProvider(clientSslContextProvider())
.protocols(param.protocols())
.ciphers(param.ciphers())
.option(OpenSslContextOption.MAX_CERTIFICATE_LIST_BYTES, 10)
.build());
serverSslCtx = wrapContext(param, SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
.sslProvider(sslServerProvider())
.sslContextProvider(serverSslContextProvider())
.protocols(param.protocols())
.ciphers(param.ciphers())
.option(OpenSslContextOption.MAX_CERTIFICATE_LIST_BYTES, 10)
.clientAuth(ClientAuth.REQUIRE)
.build());

final SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
final SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));

try {
assertThrows(SSLHandshakeException.class, new Executable() {
@Override
public void execute() throws Throwable {
handshake(param.type(), param.delegate(), client, server);
}
});
} finally {
cleanupClientSslEngine(client);
cleanupServerSslEngine(server);
ssc.delete();
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
<os.detection.classifierWithLikes>fedora,suse,arch</os.detection.classifierWithLikes>
<tcnative.artifactId>netty-tcnative</tcnative.artifactId>
<!-- Keep in sync with bom/pom.xml -->
<tcnative.version>2.0.59.Final</tcnative.version>
<tcnative.version>2.0.60.Final</tcnative.version>
<tcnative.classifier>${os.detected.classifier}</tcnative.classifier>
<conscrypt.groupId>org.conscrypt</conscrypt.groupId>
<conscrypt.artifactId>conscrypt-openjdk-uber</conscrypt.artifactId>
Expand Down

0 comments on commit b2afca4

Please sign in to comment.