Search in sources :

Example 6 with AuthenticatorData

use of com.webauthn4j.data.attestation.authenticator.AuthenticatorData in project webauthn4j by webauthn4j.

the class FIDOU2FAuthenticatorAdaptor method authenticate.

@Override
public CredentialRequestResponse authenticate(PublicKeyCredentialRequestOptions publicKeyCredentialRequestOptions, CollectedClientData collectedClientData, AuthenticationEmulationOption authenticationEmulationOption) {
    byte[] collectedClientDataBytes = collectedClientDataConverter.convertToBytes(collectedClientData);
    String rpId = publicKeyCredentialRequestOptions.getRpId();
    byte[] rpIdHash = MessageDigestUtil.createSHA256().digest(rpId.getBytes(StandardCharsets.UTF_8));
    byte control = 0x00;
    byte[] challenge = MessageDigestUtil.createSHA256().digest(collectedClientDataBytes);
    // noinspection UnnecessaryLocalVariable
    byte[] applicationParameter = rpIdHash;
    List<PublicKeyCredentialDescriptor> publicKeyCredentialDescriptors = publicKeyCredentialRequestOptions.getAllowCredentials();
    PublicKeyCredentialDescriptor publicKeyCredentialDescriptor = publicKeyCredentialDescriptors.get(0);
    // TODO: what to do if multiple publicKeyCredentialDescriptors are supplied
    byte[] keyHandle = publicKeyCredentialDescriptor.getId();
    AuthenticationRequest authenticationRequest = new AuthenticationRequest(control, challenge, applicationParameter, keyHandle);
    AuthenticationResponse authenticationResponse = fidoU2FAuthenticator.authenticate(authenticationRequest, authenticationEmulationOption);
    byte[] credentialId = publicKeyCredentialDescriptor.getId();
    long counter = ByteBuffer.allocate(8).put(new byte[4]).put(authenticationResponse.getCounter()).getLong(0);
    AuthenticatorData<AuthenticationExtensionAuthenticatorOutput> authenticatorData = new AuthenticatorData<>(rpIdHash, authenticationResponse.getUserPresence(), counter);
    byte[] authenticatorDataBytes = authenticatorDataConverter.convert(authenticatorData);
    byte[] signature = authenticationResponse.getSignature();
    return new CredentialRequestResponse(credentialId, collectedClientDataBytes, authenticatorDataBytes, signature, null);
}
Also used : PublicKeyCredentialDescriptor(com.webauthn4j.data.PublicKeyCredentialDescriptor) AuthenticationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput) AuthenticatorData(com.webauthn4j.data.attestation.authenticator.AuthenticatorData) CredentialRequestResponse(com.webauthn4j.test.authenticator.CredentialRequestResponse)

Aggregations

AuthenticatorData (com.webauthn4j.data.attestation.authenticator.AuthenticatorData)6 PublicKeyCredentialDescriptor (com.webauthn4j.data.PublicKeyCredentialDescriptor)3 AttestedCredentialData (com.webauthn4j.data.attestation.authenticator.AttestedCredentialData)3 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)3 AttestationObject (com.webauthn4j.data.attestation.AttestationObject)2 AttestationStatement (com.webauthn4j.data.attestation.statement.AttestationStatement)2 AuthenticationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput)2 AuthenticationExtensionsAuthenticatorOutputs (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionsAuthenticatorOutputs)2 DataConversionException (com.webauthn4j.converter.exception.DataConversionException)1 PublicKeyCredentialParameters (com.webauthn4j.data.PublicKeyCredentialParameters)1 PublicKeyCredentialRpEntity (com.webauthn4j.data.PublicKeyCredentialRpEntity)1 AAGUID (com.webauthn4j.data.attestation.authenticator.AAGUID)1 COSEKey (com.webauthn4j.data.attestation.authenticator.COSEKey)1 EC2COSEKey (com.webauthn4j.data.attestation.authenticator.EC2COSEKey)1 AttestationCertificatePath (com.webauthn4j.data.attestation.statement.AttestationCertificatePath)1 FIDOU2FAttestationStatement (com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement)1 UvmEntries (com.webauthn4j.data.extension.UvmEntries)1 CredentialCreationResponse (com.webauthn4j.test.authenticator.CredentialCreationResponse)1 CredentialRequestResponse (com.webauthn4j.test.authenticator.CredentialRequestResponse)1 BufferUnderflowException (java.nio.BufferUnderflowException)1