Search in sources :

Example 21 with CollectedClientData

use of com.webauthn4j.data.client.CollectedClientData in project webauthn4j by webauthn4j.

the class OriginValidatorImpl method validate.

// ~ Instance fields
// ================================================================================================
// ~ Methods
// ========================================================================================================
@Override
public void validate(@NonNull RegistrationObject registrationObject) {
    AssertUtil.notNull(registrationObject, "registrationObject must not be null");
    CollectedClientData collectedClientData = registrationObject.getCollectedClientData();
    ServerProperty serverProperty = registrationObject.getServerProperty();
    validate(collectedClientData, serverProperty);
}
Also used : CollectedClientData(com.webauthn4j.data.client.CollectedClientData) ServerProperty(com.webauthn4j.server.ServerProperty)

Example 22 with CollectedClientData

use of com.webauthn4j.data.client.CollectedClientData in project webauthn4j by webauthn4j.

the class OriginValidatorImpl method validate.

@Override
public void validate(@NonNull AuthenticationObject authenticationObject) {
    AssertUtil.notNull(authenticationObject, "authenticationObject must not be null");
    CollectedClientData collectedClientData = authenticationObject.getCollectedClientData();
    ServerProperty serverProperty = authenticationObject.getServerProperty();
    validate(collectedClientData, serverProperty);
}
Also used : CollectedClientData(com.webauthn4j.data.client.CollectedClientData) ServerProperty(com.webauthn4j.server.ServerProperty)

Example 23 with CollectedClientData

use of com.webauthn4j.data.client.CollectedClientData in project webauthn4j by webauthn4j.

the class CollectedClientDataConverterTest method convert_clientDataBase64UrlString_with_new_keys_test.

@Test
void convert_clientDataBase64UrlString_with_new_keys_test() {
    // noinspection SpellCheckingInspection
    String clientDataJson = "{\"challenge\":\"Tgup0LZZQKinvtQcZFYdRw\",\"new_keys_may_be_added_here\":\"do not compare clientDataJSON against a template. See https://goo.gl/yabPex\",\"origin\":\"http://localhost:8080\",\"tokenBinding\":{\"status\":\"not-supported\"},\"type\":\"webauthn.create\"}";
    String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8));
    CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString);
    assertAll(() -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.WEBAUTHN_CREATE), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("Tgup0LZZQKinvtQcZFYdRw")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("http://localhost:8080")), () -> assertThat(collectedClientData.getCrossOrigin()).isNull());
}
Also used : Origin(com.webauthn4j.data.client.Origin) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) Test(org.junit.jupiter.api.Test)

Example 24 with CollectedClientData

use of com.webauthn4j.data.client.CollectedClientData in project webauthn4j by webauthn4j.

the class CollectedClientDataConverterTest method convertToString_deserialization_test.

@Test
void convertToString_deserialization_test() {
    // noinspection SpellCheckingInspection
    String clientDataJson = "{\"challenge\":\"tk31UH1ETGGTPj33OhOMzw\",\"origin\":\"http://localhost:8080\",\"tokenBinding\":{\"status\":\"not-supported\"},\"type\":\"webauthn.get\"}";
    String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8));
    CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString);
    String result = target.convertToBase64UrlString(collectedClientData);
    // noinspection SpellCheckingInspection
    assertThat(result).isEqualTo("eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoidGszMVVIMUVUR0dUUGozM09oT016dyIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsInRva2VuQmluZGluZyI6eyJzdGF0dXMiOiJub3Qtc3VwcG9ydGVkIn19");
}
Also used : CollectedClientData(com.webauthn4j.data.client.CollectedClientData) Test(org.junit.jupiter.api.Test)

Example 25 with CollectedClientData

use of com.webauthn4j.data.client.CollectedClientData in project webauthn4j by webauthn4j.

the class CollectedClientDataConverterTest method convert_deserialization_test.

@Test
void convert_deserialization_test() {
    // noinspection SpellCheckingInspection
    String clientDataJson = "{\"challenge\":\"tk31UH1ETGGTPj33OhOMzw\",\"origin\":\"http://localhost:8080\",\"crossOrigin\":true,\"tokenBinding\":{\"status\":\"not-supported\"},\"type\":\"webauthn.get\"}";
    String clientDataBase64UrlString = Base64UrlUtil.encodeToString(clientDataJson.getBytes(StandardCharsets.UTF_8));
    CollectedClientData collectedClientData = target.convert(clientDataBase64UrlString);
    assertAll(() -> assertThat(collectedClientData.getType()).isEqualTo(ClientDataType.WEBAUTHN_GET), () -> assertThat(collectedClientData.getChallenge()).isEqualTo(new DefaultChallenge("tk31UH1ETGGTPj33OhOMzw")), () -> assertThat(collectedClientData.getOrigin()).isEqualTo(new Origin("http://localhost:8080")), () -> assertThat(collectedClientData.getCrossOrigin()).isTrue());
}
Also used : Origin(com.webauthn4j.data.client.Origin) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) Test(org.junit.jupiter.api.Test)

Aggregations

CollectedClientData (com.webauthn4j.data.client.CollectedClientData)56 Test (org.junit.jupiter.api.Test)33 ServerProperty (com.webauthn4j.server.ServerProperty)30 AttestationObject (com.webauthn4j.data.attestation.AttestationObject)23 RegistrationExtensionClientOutput (com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput)19 Origin (com.webauthn4j.data.client.Origin)17 AuthenticationExtensionsClientOutputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs)16 DefaultChallenge (com.webauthn4j.data.client.challenge.DefaultChallenge)14 AuthenticationExtensionClientOutput (com.webauthn4j.data.extension.client.AuthenticationExtensionClientOutput)11 Challenge (com.webauthn4j.data.client.challenge.Challenge)10 AuthenticatorTransport (com.webauthn4j.data.AuthenticatorTransport)8 RegistrationObject (com.webauthn4j.validator.RegistrationObject)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 DCRegistrationObject (com.webauthn4j.appattest.validator.DCRegistrationObject)7 Authenticator (com.webauthn4j.authenticator.Authenticator)7 CollectedClientDataConverter (com.webauthn4j.converter.CollectedClientDataConverter)7 AuthenticationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionAuthenticatorOutput)7 CoreRegistrationObject (com.webauthn4j.validator.CoreRegistrationObject)7 Test (org.junit.Test)5 RegistrationData (com.webauthn4j.data.RegistrationData)4