Search in sources :

Example 1 with TlsContext

use of software.amazon.awssdk.crt.io.TlsContext in project aws-crt-java by awslabs.

the class ProxyTest method buildDirectMqttConnection.

private MqttClientConnection buildDirectMqttConnection(ProxyTestType testType, ProxyAuthType authType) {
    try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
        HostResolver resolver = new HostResolver(eventLoopGroup);
        ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
        TlsContext tlsContext = createX509TlsContext(null);
        MqttClient mqttClient = new MqttClient(bootstrap, tlsContext);
        MqttConnectionConfig connectionConfig = new MqttConnectionConfig();
        TlsContext proxyTlsContext = createProxyTlsContext(testType)) {
        HttpProxyOptions proxyOptions = buildProxyOptions(testType, authType, proxyTlsContext);
        String clientId = PROXY_TEST_CLIENTID + (UUID.randomUUID()).toString();
        connectionConfig.setMqttClient(mqttClient);
        connectionConfig.setEndpoint(MQTT_ENDPOINT);
        connectionConfig.setHttpProxyOptions(proxyOptions);
        connectionConfig.setCleanSession(true);
        connectionConfig.setClientId(clientId);
        connectionConfig.setPort(MQTT_DIRECT_PORT);
        connectionConfig.setProtocolOperationTimeoutMs(60000);
        return new MqttClientConnection(connectionConfig);
    }
}
Also used : MqttClient(software.amazon.awssdk.crt.mqtt.MqttClient) HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) MqttClientConnection(software.amazon.awssdk.crt.mqtt.MqttClientConnection) ClientBootstrap(software.amazon.awssdk.crt.io.ClientBootstrap) MqttConnectionConfig(software.amazon.awssdk.crt.mqtt.MqttConnectionConfig) ClientTlsContext(software.amazon.awssdk.crt.io.ClientTlsContext) TlsContext(software.amazon.awssdk.crt.io.TlsContext) HostResolver(software.amazon.awssdk.crt.io.HostResolver)

Example 2 with TlsContext

use of software.amazon.awssdk.crt.io.TlsContext in project aws-crt-java by awslabs.

the class ProxyTest method buildProxiedX509CredentialsProvider.

private CredentialsProvider buildProxiedX509CredentialsProvider(ProxyTestType testType, ProxyAuthType authType) {
    try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
        HostResolver resolver = new HostResolver(eventLoopGroup);
        ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
        TlsContext tlsContext = createX509TlsContext(null);
        TlsContext proxyTlsContext = createProxyTlsContext(testType)) {
        HttpProxyOptions proxyOptions = buildProxyOptions(testType, authType, proxyTlsContext);
        X509CredentialsProvider.X509CredentialsProviderBuilder builder = new X509CredentialsProvider.X509CredentialsProviderBuilder();
        builder.withClientBootstrap(bootstrap).withEndpoint(X509_CREDENTIALS_ENDPOINT).withProxyOptions(proxyOptions).withRoleAlias(X509_CREDENTIALS_ROLE_ALIAS).withThingName(X509_CREDENTIALS_THING_NAME).withTlsContext(tlsContext);
        return builder.build();
    }
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) ClientBootstrap(software.amazon.awssdk.crt.io.ClientBootstrap) ClientTlsContext(software.amazon.awssdk.crt.io.ClientTlsContext) TlsContext(software.amazon.awssdk.crt.io.TlsContext) HostResolver(software.amazon.awssdk.crt.io.HostResolver) X509CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)

Example 3 with TlsContext

use of software.amazon.awssdk.crt.io.TlsContext in project aws-crt-java by awslabs.

the class HttpClientConnectionManagerTest method createConnectionManager.

private HttpClientConnectionManager createConnectionManager(URI uri, int numThreads, int numConnections) {
    try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
        HostResolver resolver = new HostResolver(eventLoopGroup);
        ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
        SocketOptions sockOpts = new SocketOptions();
        TlsContext tlsContext = createHttpClientTlsContext()) {
        HttpClientConnectionManagerOptions options = new HttpClientConnectionManagerOptions();
        options.withClientBootstrap(bootstrap).withSocketOptions(sockOpts).withTlsContext(tlsContext).withUri(uri).withMaxConnections(numConnections);
        return HttpClientConnectionManager.create(options);
    }
}
Also used : EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) ClientBootstrap(software.amazon.awssdk.crt.io.ClientBootstrap) HttpClientConnectionManagerOptions(software.amazon.awssdk.crt.http.HttpClientConnectionManagerOptions) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) TlsContext(software.amazon.awssdk.crt.io.TlsContext) HostResolver(software.amazon.awssdk.crt.io.HostResolver)

Example 4 with TlsContext

use of software.amazon.awssdk.crt.io.TlsContext in project aws-crt-java by awslabs.

the class TlsContextOptionsTest method testMtlsFromBadPath.

// Test should fail to create TlsContext because the file paths are not valid
@Test
public void testMtlsFromBadPath() {
    skipIfNetworkUnavailable();
    String certPath = getPathStringFromSystemProperty(TEST_CERT_PATH_PROPERTY);
    String keyPath = getPathStringFromSystemProperty(TEST_KEY_PATH_PROPERTY);
    certPath = certPath + ".not.valid.path";
    keyPath = keyPath + ".not.valid.path";
    boolean successfullyCreatedTlsContext = false;
    try (TlsContextOptions options = TlsContextOptions.createDefaultClient()) {
        options.initMtlsFromPath(certPath, keyPath);
        try (TlsContext tls = new TlsContext(options)) {
            successfullyCreatedTlsContext = true;
        }
    } catch (Exception ex) {
    // exceptions are expected
    }
    assertFalse(successfullyCreatedTlsContext);
}
Also used : TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) TlsContext(software.amazon.awssdk.crt.io.TlsContext) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Test(org.junit.Test)

Example 5 with TlsContext

use of software.amazon.awssdk.crt.io.TlsContext in project aws-crt-java by awslabs.

the class TlsContextOptionsTest method testMtlsFromPath.

@Test
public void testMtlsFromPath() {
    skipIfNetworkUnavailable();
    String certPath = getPathStringFromSystemProperty(TEST_CERT_PATH_PROPERTY);
    String keyPath = getPathStringFromSystemProperty(TEST_KEY_PATH_PROPERTY);
    try (TlsContextOptions options = TlsContextOptions.createDefaultClient()) {
        options.initMtlsFromPath(certPath, keyPath);
        try (TlsContext tls = new TlsContext(options)) {
            assertNotNull(tls);
        } catch (Exception ex) {
            fail(ex.toString());
        }
    } catch (Exception ex) {
        fail(ex.toString());
    }
}
Also used : TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) TlsContext(software.amazon.awssdk.crt.io.TlsContext) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Test(org.junit.Test)

Aggregations

TlsContext (software.amazon.awssdk.crt.io.TlsContext)11 ClientBootstrap (software.amazon.awssdk.crt.io.ClientBootstrap)7 EventLoopGroup (software.amazon.awssdk.crt.io.EventLoopGroup)6 HostResolver (software.amazon.awssdk.crt.io.HostResolver)6 TlsContextOptions (software.amazon.awssdk.crt.io.TlsContextOptions)6 SocketOptions (software.amazon.awssdk.crt.io.SocketOptions)5 Test (org.junit.Test)4 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)4 HttpClientConnectionManagerOptions (software.amazon.awssdk.crt.http.HttpClientConnectionManagerOptions)3 HttpProxyOptions (software.amazon.awssdk.crt.http.HttpProxyOptions)3 ClientTlsContext (software.amazon.awssdk.crt.io.ClientTlsContext)3 IOException (java.io.IOException)1 URI (java.net.URI)1 InvalidPathException (java.nio.file.InvalidPathException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 X509CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)1 HttpClientConnection (software.amazon.awssdk.crt.http.HttpClientConnection)1 HttpClientConnectionManager (software.amazon.awssdk.crt.http.HttpClientConnectionManager)1 Pkcs11Lib (software.amazon.awssdk.crt.io.Pkcs11Lib)1 TlsCipherPreference (software.amazon.awssdk.crt.io.TlsCipherPreference)1