use of software.amazon.awssdk.http.TlsKeyManagersProvider in project aws-sdk-java-v2 by aws.
the class AwaitCloseChannelPoolMapTest method usesProvidedKeyManagersProvider.
@Test
public void usesProvidedKeyManagersProvider() {
TlsKeyManagersProvider provider = mock(TlsKeyManagersProvider.class);
AttributeMap config = AttributeMap.builder().put(TLS_KEY_MANAGERS_PROVIDER, provider).build();
channelPoolMap = AwaitCloseChannelPoolMap.builder().sdkChannelOptions(new SdkChannelOptions()).sdkEventLoopGroup(SdkEventLoopGroup.builder().build()).protocol(Protocol.HTTP1_1).configuration(new NettyConfiguration(config.merge(GLOBAL_HTTP_DEFAULTS))).build();
ChannelPool channelPool = channelPoolMap.newPool(URI.create("https://localhost:" + mockProxy.port()));
channelPool.acquire().awaitUninterruptibly();
verify(provider).keyManagers();
}
use of software.amazon.awssdk.http.TlsKeyManagersProvider in project aws-sdk-java-v2 by aws.
the class NettyClientTlsAuthTest method builderUsesProvidedKeyManagersProvider.
@Test
public void builderUsesProvidedKeyManagersProvider() {
TlsKeyManagersProvider mockKeyManagersProvider = mock(TlsKeyManagersProvider.class);
netty = NettyNioAsyncHttpClient.builder().proxyConfiguration(proxyCfg).tlsKeyManagersProvider(mockKeyManagersProvider).buildWithDefaults(DEFAULTS);
try {
sendRequest(netty, new RecordingResponseHandler());
} catch (Exception ignored) {
}
verify(mockKeyManagersProvider).keyManagers();
}
use of software.amazon.awssdk.http.TlsKeyManagersProvider in project aws-sdk-java-v2 by aws.
the class SslContextProviderTest method customizedKeyManagerPresent_shouldUseCustomized.
@Test
public void customizedKeyManagerPresent_shouldUseCustomized() {
TlsKeyManagersProvider mockProvider = Mockito.mock(TlsKeyManagersProvider.class);
SslContextProvider sslContextProvider = new SslContextProvider(new NettyConfiguration(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, false).put(TLS_KEY_MANAGERS_PROVIDER, mockProvider).build()), Protocol.HTTP1_1, SslProvider.JDK);
sslContextProvider.sslContext();
Mockito.verify(mockProvider).keyManagers();
}
use of software.amazon.awssdk.http.TlsKeyManagersProvider in project aws-sdk-java-v2 by aws.
the class UrlConnectionHttpClient method getSslContext.
private SSLContext getSslContext(AttributeMap options) {
Validate.isTrue(options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) == null || !options.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES), "A TlsTrustManagerProvider can't be provided if TrustAllCertificates is also set");
TrustManager[] trustManagers = null;
if (options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) != null) {
trustManagers = options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER).trustManagers();
}
if (options.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)) {
log.warn(() -> "SSL Certificate verification is disabled. This is not a safe setting and should only be " + "used for testing.");
trustManagers = new TrustManager[] { TrustAllManager.INSTANCE };
}
TlsKeyManagersProvider provider = this.options.get(SdkHttpConfigurationOption.TLS_KEY_MANAGERS_PROVIDER);
KeyManager[] keyManagers = provider.keyManagers();
SSLContext context;
try {
context = SSLContext.getInstance("TLS");
context.init(keyManagers, trustManagers, null);
return context;
} catch (NoSuchAlgorithmException | KeyManagementException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
Aggregations