use of io.vertx.core.net.JksOptions in project vert.x by eclipse.
the class KeyStoreTest method testJKSOptionsJson.
@Test
public void testJKSOptionsJson() throws Exception {
JksOptions options = new JksOptions(new JsonObject());
assertEquals(null, options.getPassword());
assertEquals(null, options.getPath());
assertEquals(null, options.getValue());
String password = TestUtils.randomAlphaString(100);
String path = TestUtils.randomAlphaString(100);
String value = TestUtils.randomAlphaString(100);
options = new JksOptions(new JsonObject().put("password", password).put("path", path).put("value", value.getBytes()));
assertEquals(password, options.getPassword());
assertEquals(path, options.getPath());
assertEquals(Buffer.buffer(value), options.getValue());
}
use of io.vertx.core.net.JksOptions in project vert.x by eclipse.
the class KeyStoreTest method testJKSValue.
@Test
public void testJKSValue() throws Exception {
JksOptions options = Cert.SERVER_JKS.get();
Buffer store = vertx.fileSystem().readFileBlocking(options.getPath());
options.setPath(null).setValue(store);
testKeyStore(options);
}
use of io.vertx.core.net.JksOptions in project vert.x by eclipse.
the class KeyStoreHelper method create.
public static KeyStoreHelper create(VertxInternal vertx, KeyCertOptions options) {
if (options instanceof JksOptions) {
JksOptions jks = (JksOptions) options;
Supplier<Buffer> value;
if (jks.getPath() != null) {
value = () -> vertx.fileSystem().readFileBlocking(vertx.resolveFile(jks.getPath()).getAbsolutePath());
} else if (jks.getValue() != null) {
value = jks::getValue;
} else {
return null;
}
return new JKSOrPKCS12("JKS", jks.getPassword(), value);
} else if (options instanceof PfxOptions) {
PfxOptions pkcs12 = (PfxOptions) options;
Supplier<Buffer> value;
if (pkcs12.getPath() != null) {
value = () -> vertx.fileSystem().readFileBlocking(vertx.resolveFile(pkcs12.getPath()).getAbsolutePath());
} else if (pkcs12.getValue() != null) {
value = pkcs12::getValue;
} else {
return null;
}
return new JKSOrPKCS12("PKCS12", pkcs12.getPassword(), value);
} else if (options instanceof PemKeyCertOptions) {
PemKeyCertOptions keyCert = (PemKeyCertOptions) options;
Supplier<Buffer> key = () -> {
if (keyCert.getKeyPath() != null) {
return vertx.fileSystem().readFileBlocking(vertx.resolveFile(keyCert.getKeyPath()).getAbsolutePath());
} else if (keyCert.getKeyValue() != null) {
return keyCert.getKeyValue();
} else {
throw new RuntimeException("Missing private key");
}
};
Supplier<Buffer> cert = () -> {
if (keyCert.getCertPath() != null) {
return vertx.fileSystem().readFileBlocking(vertx.resolveFile(keyCert.getCertPath()).getAbsolutePath());
} else if (keyCert.getCertValue() != null) {
return keyCert.getCertValue();
} else {
throw new RuntimeException("Missing X.509 certificate");
}
};
return new KeyCert(DUMMY_PASSWORD, key, cert);
} else {
return null;
}
}
use of io.vertx.core.net.JksOptions in project vert.x by eclipse.
the class EventBusExamples method example13.
public void example13() {
VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setSsl(true).setKeyStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setTrustStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setClientAuth(ClientAuth.REQUIRED));
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
EventBus eventBus = vertx.eventBus();
System.out.println("We now have a clustered event bus: " + eventBus);
} else {
System.out.println("Failed: " + res.cause());
}
});
}
use of io.vertx.core.net.JksOptions in project vert.x by eclipse.
the class HTTP2Examples method example0.
public void example0(Vertx vertx) {
HttpServerOptions options = new HttpServerOptions().setUseAlpn(true).setSsl(true).setKeyStoreOptions(new JksOptions().setPath("/path/to/my/keystore"));
HttpServer server = vertx.createHttpServer(options);
}
Aggregations