use of org.eclipse.californium.scandium.dtls.PskSecretResult 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);
});
}
Aggregations