Search in sources :

Example 1 with JksOptions

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

the class KeyStoreTest method testCopyJKSOptions.

@Test
public void testCopyJKSOptions() throws Exception {
    JksOptions options = new JksOptions();
    String password = TestUtils.randomAlphaString(100);
    String path = TestUtils.randomAlphaString(100);
    Buffer value = Buffer.buffer(TestUtils.randomAlphaString(100));
    options.setPassword(password);
    options.setPath(path);
    options.setValue(value);
    options = new JksOptions(options);
    assertEquals(password, options.getPassword());
    assertEquals(path, options.getPath());
    assertEquals(value, options.getValue());
    options = new JksOptions(options.toJson());
    assertEquals(password, options.getPassword());
    assertEquals(path, options.getPath());
    assertEquals(value, options.getValue());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JksOptions(io.vertx.core.net.JksOptions) Test(org.junit.Test)

Example 2 with JksOptions

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

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

the class KeyStoreTest method testDefaultJKSOptionsJson.

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

Example 4 with JksOptions

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

the class KeyStoreTest method testJKSOptions.

@Test
public void testJKSOptions() throws Exception {
    JksOptions options = new JksOptions();
    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 : JksOptions(io.vertx.core.net.JksOptions) Test(org.junit.Test)

Example 5 with JksOptions

use of io.vertx.core.net.JksOptions in project java-chassis by ServiceComb.

the class VertxTLSBuilder method buildTCPSSLOptions.

private static TCPSSLOptions buildTCPSSLOptions(SSLOption sslOption, SSLCustom sslCustom, TCPSSLOptions httpClientOptions) {
    httpClientOptions.setSsl(true);
    if (isFileExists(sslCustom.getFullPath(sslOption.getKeyStore()))) {
        if (STORE_PKCS12.equalsIgnoreCase(sslOption.getKeyStoreType())) {
            PfxOptions keyPfxOptions = new PfxOptions();
            keyPfxOptions.setPath(sslCustom.getFullPath(sslOption.getKeyStore()));
            keyPfxOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray())));
            httpClientOptions.setPfxKeyCertOptions(keyPfxOptions);
        } else if (STORE_JKS.equalsIgnoreCase(sslOption.getKeyStoreType())) {
            JksOptions keyJksOptions = new JksOptions();
            keyJksOptions.setPath(sslCustom.getFullPath(sslOption.getKeyStore()));
            keyJksOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray())));
            httpClientOptions.setKeyStoreOptions(keyJksOptions);
        } else {
            throw new IllegalArgumentException("invalid key store type.");
        }
    }
    if (isFileExists(sslCustom.getFullPath(sslOption.getTrustStore()))) {
        if (STORE_PKCS12.equalsIgnoreCase(sslOption.getTrustStoreType())) {
            PfxOptions trustPfxOptions = new PfxOptions();
            trustPfxOptions.setPath(sslCustom.getFullPath(sslOption.getTrustStore()));
            trustPfxOptions.setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray())));
            httpClientOptions.setPfxTrustOptions(trustPfxOptions);
        } else if (STORE_JKS.equalsIgnoreCase(sslOption.getTrustStoreType())) {
            JksOptions trustJksOptions = new JksOptions();
            trustJksOptions.setPath(sslCustom.getFullPath(sslOption.getTrustStore()));
            trustJksOptions.setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray())));
            httpClientOptions.setTrustStoreOptions(trustJksOptions);
        } else {
            throw new IllegalArgumentException("invalid trust store type.");
        }
    }
    for (String protocol : sslOption.getProtocols().split(",")) {
        httpClientOptions.addEnabledSecureTransportProtocol(protocol);
    }
    for (String cipher : SSLManager.getEnalbedCiphers(sslOption.getCiphers())) {
        httpClientOptions.addEnabledCipherSuite(cipher);
    }
    if (isFileExists(sslCustom.getFullPath(sslOption.getCrl()))) {
        httpClientOptions.addCrlPath(sslCustom.getFullPath(sslOption.getCrl()));
    }
    return httpClientOptions;
}
Also used : JksOptions(io.vertx.core.net.JksOptions) PfxOptions(io.vertx.core.net.PfxOptions)

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