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();
}
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();
}
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));
}
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));
}
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));
}
Aggregations