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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations