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