Search in sources :

Example 1 with UvmEntries

use of com.webauthn4j.data.extension.UvmEntries in project webauthn4j by webauthn4j.

the class AuthenticationExtensionsClientOutputsTest method authentication_variant_test.

@SuppressWarnings("java:S5961")
@Test
void authentication_variant_test() {
    UvmEntries uvm = new UvmEntries(Collections.singletonList(new UvmEntry(UserVerificationMethod.FINGERPRINT_INTERNAL, KeyProtectionType.SOFTWARE, MatcherProtectionType.ON_CHIP)));
    AuthenticationExtensionsClientOutputs.BuilderForAuthentication builder = new AuthenticationExtensionsClientOutputs.BuilderForAuthentication();
    builder.setAppid(true);
    builder.setUvm(uvm);
    builder.setHMACGetSecret(new HMACGetSecretOutput(new byte[32], new byte[32]));
    builder.set("unknown", "data");
    AuthenticationExtensionsClientOutputs<AuthenticationExtensionClientOutput> target = builder.build();
    assertThat(target.getKeys()).containsExactlyInAnyOrder("appid", "uvm", "hmacGetSecret", "unknown");
    assertThat(target.getAppid()).isTrue();
    assertThat(target.getUvm()).isEqualTo(uvm);
    assertThat(target.getCredProps()).isNull();
    assertThat(target.getHMACCreateSecret()).isNull();
    assertThat(target.getHMACGetSecret()).isEqualTo(new HMACGetSecretOutput(new byte[32], new byte[32]));
    assertThat(target.getUnknownKeys()).containsExactly("unknown");
    assertThat((Boolean) target.getValue("appid")).isTrue();
    assertThat(target.getValue("uvm")).isEqualTo(uvm);
    assertThat(target.getValue("credProps")).isNull();
    assertThat((Boolean) target.getValue("hmacCreateSecret")).isNull();
    assertThat(target.getValue("hmacGetSecret")).isEqualTo(new HMACGetSecretOutput(new byte[32], new byte[32]));
    assertThat(target.getValue("unknown")).isEqualTo("data");
    assertThat(target.getValue("invalid")).isNull();
    assertThat(target.getExtension(FIDOAppIDExtensionClientOutput.class)).isNotNull();
    assertThat(target.getExtension(FIDOAppIDExtensionClientOutput.class).getIdentifier()).isEqualTo("appid");
    assertThat(target.getExtension(FIDOAppIDExtensionClientOutput.class).getAppid()).isTrue();
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class)).isNotNull();
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class).getIdentifier()).isEqualTo("uvm");
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class).getUvm()).isEqualTo(uvm);
    HMACSecretAuthenticationExtensionClientOutput hmacSecretAuthenticationExtensionClientOutput = target.getExtension(HMACSecretAuthenticationExtensionClientOutput.class);
    assertThat(hmacSecretAuthenticationExtensionClientOutput).isNotNull();
    assertThat(hmacSecretAuthenticationExtensionClientOutput.getIdentifier()).isEqualTo("hmac-secret");
    assertThat(hmacSecretAuthenticationExtensionClientOutput.getValue()).isEqualTo(new HMACGetSecretOutput(new byte[32], new byte[32]));
    assertThatThrownBy(() -> hmacSecretAuthenticationExtensionClientOutput.getValue("hmac-secret")).isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> hmacSecretAuthenticationExtensionClientOutput.getValue("hmacCreateSecret")).isInstanceOf(IllegalArgumentException.class);
    assertThat(hmacSecretAuthenticationExtensionClientOutput.getValue("hmacGetSecret")).isEqualTo(new HMACGetSecretOutput(new byte[32], new byte[32]));
}
Also used : UvmEntry(com.webauthn4j.data.extension.UvmEntry) HMACGetSecretOutput(com.webauthn4j.data.extension.HMACGetSecretOutput) UvmEntries(com.webauthn4j.data.extension.UvmEntries) Test(org.junit.jupiter.api.Test)

Example 2 with UvmEntries

use of com.webauthn4j.data.extension.UvmEntries in project webauthn4j by webauthn4j.

the class AuthenticationExtensionsAuthenticatorOutputsTest method toString_test.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void toString_test() {
    UvmEntries uvm = new UvmEntries(Collections.singletonList(new UvmEntry(UserVerificationMethod.FINGERPRINT_INTERNAL, KeyProtectionType.SOFTWARE, MatcherProtectionType.ON_CHIP)));
    AuthenticationExtensionsAuthenticatorOutputs.BuilderForAuthentication builder = new AuthenticationExtensionsAuthenticatorOutputs.BuilderForAuthentication();
    builder.setUvm(uvm);
    builder.set("test", "value");
    AuthenticationExtensionsAuthenticatorOutputs<AuthenticationExtensionAuthenticatorOutput> instance = builder.build();
    assertThatCode(instance::toString).doesNotThrowAnyException();
}
Also used : UvmEntry(com.webauthn4j.data.extension.UvmEntry) UvmEntries(com.webauthn4j.data.extension.UvmEntries) Test(org.junit.jupiter.api.Test)

Example 3 with UvmEntries

use of com.webauthn4j.data.extension.UvmEntries in project webauthn4j by webauthn4j.

the class AuthenticationExtensionsAuthenticatorOutputsTest method registration_variant_test.

@SuppressWarnings("java:S5961")
@Test
void registration_variant_test() {
    UvmEntries uvm = new UvmEntries(Collections.singletonList(new UvmEntry(UserVerificationMethod.FINGERPRINT_INTERNAL, KeyProtectionType.SOFTWARE, MatcherProtectionType.ON_CHIP)));
    AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration builder = new AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration();
    builder.setUvm(uvm);
    builder.setCredProtect(CredentialProtectionPolicy.USER_VERIFICATION_REQUIRED);
    builder.setHMACCreateSecret(true);
    builder.set("unknown", 1);
    AuthenticationExtensionsAuthenticatorOutputs<RegistrationExtensionAuthenticatorOutput> target = builder.build();
    assertThat(target.getKeys()).containsExactlyInAnyOrder("uvm", "credProtect", "hmac-secret", "unknown");
    assertThat(target.getUvm()).isEqualTo(uvm);
    assertThat(target.getCredProtect()).isEqualTo(CredentialProtectionPolicy.USER_VERIFICATION_REQUIRED);
    assertThat((boolean) target.getHMACSecret()).isTrue();
    assertThat(target.getHMACCreateSecret()).isTrue();
    assertThat(target.getHMACGetSecret()).isNull();
    assertThat(target.getUnknownKeys()).containsExactly("unknown");
    assertThat(target.getValue("uvm")).isEqualTo(uvm);
    assertThat(target.getValue("credProtect")).isEqualTo(CredentialProtectionPolicy.USER_VERIFICATION_REQUIRED);
    assertThat((Boolean) target.getValue("hmac-secret")).isTrue();
    // hmacCreateSecret and hmacGetSecret is not a key of HMACSecretAuthenticationExtensionAuthenticatorInput
    assertThat(target.getValue("hmacCreateSecret")).isNull();
    assertThat(target.getValue("hmacGetSecret")).isNull();
    assertThat(target.getValue("unknown")).isEqualTo(1);
    assertThat(target.getValue("invalid")).isNull();
    assertThat(target.getExtension(UserVerificationMethodExtensionAuthenticatorOutput.class)).isNotNull();
    assertThat(target.getExtension(UserVerificationMethodExtensionAuthenticatorOutput.class).getIdentifier()).isEqualTo("uvm");
    assertThat(target.getExtension(UserVerificationMethodExtensionAuthenticatorOutput.class).getUvm()).isEqualTo(uvm);
    assertThat(target.getExtension(CredentialProtectionExtensionAuthenticatorOutput.class).getCredProtect()).isEqualTo(CredentialProtectionPolicy.USER_VERIFICATION_REQUIRED);
    assertThat(target.getExtension(HMACSecretRegistrationExtensionAuthenticatorOutput.class)).isNotNull();
    assertThat(target.getExtension(HMACSecretRegistrationExtensionAuthenticatorOutput.class).getIdentifier()).isEqualTo("hmac-secret");
    assertThat(target.getExtension(HMACSecretRegistrationExtensionAuthenticatorOutput.class).getValue()).isTrue();
}
Also used : UvmEntry(com.webauthn4j.data.extension.UvmEntry) UvmEntries(com.webauthn4j.data.extension.UvmEntries) Test(org.junit.jupiter.api.Test)

Example 4 with UvmEntries

use of com.webauthn4j.data.extension.UvmEntries in project webauthn4j by webauthn4j.

the class AuthenticatorDataConverterTest method serialize_deserialize_test.

@Test
void serialize_deserialize_test() {
    // Given
    byte[] rpIdHash = new byte[32];
    // noinspection UnnecessaryLocalVariable
    byte flags = BIT_ED;
    AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration builder = new AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration();
    builder.setUvm(new UvmEntries());
    AuthenticatorData<RegistrationExtensionAuthenticatorOutput> authenticatorData = new AuthenticatorData<>(rpIdHash, flags, 0, builder.build());
    // When
    byte[] serialized = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData);
    AuthenticatorData<RegistrationExtensionAuthenticatorOutput> result = new AuthenticatorDataConverter(objectConverter).convert(serialized);
    // Then
    assertThat(result.getRpIdHash()).isNotNull();
    assertThat(result.getRpIdHash()).hasSize(32);
    assertThat(result.getFlags()).isEqualTo(BIT_ED);
    assertThat(result.getSignCount()).isZero();
    assertThat(result.getAttestedCredentialData()).isNull();
    assertThat(result.getExtensions().getKeys()).contains(UserVerificationMethodExtensionAuthenticatorOutput.ID);
}
Also used : AuthenticationExtensionsAuthenticatorOutputs(com.webauthn4j.data.extension.authenticator.AuthenticationExtensionsAuthenticatorOutputs) AuthenticatorData(com.webauthn4j.data.attestation.authenticator.AuthenticatorData) RegistrationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput) UvmEntries(com.webauthn4j.data.extension.UvmEntries) Test(org.junit.jupiter.api.Test)

Example 5 with UvmEntries

use of com.webauthn4j.data.extension.UvmEntries in project webauthn4j by webauthn4j.

the class AuthenticationExtensionsClientOutputsTest method registration_variant_test.

@SuppressWarnings("java:S5961")
@Test
void registration_variant_test() {
    CredentialPropertiesOutput credProps = new CredentialPropertiesOutput(true);
    UvmEntries uvm = new UvmEntries(Collections.singletonList(new UvmEntry(UserVerificationMethod.FINGERPRINT_INTERNAL, KeyProtectionType.SOFTWARE, MatcherProtectionType.ON_CHIP)));
    AuthenticationExtensionsClientOutputs.BuilderForRegistration builder = new AuthenticationExtensionsClientOutputs.BuilderForRegistration();
    builder.setCredProps(credProps);
    builder.setUvm(uvm);
    builder.setHMACCreateSecret(true);
    builder.set("unknown", 1);
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> target = builder.build();
    assertThat(target.getKeys()).containsExactlyInAnyOrder("credProps", "uvm", "hmacCreateSecret", "unknown");
    assertThat(target.getAppid()).isNull();
    assertThat(target.getUvm()).isEqualTo(uvm);
    assertThat(target.getCredProps()).isEqualTo(credProps);
    assertThat(target.getHMACCreateSecret()).isTrue();
    assertThat(target.getHMACGetSecret()).isNull();
    assertThat(target.getValue("unknown")).isEqualTo(1);
    assertThat(target.getUnknownKeys()).containsExactly("unknown");
    assertThat(target.getValue("appid")).isNull();
    assertThat(target.getValue("uvm")).isEqualTo(uvm);
    assertThat(target.getValue("credProps")).isEqualTo(credProps);
    assertThat((Boolean) target.getValue("hmacCreateSecret")).isTrue();
    assertThat(target.getValue("hmacGetSecret")).isNull();
    assertThat(target.getValue("invalid")).isNull();
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class)).isNotNull();
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class).getIdentifier()).isEqualTo("uvm");
    assertThat(target.getExtension(UserVerificationMethodExtensionClientOutput.class).getUvm()).isEqualTo(uvm);
    assertThat(target.getExtension(CredentialPropertiesExtensionClientOutput.class)).isNotNull();
    assertThat(target.getExtension(CredentialPropertiesExtensionClientOutput.class).getIdentifier()).isEqualTo("credProps");
    assertThat(target.getExtension(CredentialPropertiesExtensionClientOutput.class).getCredProps()).isEqualTo(credProps);
    HMACSecretRegistrationExtensionClientOutput hmacSecretRegistrationExtensionClientOutput = target.getExtension(HMACSecretRegistrationExtensionClientOutput.class);
    assertThat(hmacSecretRegistrationExtensionClientOutput).isNotNull();
    assertThat(hmacSecretRegistrationExtensionClientOutput.getIdentifier()).isEqualTo("hmac-secret");
    assertThat(hmacSecretRegistrationExtensionClientOutput.getValue()).isTrue();
    assertThatThrownBy(() -> hmacSecretRegistrationExtensionClientOutput.getValue("hmac-secret")).isInstanceOf(IllegalArgumentException.class);
    assertThat(hmacSecretRegistrationExtensionClientOutput.getValue("hmacCreateSecret")).isTrue();
    assertThatThrownBy(() -> hmacSecretRegistrationExtensionClientOutput.getValue("hmacGetSecret")).isInstanceOf(IllegalArgumentException.class);
}
Also used : UvmEntry(com.webauthn4j.data.extension.UvmEntry) UvmEntries(com.webauthn4j.data.extension.UvmEntries) Test(org.junit.jupiter.api.Test)

Aggregations

UvmEntries (com.webauthn4j.data.extension.UvmEntries)8 Test (org.junit.jupiter.api.Test)8 UvmEntry (com.webauthn4j.data.extension.UvmEntry)7 HMACGetSecretOutput (com.webauthn4j.data.extension.HMACGetSecretOutput)2 AuthenticatorData (com.webauthn4j.data.attestation.authenticator.AuthenticatorData)1 AuthenticationExtensionsAuthenticatorOutputs (com.webauthn4j.data.extension.authenticator.AuthenticationExtensionsAuthenticatorOutputs)1 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)1