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;
}
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();
}
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");
}
Aggregations