Search in sources :

Example 1 with CredentialCreationResponse

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

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);
}
Also used : NotImplementedException(com.webauthn4j.util.exception.NotImplementedException) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) NoneAttestationStatement(com.webauthn4j.data.attestation.statement.NoneAttestationStatement) NoneAttestationStatement(com.webauthn4j.data.attestation.statement.NoneAttestationStatement) AttestationStatement(com.webauthn4j.data.attestation.statement.AttestationStatement) CredentialCreationResponse(com.webauthn4j.test.authenticator.CredentialCreationResponse)

Aggregations

AttestationObject (com.webauthn4j.data.attestation.AttestationObject)2 AttestationStatement (com.webauthn4j.data.attestation.statement.AttestationStatement)2 CredentialCreationResponse (com.webauthn4j.test.authenticator.CredentialCreationResponse)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 AttestationCertificatePath (com.webauthn4j.data.attestation.statement.AttestationCertificatePath)1 FIDOU2FAttestationStatement (com.webauthn4j.data.attestation.statement.FIDOU2FAttestationStatement)1 NoneAttestationStatement (com.webauthn4j.data.attestation.statement.NoneAttestationStatement)1 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)1 NotImplementedException (com.webauthn4j.util.exception.NotImplementedException)1