use of com.webauthn4j.data.attestation.authenticator.EC2COSEKey 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.authenticator.EC2COSEKey in project webauthn4j by webauthn4j.
the class FIDOU2FAttestationStatementValidator method getSignedData.
private byte[] getSignedData(@NonNull CoreRegistrationObject registrationObject) {
String rpId = registrationObject.getServerProperty().getRpId();
MessageDigest messageDigest = MessageDigestUtil.createSHA256();
AttestationObject attestationObject = registrationObject.getAttestationObject();
// noinspection ConstantConditions as null check is already done in caller
EC2COSEKey credentialPublicKey = (EC2COSEKey) attestationObject.getAuthenticatorData().getAttestedCredentialData().getCOSEKey();
byte[] rpIdBytes = rpId.getBytes(StandardCharsets.UTF_8);
byte[] applicationParameter = messageDigest.digest(rpIdBytes);
byte[] challengeParameter = registrationObject.getClientDataHash();
byte[] keyHandle = attestationObject.getAuthenticatorData().getAttestedCredentialData().getCredentialId();
byte[] userPublicKeyBytes = getPublicKeyBytes(credentialPublicKey);
ByteBuffer byteBuffer = ByteBuffer.allocate(1 + 32 + 32 + keyHandle.length + 65);
// RFU
byteBuffer.put((byte) 0x00);
byteBuffer.put(applicationParameter);
byteBuffer.put(challengeParameter);
byteBuffer.put(keyHandle);
byteBuffer.put(userPublicKeyBytes);
return byteBuffer.array();
}
use of com.webauthn4j.data.attestation.authenticator.EC2COSEKey in project webauthn4j by webauthn4j.
the class CoreRegistrationDataValidatorTest method validateCOSEKey_test.
@Test
void validateCOSEKey_test() {
EC2COSEKey original = EC2COSEKey.create((ECPrivateKey) ECUtil.createKeyPair().getPrivate());
EC2COSEKey ec2COSEKey = new EC2COSEKey(original.getKeyId(), COSEAlgorithmIdentifier.ES256, original.getKeyOps(), original.getCurve(), null, null, original.getD());
assertThatThrownBy(() -> target.validateCOSEKey(ec2COSEKey)).isInstanceOf(ConstraintViolationException.class);
}
Aggregations