Search in sources :

Example 1 with PemTrustOptions

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());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) PemTrustOptions(io.vertx.core.net.PemTrustOptions) Test(org.junit.Test)

Example 2 with PemTrustOptions

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);
}
Also used : PemTrustOptions(io.vertx.core.net.PemTrustOptions) Test(org.junit.Test)

Example 3 with PemTrustOptions

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()));
        }
    });
}
Also used : MqttClientOptions(io.vertx.mqtt.MqttClientOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions)

Example 4 with PemTrustOptions

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);
}
Also used : HttpProxy(io.gravitee.definition.model.HttpProxy) ProxyOptions(io.vertx.core.net.ProxyOptions) HttpClientSslOptions(io.gravitee.definition.model.HttpClientSslOptions) URI(java.net.URI) PemTrustOptions(io.vertx.core.net.PemTrustOptions)

Example 5 with PemTrustOptions

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());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JsonObject(io.vertx.core.json.JsonObject) PemTrustOptions(io.vertx.core.net.PemTrustOptions) Test(org.junit.Test)

Aggregations

PemTrustOptions (io.vertx.core.net.PemTrustOptions)11 Test (org.junit.Test)7 HttpClient (io.vertx.core.http.HttpClient)3 HttpClientOptions (io.vertx.core.http.HttpClientOptions)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 HttpMethod (io.vertx.core.http.HttpMethod)3 JsonArray (io.vertx.core.json.JsonArray)3 JsonObject (io.vertx.core.json.JsonObject)3 HttpClientSslOptions (io.gravitee.definition.model.HttpClientSslOptions)2 HttpProxy (io.gravitee.definition.model.HttpProxy)2 HttpServer (io.vertx.core.http.HttpServer)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 HttpVersion (io.vertx.core.http.HttpVersion)2 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)2 Http2PushMapping (io.vertx.ext.web.Http2PushMapping)2 Router (io.vertx.ext.web.Router)2 WebTestBase (io.vertx.ext.web.WebTestBase)2 Utils (io.vertx.ext.web.impl.Utils)2 File (java.io.File)2 DateFormat (java.text.DateFormat)2