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