use of org.eclipse.californium.elements.auth.AdditionalInfo in project hono by eclipse.
the class DeviceInfoSupplier method getInfo.
/**
* {@inheritDoc}
*/
@Override
public AdditionalInfo getInfo(final Principal clientIdentity, final Object customArgument) {
if (customArgument instanceof AdditionalInfo) {
final AdditionalInfo info = (AdditionalInfo) customArgument;
final String authId = info.get(EXT_INFO_KEY_HONO_AUTH_ID, String.class);
final Device device = info.get(EXT_INFO_KEY_HONO_DEVICE, Device.class);
LOG.debug("get additional info auth-id: {}, device: {}@{}", authId, device.getDeviceId(), device.getTenantId());
return info;
}
LOG.debug("get no additional info");
return AdditionalInfo.empty();
}
use of org.eclipse.californium.elements.auth.AdditionalInfo in project hono by eclipse.
the class DeviceRegistryBasedPskStore method loadCredentialsForDevice.
/**
* Load credentials for an identity used by a device in a PSK based DTLS handshake.
*
* @param cid the connection id to report the result.
* @param identity the psk identity of the device.
*/
private void loadCredentialsForDevice(final ConnectionId cid, final PskPublicInformation identity) {
final String publicInfo = identity.getPublicInfoAsString();
LOG.debug("getting PSK secret for identity [{}]", publicInfo);
final Span span = tracer.buildSpan("look up pre-shared key").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.COMPONENT.getKey(), adapter.getTypeName()).start();
final PreSharedKeyDeviceIdentity handshakeIdentity = getHandshakeIdentity(publicInfo, span);
if (handshakeIdentity == null) {
TracingHelper.logError(span, "could not determine auth-id from PSK identity");
span.finish();
return;
}
TracingHelper.TAG_TENANT_ID.set(span, handshakeIdentity.getTenantId());
TracingHelper.TAG_AUTH_ID.set(span, handshakeIdentity.getAuthId());
applyTraceSamplingPriority(handshakeIdentity, span).compose(v -> adapter.getCredentialsClient().get(handshakeIdentity.getTenantId(), handshakeIdentity.getType(), handshakeIdentity.getAuthId(), new JsonObject(), span.context())).map(credentials -> {
final String deviceId = credentials.getDeviceId();
TracingHelper.TAG_DEVICE_ID.set(span, deviceId);
final SecretKey key = getCandidateKey(credentials);
if (key == null) {
TracingHelper.logError(span, "PSK credentials for device do not contain proper key");
return new PskSecretResult(cid, identity, null, null);
} else {
span.log("successfully retrieved PSK for device");
// set AdditionalInfo as customArgument here
final AdditionalInfo info = DeviceInfoSupplier.createDeviceInfo(new Device(handshakeIdentity.getTenantId(), credentials.getDeviceId()), handshakeIdentity.getAuthId());
return new PskSecretResult(cid, identity, key, info);
}
}).otherwise(t -> {
TracingHelper.logError(span, "could not retrieve PSK credentials for device", t);
LOG.debug("error retrieving credentials for PSK identity [{}]", publicInfo, t);
return new PskSecretResult(cid, identity, null, null);
}).onSuccess(result -> {
span.finish();
californiumResultHandler.apply(result);
});
}
use of org.eclipse.californium.elements.auth.AdditionalInfo in project hono by eclipse.
the class DeviceRegistryBasedCertificateVerifier method validateCertificateAndLoadDevice.
/**
* Validates a device's client certificate and completes the DTLS handshake result handler.
*
* @param cid the connection id to report the result.
* @param certPath certificate path.
* @param session session.
* @see #setResultHandler(HandshakeResultHandler)
*/
private void validateCertificateAndLoadDevice(final ConnectionId cid, final CertPath certPath, final DTLSSession session) {
LOG.debug("validating client's X.509 certificate");
final Span span = tracer.buildSpan("validate client certificate").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.COMPONENT.getKey(), adapter.getTypeName()).start();
validateCertificateAndLoadDevice(session, certPath, span).map(info -> {
// set AdditionalInfo as customArgument here
return new CertificateVerificationResult(cid, certPath, info);
}).otherwise(t -> {
TracingHelper.logError(span, "could not validate X509 for device", t);
LOG.debug("error validating X509", t);
final AlertMessage alert = new AlertMessage(AlertLevel.FATAL, AlertDescription.BAD_CERTIFICATE, session.getPeer());
return new CertificateVerificationResult(cid, new HandshakeException("error validating X509", alert), null);
}).onSuccess(result -> {
span.finish();
californiumResultHandler.apply(result);
});
}
Aggregations