GeezerVison is showing github.com — Make it possible to notify the TrustManager of resumed sessions by chrisvest · Pull Request #14358 · netty/netty
Make it possible to notify the TrustManager of resumed sessions
#14358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6e68fe7
Make it possible to notify the TrustManager of resumed sessions
chrisvest Sep 21, 2024
09a3811
Test debugging
chrisvest Sep 22, 2024
f20b728
Test debugging
chrisvest Sep 23, 2024
03fc08d
Hide the ResumptionController from the public API
chrisvest Sep 23, 2024
4391465
Disable the test for Conscrypt
chrisvest Sep 23, 2024
e419115
Test debugging
chrisvest Sep 23, 2024
21e0850
Javadocs for ResumableX509ExtendedTrustManager
chrisvest Sep 23, 2024
ebeaba2
Remove any stored validation on handshake failure
chrisvest Sep 23, 2024
467ddb7
Reenable test for Constrypt
chrisvest Sep 23, 2024
f5c2823
Update javadocs
chrisvest Sep 24, 2024
d55e004
Revert "Reenable test for Constrypt"
chrisvest Sep 24, 2024
921e3f6
Address some comments
chrisvest Sep 24, 2024
115c8f8
Checkstyle
chrisvest Sep 24, 2024
d37adf5
Call resumption controller after completing handshake promise but bef…
chrisvest Sep 24, 2024
703ae2d
Add tests verifying behavior when trust manager resume throws
chrisvest Sep 24, 2024
f44faed
Revert unnecessary changes in DefaultPromise
chrisvest Sep 25, 2024
ddefe88
Review and rebase fixes
chrisvest Sep 25, 2024
48012aa
Add TLS session resumption tests for different transports
chrisvest Sep 25, 2024
774d11d
Checkstyle
chrisvest Sep 25, 2024
5c57d27
Animal sniffer
chrisvest Sep 25, 2024
7a9bbba
Fix SSLEngineTests to not fail for engines that don't resume sessions
chrisvest Sep 25, 2024
64930a5
Fix test flakiness
chrisvest Sep 26, 2024
f8fe470
Small cleanups
chrisvest Sep 26, 2024
d1f1d23
Only run the original SocketSslSessionReuseTest.testSslSessionReuse o…
chrisvest Sep 26, 2024
81aec45
Attempt to catch the StacklessClosedChannelException in SocketSslSess…
chrisvest Sep 26, 2024
7535e1b
Attempt to fix the OIO flakiness in SocketSslSessionReuseTest.testSsl…
chrisvest Sep 26, 2024
e525cbf
Address review comments
chrisvest Sep 26, 2024
72599ad
Wrap an UnsupportedOperationException in CertificateException when ca…
chrisvest Sep 26, 2024
14f77c9
Remove test for TLSv1.3 because it might not be supported by all prov…
chrisvest Sep 26, 2024
6ea0554
Address more review comments
chrisvest Sep 26, 2024
52cb631
Preserve nulls in the certificate array
chrisvest Sep 26, 2024
ac285f8
Fix buffer leaks in SSLEngineTest
chrisvest Sep 26, 2024
File filter
Filter by extension
.java
(18)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -176,7 +176,7 @@ public JdkSslClientContext(
long sessionCacheSize, long sessionTimeout) throws SSLException {
super(newSSLContext(provider, toX509CertificatesInternal(trustCertCollectionFile),
trustManagerFactory, null, null,
null, null, sessionCacheSize, sessionTimeout, null, KeyStore.getDefaultType()), true,
null, null, sessionCacheSize, sessionTimeout, null, KeyStore.getDefaultType(), null ), true,
ciphers, cipherFilter, apn, ClientAuth.NONE, null, false);
}
Expand Down
Expand Up
@@ -260,7 +260,7 @@ public JdkSslClientContext(File trustCertCollectionFile, TrustManagerFactory tru
trustCertCollectionFile), trustManagerFactory,
toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout,
null, KeyStore.getDefaultType()), true,
null, KeyStore.getDefaultType(), null ), true,
ciphers, cipherFilter, apn, ClientAuth.NONE, null, false);
}
Expand All
@@ -269,21 +269,23 @@ public JdkSslClientContext(File trustCertCollectionFile, TrustManagerFactory tru
X509Certificate[] keyCertChain, PrivateKey key, String keyPassword,
KeyManagerFactory keyManagerFactory, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
ApplicationProtocolConfig apn, String[] protocols, long sessionCacheSize, long sessionTimeout,
SecureRandom secureRandom, String keyStoreType, String endpointIdentificationAlgorithm)
SecureRandom secureRandom, String keyStoreType, String endpointIdentificationAlgorithm,
ResumptionController resumptionController)
throws SSLException {
super(newSSLContext(sslContextProvider, trustCertCollection, trustManagerFactory,
keyCertChain, key, keyPassword, keyManagerFactory, sessionCacheSize,
sessionTimeout, secureRandom, keyStoreType),
sessionTimeout, secureRandom, keyStoreType, resumptionController ),
true, ciphers, cipherFilter, toNegotiator(apn, false), ClientAuth.NONE, protocols, false,
endpointIdentificationAlgorithm);
endpointIdentificationAlgorithm, resumptionController );
}
private static SSLContext newSSLContext(Provider sslContextProvider,
X509Certificate[] trustCertCollection,
TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain,
PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
long sessionCacheSize, long sessionTimeout,
SecureRandom secureRandom, String keyStore) throws SSLException {
SecureRandom secureRandom, String keyStore,
ResumptionController resumptionController) throws SSLException {
try {
if (trustCertCollection != null) {
trustManagerFactory = buildTrustManagerFactory(trustCertCollection, trustManagerFactory, keyStore);
Expand All
@@ -295,7 +297,8 @@ private static SSLContext newSSLContext(Provider sslContextProvider,
SSLContext ctx = sslContextProvider == null ? SSLContext.getInstance(PROTOCOL)
: SSLContext.getInstance(PROTOCOL, sslContextProvider);
ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
trustManagerFactory == null ? null :
wrapIfNeeded(trustManagerFactory.getTrustManagers(), resumptionController),
Comment thread
Fixed
Uh oh!
There was an error while loading. Please reload this page.
secureRandom);
SSLSessionContext sessCtx = ctx.getClientSessionContext();
Expand All
@@ -313,4 +316,13 @@ private static SSLContext newSSLContext(Provider sslContextProvider,
throw new SSLException("failed to initialize the client-side SSL context", e);
}
}
private static TrustManager[] wrapIfNeeded(TrustManager[] tms, ResumptionController resumptionController) {
if (resumptionController != null) {
for (int i = 0; i < tms.length; i++) {
tms[i] = resumptionController.wrapIfNeeded(tms[i]);
}
}
return tms;
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -261,14 +261,14 @@ public JdkSslContext(SSLContext sslContext,
@SuppressWarnings("deprecation")
JdkSslContext(SSLContext sslContext, boolean isClient, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
JdkApplicationProtocolNegotiator apn, ClientAuth clientAuth, String[] protocols, boolean startTls) {
this(sslContext, isClient, ciphers, cipherFilter, apn, clientAuth, protocols, startTls, null);
this(sslContext, isClient, ciphers, cipherFilter, apn, clientAuth, protocols, startTls, null, null );
}
@SuppressWarnings("deprecation")
JdkSslContext(SSLContext sslContext, boolean isClient, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
JdkApplicationProtocolNegotiator apn, ClientAuth clientAuth, String[] protocols, boolean startTls,
String endpointIdentificationAlgorithm) {
super(startTls);
String endpointIdentificationAlgorithm, ResumptionController resumptionController ) {
super(startTls, resumptionController );
this.apn = checkNotNull(apn, "apn");
this.clientAuth = checkNotNull(clientAuth, "clientAuth");
this.sslContext = checkNotNull(sslContext, "sslContext");
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -92,7 +92,7 @@ static void checkIfWrappingTrustManagerIsSupported() throws CertificateException
tm.init((KeyStore) null);
TrustManager[] managers = tm.getTrustManagers();
ctx.init(kmf.getKeyManagers(), wrapTrustManagerIfNeeded(managers), null);
ctx.init(kmf.getKeyManagers(), wrapTrustManagerIfNeeded(managers, null ), null);
}
/**
Expand Down
Expand Up
@@ -208,7 +208,7 @@ public JdkSslServerContext(
long sessionCacheSize, long sessionTimeout, String keyStore) throws SSLException {
super(newSSLContext(provider, null, null,
toX509CertificatesInternal(certChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, null, sessionCacheSize, sessionTimeout, null, keyStore), false,
keyPassword, null, sessionCacheSize, sessionTimeout, null, keyStore, null ), false,
ciphers, cipherFilter, apn, ClientAuth.NONE, null, false);
}
Expand Down
Expand Up
@@ -248,7 +248,7 @@ public JdkSslServerContext(File trustCertCollectionFile, TrustManagerFactory tru
long sessionCacheSize, long sessionTimeout) throws SSLException {
super(newSSLContext(null, toX509CertificatesInternal(trustCertCollectionFile), trustManagerFactory,
toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout, null, null), false,
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout, null, null, null ), false,
ciphers, cipherFilter, apn, ClientAuth.NONE, null, false);
}
Expand Down
Expand Up
@@ -290,7 +290,7 @@ public JdkSslServerContext(File trustCertCollectionFile, TrustManagerFactory tru
super(newSSLContext(null, toX509CertificatesInternal(trustCertCollectionFile), trustManagerFactory,
toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout,
null, KeyStore.getDefaultType()), false,
null, KeyStore.getDefaultType(), null ), false,
ciphers, cipherFilter, apn, ClientAuth.NONE, null, false);
}
Expand All
@@ -300,17 +300,20 @@ public JdkSslServerContext(File trustCertCollectionFile, TrustManagerFactory tru
KeyManagerFactory keyManagerFactory, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout,
ClientAuth clientAuth, String[] protocols, boolean startTls,
SecureRandom secureRandom, String keyStore) throws SSLException {
SecureRandom secureRandom, String keyStore, ResumptionController resumptionController)
throws SSLException {
super(newSSLContext(provider, trustCertCollection, trustManagerFactory, keyCertChain, key,
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout, secureRandom, keyStore), false,
ciphers, cipherFilter, toNegotiator(apn, true), clientAuth, protocols, startTls);
keyPassword, keyManagerFactory, sessionCacheSize, sessionTimeout, secureRandom, keyStore,
resumptionController),
false, ciphers, cipherFilter, toNegotiator(apn, true), clientAuth, protocols, startTls, null,
resumptionController);
}
private static SSLContext newSSLContext(Provider sslContextProvider, X509Certificate[] trustCertCollection,
TrustManagerFactory trustManagerFactory, X509Certificate[] keyCertChain,
PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
long sessionCacheSize, long sessionTimeout,
SecureRandom secureRandom, String keyStore )
long sessionCacheSize, long sessionTimeout, SecureRandom secureRandom,
String keyStore, ResumptionController resumptionController )
throws SSLException {
if (key == null && keyManagerFactory == null) {
throw new NullPointerException("key, keyManagerFactory");
Expand All
@@ -335,7 +338,7 @@ private static SSLContext newSSLContext(Provider sslContextProvider, X509Certifi
SSLContext ctx = sslContextProvider == null ? SSLContext.getInstance(PROTOCOL)
: SSLContext.getInstance(PROTOCOL, sslContextProvider);
ctx.init(keyManagerFactory.getKeyManagers(),
wrapTrustManagerIfNeeded(trustManagerFactory.getTrustManagers()),
wrapTrustManagerIfNeeded(trustManagerFactory.getTrustManagers(), resumptionController ),
secureRandom);
SSLSessionContext sessCtx = ctx.getServerSessionContext();
Expand All
@@ -355,10 +358,14 @@ private static SSLContext newSSLContext(Provider sslContextProvider, X509Certifi
}
@SuppressJava6Requirement(reason = "Guarded by java version check")
private static TrustManager[] wrapTrustManagerIfNeeded(TrustManager[] trustManagers) {
private static TrustManager[] wrapTrustManagerIfNeeded(
TrustManager[] trustManagers, ResumptionController resumptionController) {
if (WRAP_TRUST_MANAGER && PlatformDependent.javaVersion() >= 7) {
for (int i = 0; i < trustManagers.length; i++) {
TrustManager tm = trustManagers[i];
if (resumptionController != null) {
tm = resumptionController.wrapIfNeeded(tm);
}
if (tm instanceof X509ExtendedTrustManager) {
// Wrap the TrustManager to provide a better exception message for users to debug hostname
// validation failures.
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -178,24 +178,25 @@ public OpenSslClientContext(File trustCertCollectionFile, TrustManagerFactory tr
this(toX509CertificatesInternal(trustCertCollectionFile), trustManagerFactory,
toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, keyManagerFactory, ciphers, cipherFilter, apn, null, sessionCacheSize,
sessionTimeout, false, KeyStore.getDefaultType(), null);
sessionTimeout, false, KeyStore.getDefaultType(), null, null );
}
OpenSslClientContext(X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory,
X509Certificate[] keyCertChain, PrivateKey key, String keyPassword,
KeyManagerFactory keyManagerFactory, Iterable<String> ciphers,
CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn, String[] protocols,
long sessionCacheSize, long sessionTimeout, boolean enableOcsp, String keyStore,
String endpointIdentificationAlgorithm, Map.Entry<SslContextOption<?>, Object>... options)
String endpointIdentificationAlgorithm, ResumptionController resumptionController,
Map.Entry<SslContextOption<?>, Object>... options)
throws SSLException {
super(ciphers, cipherFilter, apn, SSL.SSL_MODE_CLIENT, keyCertChain,
ClientAuth.NONE, protocols, false, endpointIdentificationAlgorithm, enableOcsp, options);
super(ciphers, cipherFilter, apn, SSL.SSL_MODE_CLIENT, keyCertChain, ClientAuth.NONE, protocols, false,
endpointIdentificationAlgorithm, enableOcsp, resumptionController , options);
boolean success = false;
try {
OpenSslKeyMaterialProvider.validateKeyMaterialSupported(keyCertChain, key, keyPassword);
sessionContext = newSessionContext(this, ctx, engineMap, trustCertCollection, trustManagerFactory,
keyCertChain, key, keyPassword, keyManagerFactory, keyStore,
sessionCacheSize, sessionTimeout);
sessionCacheSize, sessionTimeout, resumptionController );
success = true;
} finally {
if (!success) {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -31,19 +31,22 @@ public abstract class OpenSslContext extends ReferenceCountedOpenSslContext {
OpenSslContext(Iterable<String> ciphers, CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apnCfg,
int mode, Certificate[] keyCertChain,
ClientAuth clientAuth, String[] protocols, boolean startTls, String endpointIdentificationAlgorithm,
boolean enableOcsp, Map.Entry<SslContextOption<?>, Object>... options)
boolean enableOcsp, ResumptionController resumptionController,
Map.Entry<SslContextOption<?>, Object>... options)
throws SSLException {
super(ciphers, cipherFilter, toNegotiator(apnCfg), mode, keyCertChain,
clientAuth, protocols, startTls, endpointIdentificationAlgorithm, enableOcsp, false, options);
clientAuth, protocols, startTls, endpointIdentificationAlgorithm, enableOcsp, false,
resumptionController, options);
}
OpenSslContext(Iterable<String> ciphers, CipherSuiteFilter cipherFilter, OpenSslApplicationProtocolNegotiator apn,
int mode, Certificate[] keyCertChain,
ClientAuth clientAuth, String[] protocols, boolean startTls, boolean enableOcsp,
ResumptionController resumptionController,
Map.Entry<SslContextOption<?>, Object>... options)
throws SSLException {
super(ciphers, cipherFilter, apn, mode, keyCertChain,
clientAuth, protocols, startTls, null, enableOcsp, false, options);
clientAuth, protocols, startTls, null, enableOcsp, false, resumptionController, options);
}
@Override
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -323,19 +323,21 @@ public OpenSslServerContext(
this(toX509CertificatesInternal(trustCertCollectionFile), trustManagerFactory,
toX509CertificatesInternal(keyCertChainFile), toPrivateKeyInternal(keyFile, keyPassword),
keyPassword, keyManagerFactory, ciphers, cipherFilter,
apn, sessionCacheSize, sessionTimeout, ClientAuth.NONE, null, false, false, KeyStore.getDefaultType());
apn, sessionCacheSize, sessionTimeout, ClientAuth.NONE, null, false, false, KeyStore.getDefaultType(),
null);
}
OpenSslServerContext(
X509Certificate[] trustCertCollection, TrustManagerFactory trustManagerFactory,
X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
Iterable<String> ciphers, CipherSuiteFilter cipherFilter, ApplicationProtocolConfig apn,
long sessionCacheSize, long sessionTimeout, ClientAuth clientAuth, String[] protocols, boolean startTls,
boolean enableOcsp, String keyStore, Map.Entry<SslContextOption<?>, Object>... options)
boolean enableOcsp, String keyStore, ResumptionController resumptionController,
Map.Entry<SslContextOption<?>, Object>... options)
throws SSLException {
this(trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword, keyManagerFactory, ciphers,
cipherFilter, toNegotiator(apn), sessionCacheSize, sessionTimeout, clientAuth, protocols, startTls,
enableOcsp, keyStore, options);
enableOcsp, keyStore, resumptionController, options);
}
@SuppressWarnings("deprecation")
Expand All
@@ -344,18 +346,19 @@ private OpenSslServerContext(
X509Certificate[] keyCertChain, PrivateKey key, String keyPassword, KeyManagerFactory keyManagerFactory,
Iterable<String> ciphers, CipherSuiteFilter cipherFilter, OpenSslApplicationProtocolNegotiator apn,
long sessionCacheSize, long sessionTimeout, ClientAuth clientAuth, String[] protocols, boolean startTls,
boolean enableOcsp, String keyStore, Map.Entry<SslContextOption<?>, Object>... options)
boolean enableOcsp, String keyStore, ResumptionController resumptionController,
Map.Entry<SslContextOption<?>, Object>... options)
throws SSLException {
super(ciphers, cipherFilter, apn, SSL.SSL_MODE_SERVER, keyCertChain,
clientAuth, protocols, startTls, enableOcsp, options);
clientAuth, protocols, startTls, enableOcsp, resumptionController, options);
// Create a new SSL_CTX and configure it.
boolean success = false;
try {
OpenSslKeyMaterialProvider.validateKeyMaterialSupported(keyCertChain, key, keyPassword);
sessionContext = newSessionContext(this, ctx, engineMap, trustCertCollection, trustManagerFactory,
keyCertChain, key, keyPassword, keyManagerFactory, keyStore,
sessionCacheSize, sessionTimeout);
sessionCacheSize, sessionTimeout, resumptionController );
success = true;
} finally {
if (!success) {
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.