use of software.amazon.awssdk.crt.io.TlsCipherPreference in project aws-sdk-java-v2 by aws.
the class AwsCrtClientKmsIntegrationTest method setup.
@Before
public void setup() {
CrtResource.waitForNoResources();
// Create an Http Client for each TLS Cipher Preference supported on the current platform
for (TlsCipherPreference pref : TlsCipherPreference.values()) {
if (!TlsContextOptions.isCipherPreferenceSupported(pref)) {
continue;
}
int numThreads = 1;
eventLoopGroup = new EventLoopGroup(numThreads);
hostResolver = new HostResolver(eventLoopGroup);
SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder().build();
awsCrtHttpClients.add(awsCrtHttpClient);
}
}
use of software.amazon.awssdk.crt.io.TlsCipherPreference in project aws-crt-java by awslabs.
the class TlsContextOptionsTest method testTlsContextOptionsAPI.
@Test
public void testTlsContextOptionsAPI() {
skipIfNetworkUnavailable();
try (TlsContextOptions options = TlsContextOptions.createDefaultClient()) {
for (TlsCipherPreference pref : TlsCipherPreference.values()) {
if (TlsContextOptions.isCipherPreferenceSupported(pref)) {
options.setCipherPreference(pref);
}
}
Assert.assertNotEquals(0, options.getNativeHandle());
}
try (TlsContextOptions options = TlsContextOptions.createDefaultClient()) {
boolean exceptionThrown = false;
try {
options.setCipherPreference(TlsCipherPreference.TLS_CIPHER_KMS_PQ_TLSv1_0_2019_06);
options.minTlsVersion = TlsVersions.TLSv1_2;
// Will never get here
Assert.assertEquals(0, options.getNativeHandle());
} catch (IllegalArgumentException | IllegalStateException e) {
exceptionThrown = true;
}
Assert.assertTrue(exceptionThrown);
}
}
use of software.amazon.awssdk.crt.io.TlsCipherPreference in project aws-crt-java by awslabs.
the class HttpClientConnectionTest method testConnectionWithAllCiphers.
private void testConnectionWithAllCiphers(URI uri, boolean expectConnected, String exceptionMsg) throws Exception {
for (TlsCipherPreference pref : TlsCipherPreference.values()) {
if (!TlsContextOptions.isCipherPreferenceSupported(pref)) {
continue;
}
HttpConnectionTestResponse resp = null;
try (TlsContextOptions tlsOpts = TlsContextOptions.createDefaultClient().withCipherPreference(pref)) {
if (getContext().trustStore != null) {
tlsOpts.withCertificateAuthority(new String(getContext().trustStore));
}
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
HostResolver resolver = new HostResolver(eventLoopGroup);
ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
SocketOptions socketOptions = new SocketOptions();
TlsContext tlsCtx = new TlsContext(tlsOpts)) {
socketOptions.connectTimeoutMs = 10000;
resp = testConnection(uri, bootstrap, socketOptions, tlsCtx);
}
}
String assertMsg = uri.toString() + " " + pref;
// If an unexpected exception occurred, rethrow so we get details in the logs
if (resp.exceptionThrown && (expectConnected || !resp.exception.getMessage().contains(exceptionMsg))) {
System.out.println(assertMsg);
throw resp.exception;
}
Assert.assertEquals(assertMsg + " connection success.", expectConnected, resp.actuallyConnected);
Assert.assertEquals(assertMsg + " exception thrown.", !expectConnected, resp.exceptionThrown);
resp.shutdownComplete.get();
}
}
Aggregations