Search in sources :

Example 1 with CredentialRequestResponse

use of com.webauthn4j.test.authenticator.CredentialRequestResponse in project webauthn4j by webauthn4j.

the class ClientPlatform method get.

public PublicKeyCredential<AuthenticatorAssertionResponse, AuthenticationExtensionClientOutput> get(PublicKeyCredentialRequestOptions publicKeyCredentialRequestOptions, CollectedClientData collectedClientData, AuthenticationEmulationOption authenticationEmulationOption) {
    NoAuthenticatorSuccessException noAuthenticatorSuccessException = new NoAuthenticatorSuccessException();
    if (authenticatorAdaptor == null) {
        throw noAuthenticatorSuccessException;
    }
    try {
        CredentialRequestResponse credentialRequestResponse = authenticatorAdaptor.authenticate(publicKeyCredentialRequestOptions, collectedClientData, authenticationEmulationOption);
        byte[] credentialId = credentialRequestResponse.getCredentialId();
        AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> clientExtensions = processAuthenticationExtensions(publicKeyCredentialRequestOptions.getExtensions());
        return new PublicKeyCredential<>(credentialId, new AuthenticatorAssertionResponse(credentialRequestResponse.getCollectedClientDataBytes(), credentialRequestResponse.getAuthenticatorDataBytes(), credentialRequestResponse.getSignature(), credentialRequestResponse.getUserHandle()), clientExtensions);
    } catch (ValidationException e) {
        noAuthenticatorSuccessException.addSuppressed(e);
    }
    throw noAuthenticatorSuccessException;
}
Also used : ValidationException(com.webauthn4j.validator.exception.ValidationException) CredentialRequestResponse(com.webauthn4j.test.authenticator.CredentialRequestResponse)

Example 2 with CredentialRequestResponse

use of com.webauthn4j.test.authenticator.CredentialRequestResponse 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

CredentialRequestResponse (com.webauthn4j.test.authenticator.CredentialRequestResponse)2 PublicKeyCredentialDescriptor (com.webauthn4j.data.PublicKeyCredentialDescriptor)1 AuthenticatorData (com.webauthn4j.data.attestation.authenticator.AuthenticatorData)1 AuthenticationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput)1 ValidationException (com.webauthn4j.validator.exception.ValidationException)1