use of io.vertx.core.net.PemTrustOptions in project vert.x by eclipse.
the class KeyStoreTest method testDefaultTrustOptionsJson.
@Test
public void testDefaultTrustOptionsJson() {
PemTrustOptions def = new PemTrustOptions();
PemTrustOptions json = new PemTrustOptions(new JsonObject());
assertEquals(def.getCertPaths(), json.getCertPaths());
assertEquals(def.getCertValues(), json.getCertValues());
}
use of io.vertx.core.net.PemTrustOptions in project vert.x by eclipse.
the class KeyStoreTest method testCaPathValue.
@Test
public void testCaPathValue() throws Exception {
PemTrustOptions options = Trust.SERVER_PEM.get();
options.getCertPaths().stream().map(vertx.fileSystem()::readFileBlocking).forEach(options::addCertValue);
options.getCertPaths().clear();
testTrustStore(options);
}
use of io.vertx.core.net.PemTrustOptions in project enmasse-workshop by EnMasseProject.
the class MqttClient method connect.
@Override
public void connect(String username, String password, Handler<AsyncResult<Client>> connectHandler) {
MqttClientOptions options = new MqttClientOptions().setUsername(username).setPassword(password);
if (this.serverCert != null && !this.serverCert.isEmpty()) {
options.setSsl(true).setHostnameVerificationAlgorithm("").setPemTrustOptions(new PemTrustOptions().addCertPath(this.serverCert));
}
this.client = io.vertx.mqtt.MqttClient.create(vertx, options);
this.client.connect(this.port, this.hostname, done -> {
if (done.succeeded()) {
log.info("Connected to {}:{}", this.hostname, this.port);
this.client.publishHandler(m -> {
MessageDelivery messageDelivery = new MessageDelivery(m.topicName(), m.payload().getBytes());
this.receivedHandler.handle(messageDelivery);
});
this.client.subscribeCompletionHandler(suback -> {
log.info("Subscription [{}], granted QoS levels {}", suback.messageId(), suback.grantedQoSLevels());
});
connectHandler.handle(Future.succeededFuture(this));
} else {
log.error("Error connecting to the service", done.cause());
connectHandler.handle(Future.failedFuture(done.cause()));
}
});
}
use of io.vertx.core.net.PemTrustOptions in project gravitee-gateway by gravitee-io.
the class VertxHttpClient method doStart.
@Override
protected void doStart() throws Exception {
// TODO: Prepare HttpClientOptions according to the endpoint to improve performance when creating a new
// instance of the Vertx client
httpClientOptions = new HttpClientOptions();
httpClientOptions.setPipelining(endpoint.getHttpClientOptions().isPipelining());
httpClientOptions.setKeepAlive(endpoint.getHttpClientOptions().isKeepAlive());
httpClientOptions.setIdleTimeout((int) (endpoint.getHttpClientOptions().getIdleTimeout() / 1000));
httpClientOptions.setConnectTimeout((int) endpoint.getHttpClientOptions().getConnectTimeout());
httpClientOptions.setUsePooledBuffers(true);
httpClientOptions.setMaxPoolSize(endpoint.getHttpClientOptions().getMaxConcurrentConnections());
httpClientOptions.setTryUseCompression(endpoint.getHttpClientOptions().isUseCompression());
// Configure proxy
HttpProxy proxy = endpoint.getHttpProxy();
if (proxy != null && proxy.isEnabled()) {
ProxyOptions proxyOptions = new ProxyOptions();
proxyOptions.setHost(proxy.getHost());
proxyOptions.setPort(proxy.getPort());
proxyOptions.setUsername(proxy.getUsername());
proxyOptions.setPassword(proxy.getPassword());
proxyOptions.setType(ProxyType.valueOf(proxy.getType().name()));
httpClientOptions.setProxyOptions(proxyOptions);
}
URI target = URI.create(endpoint.getTarget());
// Configure SSL
HttpClientSslOptions sslOptions = endpoint.getHttpClientSslOptions();
if (sslOptions != null && sslOptions.isEnabled()) {
httpClientOptions.setSsl(sslOptions.isEnabled()).setVerifyHost(sslOptions.isHostnameVerifier()).setTrustAll(sslOptions.isTrustAll());
if (sslOptions.getPem() != null && !sslOptions.getPem().isEmpty()) {
httpClientOptions.setPemTrustOptions(new PemTrustOptions().addCertValue(io.vertx.core.buffer.Buffer.buffer(sslOptions.getPem())));
}
} else if (HTTPS_SCHEME.equalsIgnoreCase(target.getScheme())) {
// SSL is not configured but the endpoint scheme is HTTPS so let's enable the SSL on Vert.x HTTP client
// automatically
httpClientOptions.setSsl(true).setTrustAll(true);
}
printHttpClientConfiguration(httpClientOptions);
}
use of io.vertx.core.net.PemTrustOptions in project vert.x by eclipse.
the class KeyStoreTest method testCopyTrustOptions.
@Test
public void testCopyTrustOptions() throws Exception {
PemTrustOptions options = new PemTrustOptions(new JsonObject());
String certPath = TestUtils.randomAlphaString(100);
Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100));
options.addCertPath(certPath);
options.addCertValue(certValue);
options = new PemTrustOptions(options);
assertEquals(Collections.singletonList(certPath), options.getCertPaths());
assertEquals(Collections.singletonList(certValue), options.getCertValues());
options = new PemTrustOptions(options.toJson());
assertEquals(Collections.singletonList(certPath), options.getCertPaths());
assertEquals(Collections.singletonList(certValue), options.getCertValues());
}
Aggregations