Search in sources :

Example 1 with Fido2RegistrationEntry

use of io.jans.fido2.model.entry.Fido2RegistrationEntry 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);
}
Also used : Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) Fido2RegistrationStatus(io.jans.fido2.model.entry.Fido2RegistrationStatus) StringUtils(org.apache.commons.lang.StringUtils) UserVerification(io.jans.fido2.ctap.UserVerification) Fido2RegistrationData(io.jans.fido2.model.entry.Fido2RegistrationData) DeviceRegistrationService(io.jans.u2f.service.persist.DeviceRegistrationService) AuthenticatorAttachment(io.jans.fido2.ctap.AuthenticatorAttachment) Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Inject(javax.inject.Inject) Fido2RuntimeException(io.jans.fido2.exception.Fido2RuntimeException) Pair(org.apache.commons.lang3.tuple.Pair) Fido2AuthenticationStatus(io.jans.fido2.model.entry.Fido2AuthenticationStatus) DataMapperService(io.jans.fido2.service.DataMapperService) DeviceRegistration(io.jans.entry.DeviceRegistration) JsonNode(com.fasterxml.jackson.databind.JsonNode) StringHelper(io.jans.util.StringHelper) AttestationFormat(io.jans.fido2.ctap.AttestationFormat) AppConfiguration(io.jans.fido2.model.conf.AppConfiguration) Fido2AuthenticationData(io.jans.fido2.model.entry.Fido2AuthenticationData) Logger(org.slf4j.Logger) Fido2CompromisedDevice(io.jans.fido2.exception.Fido2CompromisedDevice) Fido2AuthenticationEntry(io.jans.fido2.model.entry.Fido2AuthenticationEntry) ChallengeGenerator(io.jans.fido2.service.ChallengeGenerator) AuthenticationPersistenceService(io.jans.fido2.service.persist.AuthenticationPersistenceService) Collectors(java.util.stream.Collectors) PublicKeyCredentialDescriptor(io.jans.fido2.model.auth.PublicKeyCredentialDescriptor) CommonVerifiers(io.jans.fido2.service.verifier.CommonVerifiers) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) RegistrationPersistenceService(io.jans.fido2.service.persist.RegistrationPersistenceService) AssertionVerifier(io.jans.fido2.service.verifier.AssertionVerifier) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DomainVerifier(io.jans.fido2.service.verifier.DomainVerifier) NetworkService(io.jans.service.net.NetworkService) PublicKeyCredentialDescriptor(io.jans.fido2.model.auth.PublicKeyCredentialDescriptor) DeviceRegistration(io.jans.entry.DeviceRegistration) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Fido2RegistrationEntry

use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.

the class AttestationService method prepareExcludeCredentials.

private ArrayNode prepareExcludeCredentials(String documentDomain, String username) {
    List<Fido2RegistrationEntry> existingRegistrations = registrationPersistenceService.findAllRegisteredByUsername(username);
    List<JsonNode> excludedKeys = existingRegistrations.parallelStream().filter(f -> StringHelper.equals(documentDomain, f.getRegistrationData().getDomain())).filter(f -> StringHelper.isNotEmpty(f.getRegistrationData().getPublicKeyId())).map(f -> dataMapperService.convertValue(new PublicKeyCredentialDescriptor(f.getRegistrationData().getType(), new String[] { "usb", "ble", "nfc", "internal" }, f.getRegistrationData().getPublicKeyId()), JsonNode.class)).collect(Collectors.toList());
    ArrayNode excludedCredentials = dataMapperService.createArrayNode();
    excludedCredentials.addAll(excludedKeys);
    return excludedCredentials;
}
Also used : Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) Fido2RegistrationStatus(io.jans.fido2.model.entry.Fido2RegistrationStatus) Base64Service(io.jans.fido2.service.Base64Service) UserVerification(io.jans.fido2.ctap.UserVerification) Fido2RegistrationData(io.jans.fido2.model.entry.Fido2RegistrationData) CoseEC2Algorithm(io.jans.fido2.ctap.CoseEC2Algorithm) AuthenticatorAttachment(io.jans.fido2.ctap.AuthenticatorAttachment) Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) CredAndCounterData(io.jans.fido2.model.auth.CredAndCounterData) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SecureRandom(java.security.SecureRandom) Inject(javax.inject.Inject) RequestedParty(io.jans.fido2.model.conf.RequestedParty) Fido2RuntimeException(io.jans.fido2.exception.Fido2RuntimeException) DataMapperService(io.jans.fido2.service.DataMapperService) JsonNode(com.fasterxml.jackson.databind.JsonNode) StringHelper(io.jans.util.StringHelper) AppConfiguration(io.jans.fido2.model.conf.AppConfiguration) Logger(org.slf4j.Logger) AttestationVerifier(io.jans.fido2.service.verifier.AttestationVerifier) AttestationConveyancePreference(io.jans.fido2.ctap.AttestationConveyancePreference) ChallengeGenerator(io.jans.fido2.service.ChallengeGenerator) Collectors(java.util.stream.Collectors) PublicKeyCredentialDescriptor(io.jans.fido2.model.auth.PublicKeyCredentialDescriptor) CommonVerifiers(io.jans.fido2.service.verifier.CommonVerifiers) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) CoseRSAAlgorithm(io.jans.fido2.ctap.CoseRSAAlgorithm) RegistrationPersistenceService(io.jans.fido2.service.persist.RegistrationPersistenceService) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DomainVerifier(io.jans.fido2.service.verifier.DomainVerifier) PublicKeyCredentialDescriptor(io.jans.fido2.model.auth.PublicKeyCredentialDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with Fido2RegistrationEntry

use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.

the class RegistrationPersistenceService method findAllByUsername.

public List<Fido2RegistrationEntry> findAllByUsername(String username) {
    String userInum = userService.getUserInum(username);
    if (userInum == null) {
        return Collections.emptyList();
    }
    String baseDn = getBaseDnForFido2RegistrationEntries(userInum);
    if (persistenceEntryManager.hasBranchesSupport(baseDn)) {
        if (!containsBranch(baseDn)) {
            return Collections.emptyList();
        }
    }
    Filter userFilter = Filter.createEqualityFilter("personInum", userInum);
    List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, userFilter);
    return fido2RegistrationnEntries;
}
Also used : Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) Filter(io.jans.orm.search.filter.Filter)

Example 4 with Fido2RegistrationEntry

use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.

the class RegistrationPersistenceService method update.

public void update(Fido2RegistrationEntry registrationEntry) {
    Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
    Fido2RegistrationData registrationData = registrationEntry.getRegistrationData();
    registrationData.setUpdatedDate(now);
    registrationData.setUpdatedBy(registrationData.getUsername());
    registrationEntry.setPublicKeyId(registrationData.getPublicKeyId());
    registrationEntry.setRegistrationStatus(registrationData.getStatus());
    persistenceEntryManager.merge(registrationEntry);
}
Also used : Fido2RegistrationData(io.jans.fido2.model.entry.Fido2RegistrationData) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 5 with Fido2RegistrationEntry

use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.

the class RegistrationPersistenceService method findByChallenge.

public List<Fido2RegistrationEntry> findByChallenge(String challenge) {
    String baseDn = getBaseDnForFido2RegistrationEntries(null);
    Filter codeChallengFilter = Filter.createEqualityFilter("jansCodeChallenge", challenge);
    Filter codeChallengHashCodeFilter = Filter.createEqualityFilter("jansCodeChallengeHash", String.valueOf(getChallengeHashCode(challenge)));
    Filter filter = Filter.createANDFilter(codeChallengFilter, codeChallengHashCodeFilter);
    List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, filter);
    return fido2RegistrationnEntries;
}
Also used : Fido2RegistrationEntry(io.jans.fido2.model.entry.Fido2RegistrationEntry) Filter(io.jans.orm.search.filter.Filter)

Aggregations

Fido2RegistrationEntry (io.jans.fido2.model.entry.Fido2RegistrationEntry)12 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)6 Fido2RegistrationData (io.jans.fido2.model.entry.Fido2RegistrationData)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 PublicKeyCredentialDescriptor (io.jans.fido2.model.auth.PublicKeyCredentialDescriptor)4 Filter (io.jans.orm.search.filter.Filter)4 List (java.util.List)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 DeviceRegistration (io.jans.entry.DeviceRegistration)2 AuthenticatorAttachment (io.jans.fido2.ctap.AuthenticatorAttachment)2 UserVerification (io.jans.fido2.ctap.UserVerification)2 Fido2CompromisedDevice (io.jans.fido2.exception.Fido2CompromisedDevice)2 CredAndCounterData (io.jans.fido2.model.auth.CredAndCounterData)2 AppConfiguration (io.jans.fido2.model.conf.AppConfiguration)2 Fido2AuthenticationData (io.jans.fido2.model.entry.Fido2AuthenticationData)2 Fido2AuthenticationEntry (io.jans.fido2.model.entry.Fido2AuthenticationEntry)2 Fido2RegistrationStatus (io.jans.fido2.model.entry.Fido2RegistrationStatus)2 ChallengeGenerator (io.jans.fido2.service.ChallengeGenerator)2 DataMapperService (io.jans.fido2.service.DataMapperService)2