Search in sources :

Example 1 with AttestationCertificatePath

use of com.webauthn4j.data.attestation.statement.AttestationCertificatePath in project webauthn4j by webauthn4j.

the class FIDOU2FAuthenticatorAdaptor method register.

@Override
public CredentialCreationResponse register(PublicKeyCredentialCreationOptions publicKeyCredentialCreationOptions, CollectedClientData collectedClientData, RegistrationEmulationOption registrationEmulationOption, AttestationOption attestationOption) {
    String rpId = publicKeyCredentialCreationOptions.getRp().getId();
    byte[] rpIdHash = MessageDigestUtil.createSHA256().digest(rpId.getBytes(StandardCharsets.UTF_8));
    byte[] challengeParameter = MessageDigestUtil.createSHA256().digest(collectedClientDataConverter.convertToBytes(collectedClientData));
    // noinspection UnnecessaryLocalVariable
    byte[] applicationParameter = rpIdHash;
    RegistrationRequest registrationRequest = new RegistrationRequest(challengeParameter, applicationParameter);
    RegistrationResponse registrationResponse = fidoU2FAuthenticator.register(registrationRequest, registrationEmulationOption);
    AttestationStatement attestationStatement = new FIDOU2FAttestationStatement(new AttestationCertificatePath(Collections.singletonList(registrationResponse.getAttestationCertificate())), registrationResponse.getSignature());
    EC2COSEKey ec2CredentialPublicKey = EC2COSEKey.createFromUncompressedECCKey(registrationResponse.getUserPublicKey());
    // zero-filled 16bytes(128bits) array
    AAGUID aaguid = AAGUID.ZERO;
    AttestedCredentialData attestedCredentialData = new AttestedCredentialData(aaguid, registrationResponse.getKeyHandle(), ec2CredentialPublicKey);
    byte flag = BIT_AT | BIT_UP;
    AuthenticatorData<RegistrationExtensionAuthenticatorOutput> authenticatorData = new AuthenticatorData<>(rpIdHash, flag, 0, attestedCredentialData);
    AttestationObject attestationObject = new AttestationObject(authenticatorData, attestationStatement);
    return new CredentialCreationResponse(attestationObject);
}
Also used : AttestationCertificatePath(com.webauthn4j.data.attestation.statement.AttestationCertificatePath) AAGUID(com.webauthn4j.data.attestation.authenticator.AAGUID) RegistrationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput) AttestedCredentialData(com.webauthn4j.data.attestation.authenticator.AttestedCredentialData) AuthenticatorData(com.webauthn4j.data.attestation.authenticator.AuthenticatorData) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) FIDOU2FAttestationStatement(com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement) AttestationStatement(com.webauthn4j.data.attestation.statement.AttestationStatement) FIDOU2FAttestationStatement(com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement) EC2COSEKey(com.webauthn4j.data.attestation.authenticator.EC2COSEKey) CredentialCreationResponse(com.webauthn4j.test.authenticator.CredentialCreationResponse)

Example 2 with AttestationCertificatePath

use of com.webauthn4j.data.attestation.statement.AttestationCertificatePath in project webauthn4j by webauthn4j.

the class FIDOU2FAttestationStatementValidatorTest method validateAttestationStatement_test.

@Test
void validateAttestationStatement_test() {
    FIDOU2FAttestationStatement attestationStatement = mock(FIDOU2FAttestationStatement.class);
    when(attestationStatement.getX5c()).thenReturn(new AttestationCertificatePath(Arrays.asList(TestAttestationUtil.load3tierTestAuthenticatorAttestationCertificate(), TestAttestationUtil.load3tierTestIntermediateCACertificate())));
    assertThrows(BadAttestationStatementException.class, () -> target.validateAttestationStatement(attestationStatement));
}
Also used : AttestationCertificatePath(com.webauthn4j.data.attestation.statement.AttestationCertificatePath) FIDOU2FAttestationStatement(com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement) Test(org.junit.jupiter.api.Test)

Example 3 with AttestationCertificatePath

use of com.webauthn4j.data.attestation.statement.AttestationCertificatePath in project webauthn4j by webauthn4j.

the class DefaultCertPathTrustworthinessValidatorTest method validate_full_chain_test.

@Test
void validate_full_chain_test() {
    Set<TrustAnchor> trustAnchors = CertificateUtil.generateTrustAnchors(Collections.singletonList(TestAttestationUtil.load3tierTestRootCACertificate()));
    when(trustAnchorRepository.find(aaguid)).thenReturn(trustAnchors);
    AttestationCertificatePath attestationCertificatePath = new AttestationCertificatePath(Arrays.asList(TestAttestationUtil.load3tierTestAuthenticatorAttestationCertificate(), TestAttestationUtil.load3tierTestIntermediateCACertificate(), TestAttestationUtil.load3tierTestRootCACertificate()));
    CertificateBaseAttestationStatement attestationStatement = TestAttestationStatementUtil.createBasicPackedAttestationStatement(attestationCertificatePath);
    target.setFullChainProhibited(true);
    assertThrows(CertificateException.class, () -> target.validate(aaguid, attestationStatement));
}
Also used : CertificateBaseAttestationStatement(com.webauthn4j.data.attestation.statement.CertificateBaseAttestationStatement) AttestationCertificatePath(com.webauthn4j.data.attestation.statement.AttestationCertificatePath) TrustAnchor(java.security.cert.TrustAnchor) Test(org.junit.jupiter.api.Test)

Example 4 with AttestationCertificatePath

use of com.webauthn4j.data.attestation.statement.AttestationCertificatePath in project webauthn4j by webauthn4j.

the class TrustAnchorCertPathTrustworthinessValidatorTest method validate_full_chain_test.

@Test
void validate_full_chain_test() {
    Set<TrustAnchor> trustAnchors = CertificateUtil.generateTrustAnchors(Collections.singletonList(TestAttestationUtil.load3tierTestRootCACertificate()));
    when(trustAnchorsResolver.resolve(aaguid)).thenReturn(trustAnchors);
    AttestationCertificatePath attestationCertificatePath = new AttestationCertificatePath(Arrays.asList(TestAttestationUtil.load3tierTestAuthenticatorAttestationCertificate(), TestAttestationUtil.load3tierTestIntermediateCACertificate(), TestAttestationUtil.load3tierTestRootCACertificate()));
    CertificateBaseAttestationStatement attestationStatement = TestAttestationStatementUtil.createFIDOU2FAttestationStatement(attestationCertificatePath);
    target.setFullChainProhibited(true);
    assertThrows(CertificateException.class, () -> target.validate(aaguid, attestationStatement));
}
Also used : CertificateBaseAttestationStatement(com.webauthn4j.data.attestation.statement.CertificateBaseAttestationStatement) AttestationCertificatePath(com.webauthn4j.data.attestation.statement.AttestationCertificatePath) TrustAnchor(java.security.cert.TrustAnchor) Test(org.junit.jupiter.api.Test)

Example 5 with AttestationCertificatePath

use of com.webauthn4j.data.attestation.statement.AttestationCertificatePath in project webauthn4j by webauthn4j.

the class PackedAttestationStatementValidatorTest method validateAttestationStatementNotNull_test.

@Test
void validateAttestationStatementNotNull_test() {
    PackedAttestationStatement attestationStatement = new PackedAttestationStatement(COSEAlgorithmIdentifier.ES256, new byte[32], new AttestationCertificatePath());
    target.validateAttestationStatementNotNull(attestationStatement);
}
Also used : PackedAttestationStatement(com.webauthn4j.data.attestation.statement.PackedAttestationStatement) AttestationCertificatePath(com.webauthn4j.data.attestation.statement.AttestationCertificatePath) Test(org.junit.jupiter.api.Test)

Aggregations

AttestationCertificatePath (com.webauthn4j.data.attestation.statement.AttestationCertificatePath)17 Test (org.junit.jupiter.api.Test)12 AndroidKeyAttestationStatement (com.webauthn4j.data.attestation.statement.AndroidKeyAttestationStatement)3 FIDOU2FAttestationStatement (com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement)3 PackedAttestationStatement (com.webauthn4j.data.attestation.statement.PackedAttestationStatement)3 X509Certificate (java.security.cert.X509Certificate)3 AppleAppAttestAttestationStatement (com.webauthn4j.appattest.data.attestation.statement.AppleAppAttestAttestationStatement)2 AttestationObject (com.webauthn4j.data.attestation.AttestationObject)2 CertificateBaseAttestationStatement (com.webauthn4j.data.attestation.statement.CertificateBaseAttestationStatement)2 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)2 TrustAnchor (java.security.cert.TrustAnchor)2 AAGUID (com.webauthn4j.data.attestation.authenticator.AAGUID)1 AttestedCredentialData (com.webauthn4j.data.attestation.authenticator.AttestedCredentialData)1 AuthenticatorData (com.webauthn4j.data.attestation.authenticator.AuthenticatorData)1 EC2COSEKey (com.webauthn4j.data.attestation.authenticator.EC2COSEKey)1 AttestationStatement (com.webauthn4j.data.attestation.statement.AttestationStatement)1 CredentialCreationResponse (com.webauthn4j.test.authenticator.CredentialCreationResponse)1 UnexpectedCheckedException (com.webauthn4j.util.exception.UnexpectedCheckedException)1 RegistrationObject (com.webauthn4j.validator.RegistrationObject)1 BigInteger (java.math.BigInteger)1