Search in sources :

Example 6 with JksOptions

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

Example 7 with JksOptions

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

Example 8 with JksOptions

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;
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JksOptions(io.vertx.core.net.JksOptions) Supplier(java.util.function.Supplier) PfxOptions(io.vertx.core.net.PfxOptions)

Example 9 with JksOptions

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());
        }
    });
}
Also used : JksOptions(io.vertx.core.net.JksOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Example 10 with JksOptions

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);
}
Also used : JksOptions(io.vertx.core.net.JksOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpServer(io.vertx.core.http.HttpServer)

Aggregations

JksOptions (io.vertx.core.net.JksOptions)12 Test (org.junit.Test)6 Buffer (io.vertx.core.buffer.Buffer)3 PfxOptions (io.vertx.core.net.PfxOptions)3 HttpServer (io.vertx.core.http.HttpServer)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 JsonObject (io.vertx.core.json.JsonObject)2 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)2 IpPort (io.servicecomb.foundation.common.net.IpPort)1 Vertx (io.vertx.core.Vertx)1 VertxOptions (io.vertx.core.VertxOptions)1 EventBus (io.vertx.core.eventbus.EventBus)1 EventBusOptions (io.vertx.core.eventbus.EventBusOptions)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 Router (io.vertx.ext.web.Router)1 Supplier (java.util.function.Supplier)1