Search in sources :

Example 1 with SelfSignedCertificate

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());
        }
    });
}
Also used : SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router)

Example 2 with SelfSignedCertificate

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) KeyPair(java.security.KeyPair) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SaslException(javax.security.sasl.SaslException) Supplier(java.util.function.Supplier) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) GeneralSecurityException(java.security.GeneralSecurityException) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) ValueSource(org.junit.jupiter.params.provider.ValueSource) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Adapter(org.eclipse.hono.util.Adapter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AuthenticationException(javax.security.sasl.AuthenticationException) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SelfSignedCertificate

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) KeyPair(java.security.KeyPair) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SaslException(javax.security.sasl.SaslException) Supplier(java.util.function.Supplier) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) GeneralSecurityException(java.security.GeneralSecurityException) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) ValueSource(org.junit.jupiter.params.provider.ValueSource) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Adapter(org.eclipse.hono.util.Adapter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AuthenticationException(javax.security.sasl.AuthenticationException) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SelfSignedCertificate

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) KeyPair(java.security.KeyPair) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SaslException(javax.security.sasl.SaslException) Supplier(java.util.function.Supplier) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) GeneralSecurityException(java.security.GeneralSecurityException) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) ValueSource(org.junit.jupiter.params.provider.ValueSource) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Adapter(org.eclipse.hono.util.Adapter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AuthenticationException(javax.security.sasl.AuthenticationException) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SelfSignedCertificate

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) KeyPair(java.security.KeyPair) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SaslException(javax.security.sasl.SaslException) Supplier(java.util.function.Supplier) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) GeneralSecurityException(java.security.GeneralSecurityException) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) ValueSource(org.junit.jupiter.params.provider.ValueSource) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Adapter(org.eclipse.hono.util.Adapter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AuthenticationException(javax.security.sasl.AuthenticationException) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SelfSignedCertificate (io.vertx.core.net.SelfSignedCertificate)17 VertxTestContext (io.vertx.junit5.VertxTestContext)10 Tenant (org.eclipse.hono.service.management.tenant.Tenant)10 Test (org.junit.jupiter.api.Test)10 Truth.assertThat (com.google.common.truth.Truth.assertThat)9 Future (io.vertx.core.Future)9 Promise (io.vertx.core.Promise)9 HttpURLConnection (java.net.HttpURLConnection)9 TimeUnit (java.util.concurrent.TimeUnit)9 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)9 Tenants (org.eclipse.hono.tests.Tenants)9 RegistryManagementConstants (org.eclipse.hono.util.RegistryManagementConstants)9 JsonObject (io.vertx.core.json.JsonObject)8 Timeout (io.vertx.junit5.Timeout)8 VertxExtension (io.vertx.junit5.VertxExtension)8 UUID (java.util.UUID)8 Constants (org.eclipse.hono.util.Constants)8 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 GeneralSecurityException (java.security.GeneralSecurityException)7