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