use of io.jans.entry.DeviceRegistration in project jans by JanssenProject.
the class AssertionService method prepareAllowedCredentials.
private Pair<ArrayNode, String> prepareAllowedCredentials(String documentDomain, String username) {
// TODO: Add property to enable/disable U2F -> Fido2 migration
List<DeviceRegistration> existingFidoRegistrations = deviceRegistrationService.findAllRegisteredByUsername(username, documentDomain);
if (existingFidoRegistrations.size() > 0) {
deviceRegistrationService.migrateToFido2(existingFidoRegistrations, documentDomain, username);
}
List<Fido2RegistrationEntry> existingFido2Registrations = registrationPersistenceService.findAllRegisteredByUsername(username);
List<Fido2RegistrationEntry> allowedFido2Registrations = existingFido2Registrations.parallelStream().filter(f -> StringHelper.equals(documentDomain, f.getRegistrationData().getDomain())).filter(f -> StringHelper.isNotEmpty(f.getRegistrationData().getPublicKeyId())).collect(Collectors.toList());
allowedFido2Registrations.forEach((value) -> {
log.debug("attestation request:" + value.getRegistrationData().getAttenstationRequest());
});
List<JsonNode> allowedFido2Keys = allowedFido2Registrations.parallelStream().map(f -> dataMapperService.convertValue(new PublicKeyCredentialDescriptor(f.getRegistrationData().getType(), (f.getRegistrationData().getAttestationType().equalsIgnoreCase(AttestationFormat.apple.getFmt()) || f.getRegistrationData().getAttenstationRequest().contains(AuthenticatorAttachment.PLATFORM.getAttachment())) ? new String[] { "internal" } : new String[] { "usb", "ble", "nfc" }, f.getRegistrationData().getPublicKeyId()), JsonNode.class)).collect(Collectors.toList());
Optional<Fido2RegistrationEntry> fidoRegistration = allowedFido2Registrations.parallelStream().filter(f -> StringUtils.isNotEmpty(f.getRegistrationData().getApplicationId())).findAny();
String applicationId = null;
if (fidoRegistration.isPresent()) {
applicationId = fidoRegistration.get().getRegistrationData().getApplicationId();
}
ArrayNode allowedCredentials = dataMapperService.createArrayNode();
allowedCredentials.addAll(allowedFido2Keys);
return Pair.of(allowedCredentials, applicationId);
}
use of io.jans.entry.DeviceRegistration in project jans by JanssenProject.
the class DeviceRegistrationService method findAllRegisteredByUsername.
public List<DeviceRegistration> findAllRegisteredByUsername(String username, String domain, String... returnAttributes) {
String userInum = userService.getUserInum(username);
if (userInum == null) {
return Collections.emptyList();
}
String baseDn = getBaseDnForU2fUserDevices(userInum);
if (persistenceEntryManager.hasBranchesSupport(baseDn)) {
if (!containsBranch(baseDn)) {
return Collections.emptyList();
}
}
Filter resultFilter = Filter.createEqualityFilter("jansStatus", DeviceRegistrationStatus.ACTIVE.getValue());
List<DeviceRegistration> fidoRegistrations = persistenceEntryManager.findEntries(baseDn, DeviceRegistration.class, resultFilter, returnAttributes);
fidoRegistrations = fidoRegistrations.parallelStream().filter(f -> StringHelper.equals(domain, networkService.getHost(f.getApplication()))).filter(f -> (f.getDeviceData() == null)).collect(Collectors.toList());
return fidoRegistrations;
}
use of io.jans.entry.DeviceRegistration in project jans by JanssenProject.
the class DeviceRegistrationService method migrateToFido2.
public void migrateToFido2(List<DeviceRegistration> fidoRegistrations, String documentDomain, String username) {
for (DeviceRegistration fidoRegistration : fidoRegistrations) {
Fido2RegistrationData fido2RegistrationData;
try {
fido2RegistrationData = convertToFido2RegistrationData(documentDomain, username, fidoRegistration);
} catch (IOException ex) {
log.error("Faield to migrate Fido to Fido2 device: {}", fidoRegistration.getId());
continue;
}
// Save converted Fido2 entry
Date enrollmentDate = fidoRegistration.getCreationDate();
Fido2RegistrationEntry fido2RegistrationEntry = registrationPersistenceService.buildFido2RegistrationEntry(fido2RegistrationData);
// Restore dates modified by buildFido2RegistrationEntry
fido2RegistrationEntry.getRegistrationData().setCreatedDate(enrollmentDate);
fido2RegistrationEntry.setCreationDate(enrollmentDate);
fido2RegistrationEntry.setDisplayName(fidoRegistration.getDisplayName());
fido2RegistrationEntry.setPublicKeyId(fido2RegistrationData.getPublicKeyId());
persistenceEntryManager.persist(fido2RegistrationEntry);
// Testing code
// JsonNode uncompressedECPointNode;
// try {
// uncompressedECPointNode = dataMapperService.cborReadTree(base64Service.urlDecode(fido2RegistrationData.getUncompressedECPoint()));
// PublicKey publicKey = coseService.createUncompressedPointFromCOSEPublicKey(uncompressedECPointNode);
// } catch (IOException e) {
// e.printStackTrace();
// }
// Mark Fido registration entry as migrated
fidoRegistration.setStatus(DeviceRegistrationStatus.MIGRATED);
fidoRegistration.setDeletable(false);
persistenceEntryManager.merge(fidoRegistration);
}
}
Aggregations