Search in sources :

Example 1 with X509CredentialsProvider

use of software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider in project aws-iot-device-sdk-java-v2 by aws.

the class CommandLineOption method buildWebsocketX509MQTTConnection.

public MqttClientConnection buildWebsocketX509MQTTConnection(MqttClientConnectionEvents callbacks) {
    try {
        AwsIotMqttConnectionBuilder builder = AwsIotMqttConnectionBuilder.newMtlsBuilderFromPath(null, null);
        buildConnectionSetupCAFileDefaults(builder);
        buildConnectionSetupConnectionDefaults(builder, callbacks);
        HttpProxyOptions proxyOptions = null;
        int proxyPort = Integer.parseInt(getCommandOrDefault(m_cmd_proxy_port, "0"));
        if (hasCommand(m_cmd_proxy_host) && proxyPort > 0) {
            proxyOptions = new HttpProxyOptions();
            proxyOptions.setHost(getCommand(m_cmd_proxy_host));
            proxyOptions.setPort(proxyPort);
            builder.withHttpProxyOptions(proxyOptions);
        }
        builder.withWebsockets(true);
        builder.withWebsocketSigningRegion(getCommandRequired(m_cmd_signing_region, ""));
        TlsContextOptions x509TlsOptions = TlsContextOptions.createWithMtlsFromPath(getCommandRequired(m_cmd_x509_cert_file, ""), getCommandRequired(m_cmd_x509_key_file, ""));
        if (hasCommand(m_cmd_x509_ca_file)) {
            x509TlsOptions.withCertificateAuthorityFromPath(null, getCommand(m_cmd_x509_ca_file));
        }
        ClientTlsContext x509TlsContext = new ClientTlsContext(x509TlsOptions);
        X509CredentialsProvider.X509CredentialsProviderBuilder x509builder = new X509CredentialsProvider.X509CredentialsProviderBuilder().withTlsContext(x509TlsContext).withEndpoint(getCommandRequired(m_cmd_x509_endpoint, "")).withRoleAlias(getCommandRequired(m_cmd_x509_role, "")).withThingName(getCommandRequired(m_cmd_x509_thing_name, "")).withProxyOptions(proxyOptions);
        X509CredentialsProvider provider = x509builder.build();
        builder.withWebsocketCredentialsProvider(provider);
        return builder.build();
    } catch (CrtRuntimeException ex) {
        return null;
    }
}
Also used : HttpProxyOptions(software.amazon.awssdk.crt.http.HttpProxyOptions) AwsIotMqttConnectionBuilder(software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder) X509CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)

Aggregations

X509CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.X509CredentialsProvider)1 HttpProxyOptions (software.amazon.awssdk.crt.http.HttpProxyOptions)1 AwsIotMqttConnectionBuilder (software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder)1