Search in sources :

Example 6 with PemTrustOptions

use of io.vertx.core.net.PemTrustOptions in project raml-module-builder by folio-org.

the class PostgresClient method createPgConnectOptions.

static PgConnectOptions createPgConnectOptions(JsonObject sqlConfig) {
    PgConnectOptions pgConnectOptions = new PgConnectOptions();
    String host = sqlConfig.getString(HOST);
    if (host != null) {
        pgConnectOptions.setHost(host);
    }
    Integer port = sqlConfig.getInteger(PORT);
    if (port != null) {
        pgConnectOptions.setPort(port);
    }
    String username = sqlConfig.getString(USERNAME);
    if (username != null) {
        pgConnectOptions.setUser(username);
    }
    String password = sqlConfig.getString(PASSWORD);
    if (password != null) {
        pgConnectOptions.setPassword(password);
    }
    String database = sqlConfig.getString(DATABASE);
    if (database != null) {
        pgConnectOptions.setDatabase(database);
    }
    String serverPem = sqlConfig.getString(SERVER_PEM);
    if (serverPem != null) {
        pgConnectOptions.setSslMode(SslMode.VERIFY_FULL);
        pgConnectOptions.setHostnameVerificationAlgorithm("HTTPS");
        pgConnectOptions.setPemTrustOptions(new PemTrustOptions().addCertValue(Buffer.buffer(serverPem)));
        pgConnectOptions.setEnabledSecureTransportProtocols(Collections.singleton("TLSv1.3"));
        if (OpenSSLEngineOptions.isAvailable()) {
            pgConnectOptions.setOpenSslEngineOptions(new OpenSSLEngineOptions());
        } else {
            pgConnectOptions.setJdkSslEngineOptions(new JdkSSLEngineOptions());
            log.error("Cannot run OpenSSL, using slow JDKSSL. Is netty-tcnative-boringssl-static for windows-x86_64, " + "osx-x86_64 or linux-x86_64 installed? https://netty.io/wiki/forked-tomcat-native.html " + "Is libc6-compat installed (if required)? https://github.com/pires/netty-tcnative-alpine");
        }
        log.debug("Enforcing SSL encryption for PostgreSQL connections, " + "requiring TLSv1.3 with server name certificate, " + "using " + (OpenSSLEngineOptions.isAvailable() ? "OpenSSL " + OpenSsl.versionString() : "JDKSSL"));
    }
    return pgConnectOptions;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PgConnectOptions(io.vertx.pgclient.PgConnectOptions) JdkSSLEngineOptions(io.vertx.core.net.JdkSSLEngineOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions)

Example 7 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)

Example 8 with PemTrustOptions

use of io.vertx.core.net.PemTrustOptions in project vert.x by eclipse.

the class KeyStoreTest method testTrustOptions.

@Test
public void testTrustOptions() throws Exception {
    PemTrustOptions options = new PemTrustOptions();
    assertEquals(Collections.emptyList(), options.getCertPaths());
    assertNullPointerException(() -> options.addCertPath(null));
    assertIllegalArgumentException(() -> options.addCertPath(""));
    String randString = TestUtils.randomAlphaString(100);
    options.addCertPath(randString);
    assertEquals(Collections.singletonList(randString), options.getCertPaths());
    assertEquals(Collections.emptyList(), options.getCertValues());
    assertNullPointerException(() -> options.addCertValue(null));
    randString = TestUtils.randomAlphaString(100);
    options.addCertValue(Buffer.buffer(randString));
    assertEquals(Collections.singletonList(Buffer.buffer(randString)), options.getCertValues());
}
Also used : PemTrustOptions(io.vertx.core.net.PemTrustOptions) Test(org.junit.Test)

Example 9 with PemTrustOptions

use of io.vertx.core.net.PemTrustOptions in project vert.x by eclipse.

the class KeyStoreTest method testTrustOptionsJson.

@Test
public void testTrustOptionsJson() throws Exception {
    PemTrustOptions options = new PemTrustOptions(new JsonObject());
    assertEquals(Collections.emptyList(), options.getCertPaths());
    assertEquals(Collections.emptyList(), options.getCertValues());
    String certPath = TestUtils.randomAlphaString(100);
    String certValue = TestUtils.randomAlphaString(100);
    JsonObject json = new JsonObject().put("certPaths", new JsonArray().add(certPath)).put("certValues", new JsonArray().add(certValue.getBytes()));
    options = new PemTrustOptions(json);
    assertEquals(Collections.singletonList(certPath), options.getCertPaths());
    assertEquals(Collections.singletonList(Buffer.buffer(certValue)), options.getCertValues());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) PemTrustOptions(io.vertx.core.net.PemTrustOptions) Test(org.junit.Test)

Example 10 with PemTrustOptions

use of io.vertx.core.net.PemTrustOptions in project vertx-web by vert-x3.

the class StaticHandlerTest method testNoHttp2Push.

@Test
public void testNoHttp2Push() throws Exception {
    stat.setWebRoot("webroot/somedir3");
    router.route().handler(stat);
    HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
    http2Server.requestHandler(router).listen(8443);
    HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2).setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
    HttpClient client = vertx.createHttpClient(options);
    HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(HttpVersion.HTTP_2, resp.version());
        resp.bodyHandler(this::assertNotNull);
        testComplete();
    });
    request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
        fail();
    }));
    request.end();
    await();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Utils(io.vertx.ext.web.impl.Utils) HttpVersion(io.vertx.core.http.HttpVersion) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) WebTestBase(io.vertx.ext.web.WebTestBase) DateFormat(java.text.DateFormat) Set(java.util.Set) Test(org.junit.Test) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Http2PushMapping(io.vertx.ext.web.Http2PushMapping) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Aggregations

PemTrustOptions (io.vertx.core.net.PemTrustOptions)13 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 MqttClientOptions (io.vertx.mqtt.MqttClientOptions)2 File (java.io.File)2