Search in sources :

Example 1 with PemKeyCertOptions

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

the class KeyStoreTest method testCopyKeyCertOptions.

@Test
public void testCopyKeyCertOptions() throws Exception {
    PemKeyCertOptions options = new PemKeyCertOptions(new JsonObject());
    String keyPath = TestUtils.randomAlphaString(100);
    Buffer keyValue = Buffer.buffer(TestUtils.randomAlphaString(100));
    String certPath = TestUtils.randomAlphaString(100);
    Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100));
    options.setKeyPath(keyPath);
    options.setKeyValue(keyValue);
    options.setCertPath(certPath);
    options.setCertValue(certValue);
    options = new PemKeyCertOptions(options);
    assertEquals(keyPath, options.getKeyPath());
    assertEquals(keyValue, options.getKeyValue());
    assertEquals(certPath, options.getCertPath());
    assertEquals(certValue, options.getCertValue());
    options = new PemKeyCertOptions(options.toJson());
    assertEquals(keyPath, options.getKeyPath());
    assertEquals(keyValue, options.getKeyValue());
    assertEquals(certPath, options.getCertPath());
    assertEquals(certValue, options.getCertValue());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 2 with PemKeyCertOptions

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

the class KeyStoreTest method testKeyOptionsEquality.

@Test
public void testKeyOptionsEquality() {
    JksOptions jksOptions = Cert.SERVER_JKS.get();
    JksOptions jksOptionsCopy = new JksOptions(jksOptions);
    PfxOptions pfxOptions = Cert.SERVER_PKCS12.get();
    PfxOptions pfxOptionsCopy = new PfxOptions(pfxOptions);
    PemKeyCertOptions pemKeyCertOptions = Cert.SERVER_PEM.get();
    PemKeyCertOptions pemKeyCertOptionsCopy = new PemKeyCertOptions(pemKeyCertOptions);
    assertEquals(jksOptions, jksOptionsCopy);
    assertEquals(jksOptions.hashCode(), jksOptionsCopy.hashCode());
    assertEquals(pfxOptions, pfxOptionsCopy);
    assertEquals(pfxOptions.hashCode(), pfxOptionsCopy.hashCode());
    assertEquals(pemKeyCertOptions, pemKeyCertOptionsCopy);
    assertEquals(pemKeyCertOptions.hashCode(), pemKeyCertOptionsCopy.hashCode());
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JksOptions(io.vertx.core.net.JksOptions) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 3 with PemKeyCertOptions

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

the class KeyStoreTest method testKeyCertOptionsJson.

@Test
public void testKeyCertOptionsJson() throws Exception {
    PemKeyCertOptions options = new PemKeyCertOptions(new JsonObject());
    assertEquals(null, options.getKeyPath());
    assertEquals(null, options.getKeyValue());
    assertEquals(null, options.getCertPath());
    assertEquals(null, options.getCertValue());
    String keyPath = TestUtils.randomAlphaString(100);
    String keyValue = TestUtils.randomAlphaString(100);
    String certPath = TestUtils.randomAlphaString(100);
    String certValue = TestUtils.randomAlphaString(100);
    options = new PemKeyCertOptions(new JsonObject().put("keyPath", keyPath).put("keyValue", keyValue.getBytes()).put("certPath", certPath).put("certValue", certValue.getBytes()));
    assertEquals(keyPath, options.getKeyPath());
    assertEquals(Buffer.buffer(keyValue), options.getKeyValue());
    assertEquals(certPath, options.getCertPath());
    assertEquals(Buffer.buffer(certValue), options.getCertValue());
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 4 with PemKeyCertOptions

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

the class KeyStoreTest method testDefaultKeyCertOptionsJson.

@Test
public void testDefaultKeyCertOptionsJson() throws Exception {
    PemKeyCertOptions def = new PemKeyCertOptions();
    PemKeyCertOptions json = new PemKeyCertOptions(new JsonObject());
    assertEquals(def.getKeyPath(), json.getKeyPath());
    assertEquals(def.getCertPath(), json.getCertPath());
    assertEquals(def.getKeyValue(), json.getKeyValue());
    assertEquals(def.getCertValue(), json.getCertValue());
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 5 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions 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)

Aggregations

PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)22 Test (org.junit.Test)10 HttpServerOptions (io.vertx.core.http.HttpServerOptions)9 HttpServer (io.vertx.core.http.HttpServer)7 AbstractVerticle (io.vertx.core.AbstractVerticle)4 Buffer (io.vertx.core.buffer.Buffer)4 PfxOptions (io.vertx.core.net.PfxOptions)4 Router (io.vertx.ext.web.Router)4 HttpServerResponse (io.vertx.core.http.HttpServerResponse)3 JsonObject (io.vertx.core.json.JsonObject)3 JksOptions (io.vertx.core.net.JksOptions)3 HttpClient (io.vertx.core.http.HttpClient)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpMethod (io.vertx.core.http.HttpMethod)2 HttpVersion (io.vertx.core.http.HttpVersion)2 JsonArray (io.vertx.core.json.JsonArray)2 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)2 PemTrustOptions (io.vertx.core.net.PemTrustOptions)2 KeyStoreHelper (io.vertx.core.net.impl.KeyStoreHelper)2