Search in sources :

Example 1 with COSEKeyEnvelope

use of com.webauthn4j.converter.jackson.deserializer.cbor.COSEKeyEnvelope in project webauthn4j by webauthn4j.

the class AttestedCredentialDataConverter method convert.

@NonNull
public AttestedCredentialData convert(@NonNull ByteBuffer attestedCredentialData) {
    try {
        AssertUtil.notNull(attestedCredentialData, ATTESTED_CREDENTIAL_DATA_MUST_NOT_BE_NULL);
        byte[] aaguidBytes = new byte[AAGUID_LENGTH];
        attestedCredentialData.get(aaguidBytes, 0, AAGUID_LENGTH);
        AAGUID aaguid = new AAGUID(aaguidBytes);
        int length = UnsignedNumberUtil.getUnsignedShort(attestedCredentialData);
        byte[] credentialId = new byte[length];
        attestedCredentialData.get(credentialId, 0, length);
        byte[] remaining = new byte[attestedCredentialData.remaining()];
        attestedCredentialData.get(remaining);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(remaining);
        COSEKeyEnvelope coseKeyEnvelope = convertToCredentialPublicKey(byteArrayInputStream);
        COSEKey coseKey = coseKeyEnvelope.getCOSEKey();
        assertCoseKey(coseKey);
        AttestedCredentialData result = createAttestedCredentialData(aaguid, credentialId, coseKey);
        int extensionsBufferLength = remaining.length - coseKeyEnvelope.getLength();
        attestedCredentialData.position(attestedCredentialData.position() - extensionsBufferLength);
        return result;
    } catch (IllegalArgumentException e) {
        throw new DataConversionException(e);
    }
}
Also used : AttestedCredentialData(com.webauthn4j.data.attestation.authenticator.AttestedCredentialData) COSEKey(com.webauthn4j.data.attestation.authenticator.COSEKey) COSEKeyEnvelope(com.webauthn4j.converter.jackson.deserializer.cbor.COSEKeyEnvelope) AAGUID(com.webauthn4j.data.attestation.authenticator.AAGUID) DataConversionException(com.webauthn4j.converter.exception.DataConversionException) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 2 with COSEKeyEnvelope

use of com.webauthn4j.converter.jackson.deserializer.cbor.COSEKeyEnvelope in project webauthn4j by webauthn4j.

the class AuthenticatorDataConverter method extractAttestedCredentialData.

/**
 * Extract attestedCredData byte array from a authenticatorData byte array.
 *
 * @param authenticatorData the authenticatorData byte array
 * @return the extracted attestedCredData byte array
 */
@NonNull
public byte[] extractAttestedCredentialData(@NonNull byte[] authenticatorData) {
    byte[] lengthBytes = Arrays.copyOfRange(authenticatorData, L_INDEX, CREDENTIAL_ID_INDEX);
    int credentialIdLength = UnsignedNumberUtil.getUnsignedShort(lengthBytes);
    int credentialPublicKeyIndex = CREDENTIAL_ID_INDEX + credentialIdLength;
    byte[] attestedCredentialDataBytes = Arrays.copyOfRange(authenticatorData, credentialPublicKeyIndex, authenticatorData.length);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(attestedCredentialDataBytes);
    COSEKeyEnvelope coseKeyEnvelope = attestedCredentialDataConverter.convertToCredentialPublicKey(byteArrayInputStream);
    int credentialPublicKeyLength = coseKeyEnvelope.getLength();
    int attestedCredentialDataLength = AAGUID_LENGTH + L_LENGTH + credentialIdLength + credentialPublicKeyLength;
    return Arrays.copyOfRange(authenticatorData, ATTESTED_CREDENTIAL_DATA_INDEX, ATTESTED_CREDENTIAL_DATA_INDEX + attestedCredentialDataLength);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) COSEKeyEnvelope(com.webauthn4j.converter.jackson.deserializer.cbor.COSEKeyEnvelope) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

COSEKeyEnvelope (com.webauthn4j.converter.jackson.deserializer.cbor.COSEKeyEnvelope)2 NonNull (org.checkerframework.checker.nullness.qual.NonNull)2 DataConversionException (com.webauthn4j.converter.exception.DataConversionException)1 AAGUID (com.webauthn4j.data.attestation.authenticator.AAGUID)1 AttestedCredentialData (com.webauthn4j.data.attestation.authenticator.AttestedCredentialData)1 COSEKey (com.webauthn4j.data.attestation.authenticator.COSEKey)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1