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