Search in sources :

Example 1 with TlsKeyManagersProvider

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();
}
Also used : ChannelPool(io.netty.channel.pool.ChannelPool) TlsKeyManagersProvider(software.amazon.awssdk.http.TlsKeyManagersProvider) AttributeMap(software.amazon.awssdk.utils.AttributeMap) Test(org.junit.Test)

Example 2 with TlsKeyManagersProvider

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();
}
Also used : FileStoreTlsKeyManagersProvider(software.amazon.awssdk.http.FileStoreTlsKeyManagersProvider) TlsKeyManagersProvider(software.amazon.awssdk.http.TlsKeyManagersProvider) ExpectedException(org.junit.rules.ExpectedException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) SSLException(javax.net.ssl.SSLException) Test(org.junit.Test)

Example 3 with TlsKeyManagersProvider

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();
}
Also used : TlsKeyManagersProvider(software.amazon.awssdk.http.TlsKeyManagersProvider) Test(org.junit.jupiter.api.Test)

Example 4 with TlsKeyManagersProvider

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);
    }
}
Also used : TlsKeyManagersProvider(software.amazon.awssdk.http.TlsKeyManagersProvider) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManager(javax.net.ssl.KeyManager) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Aggregations

TlsKeyManagersProvider (software.amazon.awssdk.http.TlsKeyManagersProvider)4 Test (org.junit.Test)2 ChannelPool (io.netty.channel.pool.ChannelPool)1 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CompletionException (java.util.concurrent.CompletionException)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContext (javax.net.ssl.SSLContext)1 SSLException (javax.net.ssl.SSLException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 Test (org.junit.jupiter.api.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 FileStoreTlsKeyManagersProvider (software.amazon.awssdk.http.FileStoreTlsKeyManagersProvider)1 AttributeMap (software.amazon.awssdk.utils.AttributeMap)1