Search in sources :

Example 1 with TlsCipherPreference

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);
    }
}
Also used : EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) TlsCipherPreference(software.amazon.awssdk.crt.io.TlsCipherPreference) HostResolver(software.amazon.awssdk.crt.io.HostResolver) Before(org.junit.Before)

Example 2 with TlsCipherPreference

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);
    }
}
Also used : TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) TlsCipherPreference(software.amazon.awssdk.crt.io.TlsCipherPreference) Test(org.junit.Test)

Example 3 with TlsCipherPreference

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();
    }
}
Also used : EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) ClientBootstrap(software.amazon.awssdk.crt.io.ClientBootstrap) TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) TlsContext(software.amazon.awssdk.crt.io.TlsContext) TlsCipherPreference(software.amazon.awssdk.crt.io.TlsCipherPreference) HostResolver(software.amazon.awssdk.crt.io.HostResolver)

Aggregations

TlsCipherPreference (software.amazon.awssdk.crt.io.TlsCipherPreference)3 EventLoopGroup (software.amazon.awssdk.crt.io.EventLoopGroup)2 HostResolver (software.amazon.awssdk.crt.io.HostResolver)2 TlsContextOptions (software.amazon.awssdk.crt.io.TlsContextOptions)2 Before (org.junit.Before)1 Test (org.junit.Test)1 ClientBootstrap (software.amazon.awssdk.crt.io.ClientBootstrap)1 SocketOptions (software.amazon.awssdk.crt.io.SocketOptions)1 TlsContext (software.amazon.awssdk.crt.io.TlsContext)1 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)1