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