use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class AmqpConnectionIT method testConnectFailsIfAutoProvisioningIsDisabled.
/**
* Verifies that the adapter rejects connection attempts from an unknown device for which auto-provisioning is
* disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsIfAutoProvisioningIsDisabled(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
// GIVEN a tenant configured with a trust anchor that does not allow auto-provisioning
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(false);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> connectToAdapter(deviceCert)).onComplete(ctx.failing(t -> {
// THEN the connection is refused
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 testConnectX509SucceedsUsingSni.
/**
* Verifies that an attempt to open a connection using a valid X.509 client certificate succeeds
* for a device belonging to a tenant that uses the same trust anchor as another tenant.
*
* @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 testConnectX509SucceedsUsingSni(final String tlsVersion, final VertxTestContext ctx) {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
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"), deviceId, cert)).compose(ok -> connectToAdapter(tenantId + "." + 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 DeviceAndGatewayAutoProvisionerTest method init.
/**
* Initializes common fixture.
*
* @throws GeneralSecurityException if the self signed certificate cannot be created.
* @throws IOException if the self signed certificate cannot be read.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void init() throws GeneralSecurityException, IOException {
tenantId = UUID.randomUUID().toString();
deviceId = UUID.randomUUID().toString();
commonName = UUID.randomUUID().toString();
final SelfSignedCertificate ssc = SelfSignedCertificate.create(String.format("%s,OU=Hono,O=Eclipse", commonName));
cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new FileInputStream(ssc.certificatePath()));
subjectDn = cert.getSubjectX500Principal().getName(X500Principal.RFC2253);
final TrustedCertificateAuthority trustedCertificateAuthority = new TrustedCertificateAuthority().setCertificate(cert.getEncoded());
tenant = new Tenant().setTrustedCertificateAuthorities(List.of(trustedCertificateAuthority));
deviceManagementService = mock(DeviceManagementService.class);
credentialsManagementService = mock(CredentialsManagementService.class);
sender = mock(EventSender.class);
when(sender.getMessagingType()).thenReturn(MessagingType.amqp);
when(sender.sendEvent(any(TenantObject.class), any(RegistrationAssertion.class), anyString(), any(), any(Map.class), any())).thenReturn(Future.succeededFuture());
deviceAndGatewayAutoProvisioner = new DeviceAndGatewayAutoProvisioner(mock(Vertx.class), deviceManagementService, credentialsManagementService, new MessagingClientProvider<EventSender>().setClient(sender));
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class TrustedCertificateAuthorityTest method setUp.
/**
* Sets up class fixture.
*
* @throws GeneralSecurityException if the self signed certificate cannot be created.
* @throws IOException if the self signed certificate cannot be read.
*/
@BeforeAll
public static void setUp() throws GeneralSecurityException, IOException {
final SelfSignedCertificate selfSignedCert = SelfSignedCertificate.create("eclipse.org");
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
certificate = (X509Certificate) factory.generateCertificate(new FileInputStream(selfSignedCert.certificatePath()));
}
use of io.vertx.core.net.SelfSignedCertificate in project hono by eclipse.
the class TenantTest method setUp.
/**
* Sets up class fixture.
* @throws GeneralSecurityException if the self signed certificate cannot be created.
* @throws IOException if the self signed certificate cannot be read.
*/
@BeforeAll
public static void setUp() throws GeneralSecurityException, IOException {
final SelfSignedCertificate selfSignedCert = SelfSignedCertificate.create("eclipse.org");
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
certificate = (X509Certificate) factory.generateCertificate(new FileInputStream(selfSignedCert.certificatePath()));
}
Aggregations