Search in sources :

Example 1 with TlsTrustManagersProvider

use of software.amazon.awssdk.http.TlsTrustManagersProvider in project aws-sdk-java-v2 by aws.

the class SslContextProvider method getTrustManager.

private TrustManagerFactory getTrustManager(NettyConfiguration configuration) {
    TlsTrustManagersProvider tlsTrustManagersProvider = configuration.tlsTrustManagersProvider();
    Validate.isTrue(tlsTrustManagersProvider == null || !configuration.trustAllCertificates(), "A TlsTrustManagerProvider can't be provided if TrustAllCertificates is also set");
    if (tlsTrustManagersProvider != null) {
        return StaticTrustManagerFactory.create(tlsTrustManagersProvider.trustManagers());
    }
    if (configuration.trustAllCertificates()) {
        log.warn(null, () -> "SSL Certificate verification is disabled. This is not a safe setting and should only be " + "used for testing.");
        return InsecureTrustManagerFactory.INSTANCE;
    }
    // return null so that the system default trust manager will be used
    return null;
}
Also used : TlsTrustManagersProvider(software.amazon.awssdk.http.TlsTrustManagersProvider)

Example 2 with TlsTrustManagersProvider

use of software.amazon.awssdk.http.TlsTrustManagersProvider in project aws-sdk-java-v2 by aws.

the class SslContextProviderTest method customizedTrustManagerPresent_shouldUseCustomized.

@Test
public void customizedTrustManagerPresent_shouldUseCustomized() {
    TlsTrustManagersProvider mockProvider = Mockito.mock(TlsTrustManagersProvider.class);
    TrustManager mockTrustManager = Mockito.mock(TrustManager.class);
    Mockito.when(mockProvider.trustManagers()).thenReturn(new TrustManager[] { mockTrustManager });
    SslContextProvider sslContextProvider = new SslContextProvider(new NettyConfiguration(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, false).put(TLS_TRUST_MANAGERS_PROVIDER, mockProvider).build()), Protocol.HTTP1_1, SslProvider.JDK);
    sslContextProvider.sslContext();
    Mockito.verify(mockProvider).trustManagers();
}
Also used : TlsTrustManagersProvider(software.amazon.awssdk.http.TlsTrustManagersProvider) TrustManager(javax.net.ssl.TrustManager) Test(org.junit.jupiter.api.Test)

Example 3 with TlsTrustManagersProvider

use of software.amazon.awssdk.http.TlsTrustManagersProvider in project aws-sdk-java-v2 by aws.

the class SslContextProviderTest method TlsTrustManagerAndTrustAllCertificates_shouldThrowException.

@Test
public void TlsTrustManagerAndTrustAllCertificates_shouldThrowException() {
    TlsTrustManagersProvider mockProvider = Mockito.mock(TlsTrustManagersProvider.class);
    assertThatThrownBy(() -> new SslContextProvider(new NettyConfiguration(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).put(TLS_TRUST_MANAGERS_PROVIDER, mockProvider).build()), Protocol.HTTP1_1, SslProvider.JDK)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("A TlsTrustManagerProvider can't" + " be provided if " + "TrustAllCertificates is also " + "set");
}
Also used : TlsTrustManagersProvider(software.amazon.awssdk.http.TlsTrustManagersProvider) Test(org.junit.jupiter.api.Test)

Aggregations

TlsTrustManagersProvider (software.amazon.awssdk.http.TlsTrustManagersProvider)3 Test (org.junit.jupiter.api.Test)2 TrustManager (javax.net.ssl.TrustManager)1