Search in sources :

Example 1 with AuthenticatorDataConverter

use of com.webauthn4j.converter.AuthenticatorDataConverter in project webauthn4j by webauthn4j.

the class PackedAttestationStatementValidatorTest method generateSignature.

private <T extends ExtensionAuthenticatorOutput> byte[] generateSignature(String signAlg, KeyPair keyPair, AuthenticatorData<T> data, byte[] clientDataJSON) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
    byte[] authenticatorData = new AuthenticatorDataConverter(objectConverter).convert(data);
    byte[] clientDataHash = MessageDigestUtil.createSHA256().digest(clientDataJSON);
    byte[] signedData = ByteBuffer.allocate(authenticatorData.length + clientDataHash.length).put(authenticatorData).put(clientDataHash).array();
    Signature sig = Signature.getInstance(signAlg);
    sig.initSign(keyPair.getPrivate());
    sig.update(signedData);
    return sig.sign();
}
Also used : AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter)

Example 2 with AuthenticatorDataConverter

use of com.webauthn4j.converter.AuthenticatorDataConverter in project webauthn4j-spring-security by webauthn4j.

the class WebAuthnAuthenticationRequestTest method getter_test.

@Test
public void getter_test() {
    byte[] clientDataJSON = TestDataUtil.createClientDataJSON(ClientDataType.WEBAUTHN_GET);
    byte[] authenticatorData = new AuthenticatorDataConverter(objectConverter).convert(TestDataUtil.createAuthenticatorData());
    WebAuthnAuthenticationRequest request = new WebAuthnAuthenticationRequest(new byte[] { 0x01, 0x23 }, clientDataJSON, authenticatorData, new byte[] { 0x45, 0x56 }, "");
    assertThat(request.getCredentialId()).isEqualTo(new byte[] { 0x01, 0x23 });
    assertThat(request.getClientDataJSON()).isEqualTo(clientDataJSON);
    assertThat(request.getAuthenticatorData()).isEqualTo(authenticatorData);
    assertThat(request.getSignature()).isEqualTo(new byte[] { 0x45, 0x56 });
    assertThat(request.getClientExtensionsJSON()).isEmpty();
}
Also used : AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter) Test(org.junit.Test)

Example 3 with AuthenticatorDataConverter

use of com.webauthn4j.converter.AuthenticatorDataConverter in project webauthn4j by webauthn4j.

the class RegistrationObjectTest method getter_test.

@Test
void getter_test() {
    CollectedClientData clientData = TestDataUtil.createClientData(ClientDataType.WEBAUTHN_CREATE);
    byte[] clientDataBytes = new CollectedClientDataConverter(objectConverter).convertToBytes(clientData);
    AttestationObject attestationObject = TestDataUtil.createAttestationObjectWithFIDOU2FAttestationStatement();
    byte[] attestationObjectBytes = new AttestationObjectConverter(objectConverter).convertToBytes(attestationObject);
    AuthenticatorData<RegistrationExtensionAuthenticatorOutput> authenticatorData = TestDataUtil.createAuthenticatorData();
    byte[] authenticatorDataBytes = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData);
    Set<AuthenticatorTransport> transports = Collections.emptySet();
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> clientExtensions = new AuthenticationExtensionsClientOutputs<>();
    ServerProperty serverProperty = TestDataUtil.createServerProperty();
    Instant timestamp = Instant.now();
    RegistrationObject registrationObject = new RegistrationObject(attestationObject, attestationObjectBytes, clientData, clientDataBytes, clientExtensions, transports, serverProperty, timestamp);
    assertAll(() -> assertThat(registrationObject.getCollectedClientData()).isEqualTo(clientData), () -> assertThat(registrationObject.getCollectedClientDataBytes()).isEqualTo(clientDataBytes), () -> assertThat(registrationObject.getAttestationObject()).isEqualTo(attestationObject), () -> assertThat(registrationObject.getAttestationObjectBytes()).isEqualTo(attestationObjectBytes), () -> assertThat(registrationObject.getAuthenticatorDataBytes()).isEqualTo(authenticatorDataBytes), () -> assertThat(registrationObject.getTransports()).isEqualTo(transports), () -> assertThat(registrationObject.getClientExtensions()).isEqualTo(clientExtensions), () -> assertThat(registrationObject.getServerProperty()).isEqualTo(serverProperty), () -> assertThat(registrationObject.getTimestamp()).isEqualTo(timestamp));
}
Also used : AttestationObjectConverter(com.webauthn4j.converter.AttestationObjectConverter) AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter) ServerProperty(com.webauthn4j.server.ServerProperty) Instant(java.time.Instant) RegistrationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput) CollectedClientDataConverter(com.webauthn4j.converter.CollectedClientDataConverter) RegistrationExtensionClientOutput(com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) AuthenticatorTransport(com.webauthn4j.data.AuthenticatorTransport) Test(org.junit.jupiter.api.Test)

Example 4 with AuthenticatorDataConverter

use of com.webauthn4j.converter.AuthenticatorDataConverter 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 5 with AuthenticatorDataConverter

use of com.webauthn4j.converter.AuthenticatorDataConverter 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

AuthenticatorDataConverter (com.webauthn4j.converter.AuthenticatorDataConverter)6 CollectedClientDataConverter (com.webauthn4j.converter.CollectedClientDataConverter)3 CollectedClientData (com.webauthn4j.data.client.CollectedClientData)3 AuthenticationExtensionsClientOutputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs)3 ServerProperty (com.webauthn4j.server.ServerProperty)3 Test (org.junit.jupiter.api.Test)3 Authenticator (com.webauthn4j.authenticator.Authenticator)2 AuthenticationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput)2 AuthenticationExtensionClientOutput (com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput)2 Test (org.junit.Test)2 AttestationObjectConverter (com.webauthn4j.converter.AttestationObjectConverter)1 AuthenticatorTransport (com.webauthn4j.data.AuthenticatorTransport)1 AttestationObject (com.webauthn4j.data.attestation.AttestationObject)1 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)1 RegistrationExtensionClientOutput (com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput)1 Instant (java.time.Instant)1