use of org.eclipse.hono.config.KeyLoader in project hono by eclipse.
the class ConfigBasedCoapEndpointFactory method addIdentity.
private void addIdentity(final DtlsConnectorConfig.Builder dtlsConfig) {
final KeyLoader keyLoader = KeyLoader.fromFiles(vertx, config.getKeyPath(), config.getCertPath());
final PrivateKey pk = keyLoader.getPrivateKey();
final Certificate[] certChain = keyLoader.getCertificateChain();
if (pk == null) {
LOG.warn("no private private key configured");
} else if (certChain == null) {
LOG.warn("no server certificate configured");
} else {
if (pk.getAlgorithm().equals("EC")) {
// Californium's cipher suites support ECC based keys only
LOG.info("using private key [{}] and certificate [{}] as server identity", config.getKeyPath(), config.getCertPath());
dtlsConfig.setIdentity(pk, certChain);
Optional.ofNullable(certificateVerifier).ifPresent(dtlsConfig::setAdvancedCertificateVerifier);
} else {
LOG.warn("configured key is not ECC based, certificate based cipher suites will be disabled");
}
}
}
use of org.eclipse.hono.config.KeyLoader in project hono by eclipse.
the class CoapTestBase method testUploadFailsForNonMatchingTrustAnchor.
/**
* Verifies that the adapter fails to authenticate a device if the device's client certificate's signature cannot be
* validated using the trust anchor that is registered for the tenant that the device belongs to.
*
* @param ctx The vert.x test context.
* @throws GeneralSecurityException if the tenant's trust anchor cannot be generated
*/
@Test
@Timeout(timeUnit = TimeUnit.SECONDS, value = 20)
public void testUploadFailsForNonMatchingTrustAnchor(final VertxTestContext ctx) throws GeneralSecurityException {
final var keyLoader = KeyLoader.fromFiles(vertx, PATH_DEVICE_KEY, PATH_DEVICE_CERT);
// GIVEN a tenant configured with a trust anchor
final KeyPair keyPair = helper.newEcKeyPair();
final var clientCert = (X509Certificate) keyLoader.getCertificateChain()[0];
final Tenant tenant = Tenants.createTenantForTrustAnchor(clientCert.getIssuerX500Principal().getName(X500Principal.RFC2253), keyPair.getPublic().getEncoded(), keyPair.getPublic().getAlgorithm());
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, clientCert).compose(ok -> {
final CoapClient client = getCoapsClient(keyLoader);
final Promise<OptionSet> result = Promise.promise();
client.advanced(getHandler(result), createCoapsRequest(Code.POST, getPostResource(), 0));
return result.future();
}).onComplete(ctx.failing(t -> {
// THEN the request fails because the DTLS handshake cannot be completed
assertStatus(ctx, HttpURLConnection.HTTP_UNAVAILABLE, t);
ctx.completeNow();
}));
}
Aggregations