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