Skip to content

Commit 9614f9e

Browse files
Add back sslContext() to SslContextHandler. Used in tests.
Signed-off-by: Finn Carroll <carrofin@amazon.com>
1 parent e09e6c8 commit 9614f9e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/org/opensearch/security/ssl/OpenSearchSecureSettingsFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public Optional<SecureAuxTransportSettingsProvider> getSecureAuxTransportSetting
240240
@Override
241241
public Optional<SSLContext> buildSecureAuxServerTransportContext(Settings settings, AuxTransport transport) {
242242
CertType auxCertType = new CertType(transport.settingKey());
243-
return sslSettingsManager.sslContextHandler(auxCertType).map(SslContextHandler::sslContext);
243+
return sslSettingsManager.sslContextHandler(auxCertType).map(SslContextHandler::tryFetchSSLContext);
244244
}
245245

246246
@Override

src/main/java/org/opensearch/security/ssl/SslContextHandler.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,24 @@ public SslConfiguration sslConfiguration() {
6767
}
6868

6969
/**
70-
* Only JDK provider is supported, so we expect only JdkSslContext.
71-
* @return null if context cannot be fetched from io.netty.handler.ssl.SslContext child type.
70+
* Attempt to fetch the underlying io.netty.handler.ssl.SslContext as a javax SSLContext.
71+
* As JDK is the only supported provider we expect sslContext is always of type JdkSslContext,
72+
* allowing us to extract the javax.net.ssl.SSLContext delegate. Providing a javax SSLContext is
73+
* desirable for dependencies which want to access security settings without taking on netty as a dependency.
74+
* @return null if context cannot be fetched as JdkSslContext.
7275
*/
73-
public SSLContext sslContext() {
76+
public SSLContext tryFetchSSLContext() {
7477
if (sslContext instanceof JdkSslContext) {
7578
return ((JdkSslContext) sslContext).context();
7679
}
7780
return null;
7881
}
7982

83+
// public for testing
84+
public SslContext sslContext() {
85+
return sslContext;
86+
}
87+
8088
public Stream<Certificate> certificates() {
8189
return Stream.concat(authorityCertificates(), keyMaterialCertificates())
8290
.sorted((c1, c2) -> Boolean.compare(c1.hasPrivateKey(), c2.hasPrivateKey()));

0 commit comments

Comments
 (0)