Search in sources :

Example 11 with AuthenticationExtensionAuthenticatorOutput

use of com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput in project webauthn4j by webauthn4j.

the class AuthenticationDataTest method toString_test.

@Test
void toString_test() {
    byte[] credentialId = new byte[32];
    byte[] userHandle = new byte[32];
    AuthenticatorData<AuthenticationExtensionAuthenticatorOutput> authenticatorData = null;
    byte[] authenticatorDataBytes = new byte[64];
    CollectedClientData collectedClientData = mock(CollectedClientData.class);
    byte[] collectedClientDataBytes = new byte[128];
    AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> authenticationExtensionsClientOutputs = null;
    byte[] signature = new byte[32];
    AuthenticationData instance = new AuthenticationData(credentialId, userHandle, authenticatorData, authenticatorDataBytes, collectedClientData, collectedClientDataBytes, authenticationExtensionsClientOutputs, signature);
    // noinspection ResultOfMethodCallIgnored
    assertThatCode(instance::toString).doesNotThrowAnyException();
}
Also used : AuthenticationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AuthenticationExtensionClientOutput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput) Test(org.junit.jupiter.api.Test)

Example 12 with AuthenticationExtensionAuthenticatorOutput

use of com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput 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)

Example 13 with AuthenticationExtensionAuthenticatorOutput

use of com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput in project webauthn4j by webauthn4j.

the class WebAuthnAuthenticationManager method parse.

@SuppressWarnings("squid:S1130")
@NonNull
public AuthenticationData parse(@NonNull AuthenticationRequest authenticationRequest) throws DataConversionException {
    AssertUtil.notNull(authenticationRequest, "authenticationRequest must not be null");
    byte[] credentialId = authenticationRequest.getCredentialId();
    byte[] signature = authenticationRequest.getSignature();
    byte[] userHandle = authenticationRequest.getUserHandle();
    byte[] clientDataBytes = authenticationRequest.getClientDataJSON();
    CollectedClientData collectedClientData = clientDataBytes == null ? null : collectedClientDataConverter.convert(clientDataBytes);
    byte[] authenticatorDataBytes = authenticationRequest.getAuthenticatorData();
    AuthenticatorData<AuthenticationExtensionAuthenticatorOutput> authenticatorData = authenticatorDataBytes == null ? null : authenticatorDataConverter.convert(authenticatorDataBytes);
    AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> clientExtensions = authenticationRequest.getClientExtensionsJSON() == null ? null : authenticationExtensionsClientOutputsConverter.convert(authenticationRequest.getClientExtensionsJSON());
    return new AuthenticationData(credentialId, userHandle, authenticatorData, authenticatorDataBytes, collectedClientData, clientDataBytes, clientExtensions, signature);
}
Also used : CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AuthenticationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput) AuthenticationData(com.webauthn4j.data.AuthenticationData) AuthenticationExtensionClientOutput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 14 with AuthenticationExtensionAuthenticatorOutput

use of com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput in project webauthn4j by webauthn4j.

the class AuthenticationObjectTest method equals_hashCode_test.

@Test
void equals_hashCode_test() {
    byte[] credentialId = new byte[32];
    CollectedClientData clientData = TestDataUtil.createClientData(ClientDataType.WEBAUTHN_CREATE);
    byte[] clientDataBytes = new CollectedClientDataConverter(objectConverter).convertToBytes(clientData);
    AuthenticatorData<AuthenticationExtensionAuthenticatorOutput> authenticatorData = TestDataUtil.createAuthenticatorData();
    byte[] authenticatorDataBytes = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData);
    AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> clientExtensions = new AuthenticationExtensionsClientOutputs<>();
    ServerProperty serverProperty = TestDataUtil.createServerProperty();
    Authenticator authenticator = TestDataUtil.createAuthenticator();
    AuthenticationObject instanceA = new AuthenticationObject(credentialId, authenticatorData, authenticatorDataBytes, clientData, clientDataBytes, clientExtensions, serverProperty, authenticator);
    AuthenticationObject instanceB = new AuthenticationObject(credentialId, authenticatorData, authenticatorDataBytes, clientData, clientDataBytes, clientExtensions, serverProperty, authenticator);
    assertAll(() -> assertThat(instanceA).isEqualTo(instanceB), () -> assertThat(instanceA).hasSameHashCodeAs(instanceB));
}
Also used : AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AuthenticationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput) ServerProperty(com.webauthn4j.server.ServerProperty) AuthenticationExtensionClientOutput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) CollectedClientDataConverter(com.webauthn4j.converter.CollectedClientDataConverter) Authenticator(com.webauthn4j.authenticator.Authenticator) Test(org.junit.jupiter.api.Test)

Example 15 with AuthenticationExtensionAuthenticatorOutput

use of com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput in project webauthn4j by webauthn4j.

the class AuthenticationObjectTest method getter_test.

@Test
void getter_test() {
    byte[] credentialId = new byte[32];
    CollectedClientData clientData = TestDataUtil.createClientData(ClientDataType.WEBAUTHN_CREATE);
    byte[] clientDataBytes = new CollectedClientDataConverter(objectConverter).convertToBytes(clientData);
    AuthenticatorData<AuthenticationExtensionAuthenticatorOutput> authenticatorData = TestDataUtil.createAuthenticatorData();
    byte[] authenticatorDataBytes = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData);
    AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> clientExtensions = new AuthenticationExtensionsClientOutputs<>();
    ServerProperty serverProperty = TestDataUtil.createServerProperty();
    Authenticator authenticator = TestDataUtil.createAuthenticator();
    AuthenticationObject authenticationObject = new AuthenticationObject(credentialId, authenticatorData, authenticatorDataBytes, clientData, clientDataBytes, clientExtensions, serverProperty, authenticator);
    assertAll(() -> assertThat(authenticationObject.getCredentialId()).isEqualTo(credentialId), () -> assertThat(authenticationObject.getCollectedClientData()).isEqualTo(clientData), () -> assertThat(authenticationObject.getCollectedClientDataBytes()).isEqualTo(clientDataBytes), () -> assertThat(authenticationObject.getAuthenticatorData()).isEqualTo(authenticatorData), () -> assertThat(authenticationObject.getAuthenticatorDataBytes()).isEqualTo(authenticatorDataBytes), () -> assertThat(authenticationObject.getClientExtensions()).isEqualTo(clientExtensions), () -> assertThat(authenticationObject.getServerProperty()).isEqualTo(serverProperty), () -> assertThat(authenticationObject.getAuthenticator()).isEqualTo(authenticator));
}
Also used : AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AuthenticationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput) ServerProperty(com.webauthn4j.server.ServerProperty) AuthenticationExtensionClientOutput(com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) CollectedClientDataConverter(com.webauthn4j.converter.CollectedClientDataConverter) Authenticator(com.webauthn4j.authenticator.Authenticator) Test(org.junit.jupiter.api.Test)

Aggregations

AuthenticationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput)15 AuthenticationExtensionClientOutput (com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput)8 CollectedClientData (com.webauthn4j.data.client.CollectedClientData)7 Test (org.junit.jupiter.api.Test)7 Authenticator (com.webauthn4j.authenticator.Authenticator)4 ServerProperty (com.webauthn4j.server.ServerProperty)4 NonNull (org.checkerframework.checker.nullness.qual.NonNull)4 CoreAuthenticator (com.webauthn4j.authenticator.CoreAuthenticator)3 CoreServerProperty (com.webauthn4j.server.CoreServerProperty)3 DCAppleDevice (com.webauthn4j.appattest.authenticator.DCAppleDevice)2 DCAppleDeviceImpl (com.webauthn4j.appattest.authenticator.DCAppleDeviceImpl)2 AuthenticatorDataConverter (com.webauthn4j.converter.AuthenticatorDataConverter)2 CollectedClientDataConverter (com.webauthn4j.converter.CollectedClientDataConverter)2 PublicKeyCredentialDescriptor (com.webauthn4j.data.PublicKeyCredentialDescriptor)2 AuthenticatorData (com.webauthn4j.data.attestation.authenticator.AuthenticatorData)2 DefaultChallenge (com.webauthn4j.data.client.challenge.DefaultChallenge)2 AuthenticationExtensionsClientOutputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs)2 DCAssertion (com.webauthn4j.appattest.data.DCAssertion)1 DCAssertionData (com.webauthn4j.appattest.data.DCAssertionData)1 AppleAppAttestAttestationStatement (com.webauthn4j.appattest.data.attestation.statement.AppleAppAttestAttestationStatement)1