Search in sources :

Example 6 with PfxOptions

use of io.vertx.core.net.PfxOptions in project vertx-proton by vert-x3.

the class ProtonClientSslTest method testConnectWithSslToServerWhileUsingTrustAll.

@Test(timeout = 20000)
public void testConnectWithSslToServerWhileUsingTrustAll(TestContext context) throws Exception {
    Async async = context.async();
    // Create a server that accept a connection and expects a client connection+session+receiver
    ProtonServerOptions serverOptions = new ProtonServerOptions();
    serverOptions.setSsl(true);
    PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
    serverOptions.setPfxKeyCertOptions(serverPfxOptions);
    protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
    // Try to connect the client and expect it to succeed due to trusting all certs
    ProtonClientOptions clientOptions = new ProtonClientOptions();
    clientOptions.setSsl(true);
    clientOptions.setTrustAll(true);
    ProtonClient client = ProtonClient.create(vertx);
    client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
        // Expect connect to succeed
        context.assertTrue(res.succeeded());
        async.complete();
    });
    async.awaitSuccess();
}
Also used : Async(io.vertx.ext.unit.Async) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 7 with PfxOptions

use of io.vertx.core.net.PfxOptions in project vertx-proton by vert-x3.

the class ProtonClientSslTest method testConnectWithSslSucceeds.

@Test(timeout = 20000)
public void testConnectWithSslSucceeds(TestContext context) throws Exception {
    Async async = context.async();
    // Create a server that accept a connection and expects a client connection+session+receiver
    ProtonServerOptions serverOptions = new ProtonServerOptions();
    serverOptions.setSsl(true);
    PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
    serverOptions.setPfxKeyCertOptions(serverPfxOptions);
    protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
    // Connect the client and open a receiver to verify the connection works
    ProtonClientOptions clientOptions = new ProtonClientOptions();
    clientOptions.setSsl(true);
    PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD);
    clientOptions.setPfxTrustOptions(clientPfxOptions);
    ProtonClient client = ProtonClient.create(vertx);
    client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
        // Expect connect to succeed
        context.assertTrue(res.succeeded());
        ProtonConnection connection = res.result();
        connection.open();
        ProtonReceiver receiver = connection.createReceiver("some-address");
        receiver.openHandler(recvResult -> {
            context.assertTrue(recvResult.succeeded());
            LOG.trace("Client reciever open");
            async.complete();
        }).open();
    });
    async.awaitSuccess();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) LoggerFactory(io.vertx.core.logging.LoggerFactory) PfxOptions(io.vertx.core.net.PfxOptions) ExecutionException(java.util.concurrent.ExecutionException) After(org.junit.After) ClientAuth(io.vertx.core.http.ClientAuth) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) Before(org.junit.Before) Async(io.vertx.ext.unit.Async) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 8 with PfxOptions

use of io.vertx.core.net.PfxOptions in project hono by eclipse.

the class AbstractConfig method getKeyCertOptions.

/**
 * Gets the key & certificate options derived from the key store properties.
 *
 * @return The options or {@code null} if key store path or key path and cert path are not set or not supported.
 */
public KeyCertOptions getKeyCertOptions() {
    if (keyPath != null && certPath != null) {
        final FileFormat format = FileFormat.orDetect(keyFormat, keyPath);
        final FileFormat certFormat = FileFormat.orDetect(keyFormat, certPath);
        if (format == null) {
            LOG.warn("Unable to detect key file format for: {}", keyPath);
            return null;
        }
        if (certFormat == null) {
            LOG.warn("Unable to detect cert file format for: {}", certPath);
            return null;
        }
        if (certFormat != format) {
            LOG.warn("Key file is {}, but cert file is {}, it must be {} as well", format, certFormat, format);
            return null;
        }
        switch(format) {
            case PEM:
                LOG.debug("using key [{}] and certificate [{}] for identity", keyPath, certPath);
                return new PemKeyCertOptions().setKeyPath(keyPath).setCertPath(certPath);
            default:
                LOG.warn("unsupported key & cert format: {}", format);
                return null;
        }
    } else if (keyStorePath != null) {
        final FileFormat format = FileFormat.orDetect(keyFormat, keyStorePath);
        switch(format) {
            case PKCS12:
                LOG.debug("using key & certificate from PKCS12 key store [{}] for identity", keyStorePath);
                return new PfxOptions().setPath(keyStorePath).setPassword(getKeyStorePassword());
            case JKS:
                LOG.debug("using key & certificate from JKS key store [{}] for server identity", keyStorePath);
                return new JksOptions().setPath(keyStorePath).setPassword(getKeyStorePassword());
            default:
                LOG.warn("unsupported key store format: {}", format);
                return null;
        }
    } else {
        // no configuration
        LOG.debug("neither key/cert nor keystore is configured");
        return null;
    }
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JksOptions(io.vertx.core.net.JksOptions) PfxOptions(io.vertx.core.net.PfxOptions)

Example 9 with PfxOptions

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

the class KeyStoreTest method testPKCS12Options.

@Test
public void testPKCS12Options() throws Exception {
    PfxOptions options = new PfxOptions();
    assertNull(options.getPath());
    String randString = TestUtils.randomAlphaString(100);
    assertEquals(options, options.setPath(randString));
    assertEquals(randString, options.getPath());
    assertNull(options.getPassword());
    randString = TestUtils.randomAlphaString(100);
    assertEquals(options, options.setPassword(randString));
    assertEquals(randString, options.getPassword());
}
Also used : PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 10 with PfxOptions

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

the class KeyStoreTest method testDefaultPKCS12OptionsJson.

@Test
public void testDefaultPKCS12OptionsJson() {
    PfxOptions def = new PfxOptions();
    PfxOptions json = new PfxOptions(new JsonObject());
    assertEquals(def.getPassword(), json.getPassword());
    assertEquals(def.getPath(), json.getPath());
    assertEquals(def.getValue(), json.getValue());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Aggregations

PfxOptions (io.vertx.core.net.PfxOptions)15 Test (org.junit.Test)11 Async (io.vertx.ext.unit.Async)6 JksOptions (io.vertx.core.net.JksOptions)4 Buffer (io.vertx.core.buffer.Buffer)3 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)3 AsyncResult (io.vertx.core.AsyncResult)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 ClientAuth (io.vertx.core.http.ClientAuth)2 JsonObject (io.vertx.core.json.JsonObject)2 Logger (io.vertx.core.logging.Logger)2 LoggerFactory (io.vertx.core.logging.LoggerFactory)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 ExecutionException (java.util.concurrent.ExecutionException)2 After (org.junit.After)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 Supplier (java.util.function.Supplier)1