use of io.vertx.core.net.SelfSignedCertificate in project pinpoint by naver.
the class Vertx4PluginTestStarter method start.
@Override
public void start(Promise<Void> startPromise) throws Exception {
HttpServerOptions options = new HttpServerOptions();
options.setIdleTimeout(1000);
options.setSsl(true);
SelfSignedCertificate selfSignedCertificate = SelfSignedCertificate.create();
options.setKeyCertOptions(selfSignedCertificate.keyCertOptions());
options.setTrustOptions(selfSignedCertificate.trustOptions());
Router router = Router.router(vertx);
router.get("/").handler(routingContext -> {
routingContext.response().end("Welcome pinpoint vert.x HTTP server test.");
});
router.get("/request").handler(routingContext -> {
request(80, "naver.com", "/");
routingContext.response().end("Request http://naver.com:80/");
});
router.get("/request/local").handler(routingContext -> {
request(18080, "localhost", "/");
routingContext.response().end("Request http://localhost:18080/");
});
router.get("/request/https").handler(routingContext -> {
request(443, "naver.com", "/");
routingContext.response().end("Request http://naver.com:80/");
});
router.get("/noresponse").handler(routingContext -> {
});
router.get("/close").handler(routingContext -> {
routingContext.response().close();
});
router.get("/connection/close").handler(routingContext -> {
routingContext.request().connection().close();
});
router.get("/executeBlocking").handler(routingContext -> {
executeBlocking(routingContext.request(), 1);
});
router.get("/executeBlocking/wait10s").handler(routingContext -> {
executeBlocking(routingContext.request(), 10);
});
router.get("/executeBlocking/request").handler(routingContext -> {
executeBlockingRequest(routingContext.request());
});
router.get("/runOnContext").handler(routingContext -> {
runOnContext(routingContext.request(), 1);
});
router.get("/runOnContext/wait10s").handler(routingContext -> {
runOnContext(routingContext.request(), 10);
});
router.get("/runOnContext/request").handler(routingContext -> {
runOnContextRequest(routingContext.request());
});
vertx.createHttpServer().requestHandler(router).listen(18080, http -> {
if (http.succeeded()) {
startPromise.complete();
System.out.println("HTTP server started on port 18080");
} else {
startPromise.fail(http.cause());
}
});
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509FailsUsingSniWithNonExistingTenantAlias.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate fails
* for a device belonging to a tenant using a non-existing tenant alias.
*
* @param ctx The test context
*/
@Test
public void testConnectX509FailsUsingSniWithNonExistingTenantAlias(final VertxTestContext ctx) {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addTenant(helper.getRandomTenantId(), Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group")).map(cert)).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group").setAlias("test-alias"), deviceId, cert)).compose(ok -> connectToAdapter("wrong-alias." + IntegrationTestSupport.AMQP_HOST, deviceCert, IntegrationTestSupport.TLS_VERSION_1_2)).onComplete(ctx.failing(t -> {
// THEN the connection is not established
ctx.verify(() -> assertThat(t).isInstanceOf(SaslException.class));
ctx.completeNow();
}));
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509SucceedsForRegisteredDevice.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectX509SucceedsForRegisteredDevice(final String tlsVersion, final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert), deviceId, cert)).compose(ok -> connectToAdapter(IntegrationTestSupport.AMQP_HOST, deviceCert, tlsVersion)).onComplete(ctx.succeeding(con -> {
ctx.verify(() -> assertThat(con.isDisconnected()).isFalse());
ctx.completeNow();
}));
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class AmqpConnectionIT method testConnectX509SucceedsUsingSniWithTenantAlias.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds
* for a device belonging to a tenant with a tenant alias.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param ctx The test context
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@ValueSource(strings = { IntegrationTestSupport.TLS_VERSION_1_2, IntegrationTestSupport.TLS_VERSION_1_3 })
public void testConnectX509SucceedsUsingSniWithTenantAlias(final String tlsVersion, final VertxTestContext ctx) {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addTenant(helper.getRandomTenantId(), Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group")).map(cert)).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group").setAlias("test-alias"), deviceId, cert)).compose(ok -> connectToAdapter("test-alias." + IntegrationTestSupport.AMQP_HOST, deviceCert, tlsVersion)).onComplete(ctx.succeeding(con -> {
ctx.verify(() -> assertThat(con.isDisconnected()).isFalse());
ctx.completeNow();
}));
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class AmqpConnectionIT method testConnectSucceedsWithAutoProvisioning.
/**
* Verifies that the adapter opens a connection if auto-provisioning is enabled for the device certificate.
*
* @param ctx The test context.
*/
@Test
public void testConnectSucceedsWithAutoProvisioning(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
final Promise<String> autoProvisionedDeviceId = Promise.promise();
helper.createAutoProvisioningNotificationConsumer(ctx, autoProvisionedDeviceId, tenantId).compose(ok -> helper.getCertificate(deviceCert.certificatePath())).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> connectToAdapter(deviceCert)).compose(ok -> autoProvisionedDeviceId.future()).compose(deviceId -> helper.registry.getRegistrationInfo(tenantId, deviceId)).onComplete(ctx.succeeding(registrationResult -> {
ctx.verify(() -> {
final var info = registrationResult.bodyAsJsonObject();
IntegrationTestSupport.assertDeviceStatusProperties(info.getJsonObject(RegistryManagementConstants.FIELD_STATUS), true);
});
ctx.completeNow();
}));
}
Aggregations