use of com.webauthn4j.test.authenticator.CredentialCreationResponse 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.test.authenticator.CredentialCreationResponse in project webauthn4j by webauthn4j.
the class ClientPlatform method create.
public PublicKeyCredential<AuthenticatorAttestationResponse, RegistrationExtensionClientOutput> create(PublicKeyCredentialCreationOptions publicKeyCredentialCreationOptions, RegistrationEmulationOption registrationEmulationOption, AttestationOption attestationOption) {
CollectedClientData collectedClientData;
if (registrationEmulationOption.isCollectedClientDataOverrideEnabled()) {
collectedClientData = registrationEmulationOption.getCollectedClientData();
} else {
collectedClientData = createCollectedClientData(ClientDataType.WEBAUTHN_CREATE, publicKeyCredentialCreationOptions.getChallenge());
}
if (authenticatorAdaptor == null) {
throw new NoAuthenticatorSuccessException();
}
CredentialCreationResponse credentialCreationResponse = authenticatorAdaptor.register(publicKeyCredentialCreationOptions, collectedClientData, registrationEmulationOption, attestationOption);
AttestationObject attestationObject = credentialCreationResponse.getAttestationObject();
AttestationStatement attestationStatement = credentialCreationResponse.getAttestationObject().getAttestationStatement();
AttestationConveyancePreference attestationConveyancePreference = publicKeyCredentialCreationOptions.getAttestation();
if (attestationConveyancePreference == null) {
attestationConveyancePreference = AttestationConveyancePreference.NONE;
}
if (AttestationConveyancePreference.DIRECT.equals(attestationConveyancePreference)) {
// nop
} else if (AttestationConveyancePreference.INDIRECT.equals(attestationConveyancePreference)) {
throw new NotImplementedException();
} else if (AttestationConveyancePreference.NONE.equals(attestationConveyancePreference)) {
attestationStatement = new NoneAttestationStatement();
} else {
throw new NotImplementedException();
}
attestationObject = new AttestationObject(attestationObject.getAuthenticatorData(), attestationStatement);
byte[] attestationObjectBytes = attestationObjectConverter.convertToBytes(attestationObject);
byte[] credentialId = credentialCreationResponse.getAttestationObject().getAuthenticatorData().getAttestedCredentialData().getCredentialId();
byte[] collectedClientDataBytes = collectedClientDataConverter.convertToBytes(collectedClientData);
AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> clientExtensions = processRegistrationExtensions(publicKeyCredentialCreationOptions.getExtensions());
return new PublicKeyCredential<>(credentialId, new AuthenticatorAttestationResponse(collectedClientDataBytes, attestationObjectBytes), clientExtensions);
}
Aggregations