Search in sources :

Example 11 with CollectedClientData

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

the class ChallengeValidatorTest method validate_test1.

@Test
void validate_test1() {
    Challenge challengeA = new DefaultChallenge(new byte[] { 0x00 });
    Challenge challengeB = new DefaultChallenge(new byte[] { 0x00 });
    CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.WEBAUTHN_CREATE, challengeA, Origin.create("http://example.com"), null);
    ServerProperty serverProperty = new ServerProperty(origin, rpId, challengeB, null);
    // When
    target.validate(collectedClientData, serverProperty);
}
Also used : DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) ServerProperty(com.webauthn4j.server.ServerProperty) Challenge(com.webauthn4j.data.client.challenge.Challenge) DefaultChallenge(com.webauthn4j.data.client.challenge.DefaultChallenge) Test(org.junit.jupiter.api.Test)

Example 12 with CollectedClientData

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

the class PackedAttestationStatementValidatorTest method validate.

private void validate(byte[] clientDataBytes, AttestationObject attestationObject) {
    byte[] attestationObjectBytes = new AttestationObjectConverter(objectConverter).convertToBytes(attestationObject);
    Origin origin = new Origin(originUrl);
    Challenge challenge = (Challenge) () -> Base64UrlUtil.decode(challengeString);
    CollectedClientData collectedClientData = new CollectedClientDataConverter(objectConverter).convert(clientDataBytes);
    Set<AuthenticatorTransport> transports = Collections.emptySet();
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> authenticationExtensionsClientOutputs = new AuthenticationExtensionsClientOutputs<>();
    RegistrationObject registrationObject = new RegistrationObject(attestationObject, attestationObjectBytes, collectedClientData, clientDataBytes, authenticationExtensionsClientOutputs, transports, new ServerProperty(origin, rpId, challenge, tokenBindingId));
    target.validate(registrationObject);
}
Also used : Origin(com.webauthn4j.data.client.Origin) AttestationObjectConverter(com.webauthn4j.converter.AttestationObjectConverter) ServerProperty(com.webauthn4j.server.ServerProperty) CollectedClientDataConverter(com.webauthn4j.converter.CollectedClientDataConverter) RegistrationExtensionClientOutput(com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput) Challenge(com.webauthn4j.data.client.challenge.Challenge) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) RegistrationObject(com.webauthn4j.validator.RegistrationObject) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) AuthenticatorTransport(com.webauthn4j.data.AuthenticatorTransport)

Example 13 with CollectedClientData

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

the class OriginValidatorImplTest method apk_key_hash_sha256_test_with_not_equal_origins_apk_key_hash_sha1.

@SuppressWarnings("java:S5976")
@Test
void apk_key_hash_sha256_test_with_not_equal_origins_apk_key_hash_sha1() {
    Origin originA = new Origin("android:apk-key-hash-sha256:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    Origin originB = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.WEBAUTHN_CREATE, TestDataUtil.createChallenge(), originA, null);
    ServerProperty serverProperty = new ServerProperty(originB, "3.example.com", TestDataUtil.createChallenge(), null);
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty));
}
Also used : Origin(com.webauthn4j.data.client.Origin) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) ServerProperty(com.webauthn4j.server.ServerProperty) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with CollectedClientData

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

the class OriginValidatorImplTest method apk_key_hash_sha1_test_with_not_equal_origins_apk_key_hash_sha256.

@SuppressWarnings("java:S5976")
@Test
void apk_key_hash_sha1_test_with_not_equal_origins_apk_key_hash_sha256() {
    Origin originA = new Origin("android:apk-key-hash:aNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    Origin originB = new Origin("android:apk-key-hash-sha256:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    CollectedClientData collectedClientData = new CollectedClientData(ClientDataType.WEBAUTHN_CREATE, TestDataUtil.createChallenge(), originA, null);
    ServerProperty serverProperty = new ServerProperty(originB, "4.example.com", TestDataUtil.createChallenge(), null);
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientData, serverProperty));
}
Also used : Origin(com.webauthn4j.data.client.Origin) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) ServerProperty(com.webauthn4j.server.ServerProperty) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with CollectedClientData

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

the class OriginValidatorImplTest method multiple_origins_test_with_invalid_origin.

@Test
void multiple_origins_test_with_invalid_origin() {
    final Origin originA = new Origin("https://example.com:14443");
    final Origin originB = new Origin("http://localhost:9090");
    final Origin originC = new Origin("android:apk-key-hash:pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    final Origin originD = new Origin("android:apk-key-hash-sha256:qSiQ5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    final Origin badOriginA = new Origin("https://example.phish.com:14443");
    final Origin badOriginB = new Origin("http://phish.localhost:9090");
    final Origin badOriginC = new Origin("android:apk-key-hash:0pNiP5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    final Origin badOriginD = new Origin("android:apk-key-hash-sha256:0qSiQ5iKyQ8JwgGOaKA1zGPUPJIS-0H1xKCQcfIoGLck");
    final ServerProperty serverProperty = new ServerProperty(new HashSet<>(Arrays.asList(originA, originB, originC, originD)), "example.com", TestDataUtil.createChallenge(), null);
    final CollectedClientData collectedClientDataA = new CollectedClientData(ClientDataType.WEBAUTHN_CREATE, TestDataUtil.createChallenge(), badOriginA, null);
    final CollectedClientData collectedClientDataB = new CollectedClientData(ClientDataType.WEBAUTHN_CREATE, TestDataUtil.createChallenge(), badOriginB, null);
    final CollectedClientData collectedClientDataC = new CollectedClientData(ClientDataType.WEBAUTHN_GET, TestDataUtil.createChallenge(), badOriginC, null);
    final CollectedClientData collectedClientDataD = new CollectedClientData(ClientDataType.WEBAUTHN_GET, TestDataUtil.createChallenge(), badOriginD, null);
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataA, serverProperty));
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataB, serverProperty));
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataC, serverProperty));
    assertThrows(BadOriginException.class, () -> target.validate(collectedClientDataD, serverProperty));
}
Also used : Origin(com.webauthn4j.data.client.Origin) ServerProperty(com.webauthn4j.server.ServerProperty) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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