microg / GmsCore

Free implementation of Play Services
https://microg.org
Apache License 2.0
8.08k stars 1.67k forks source link

Consider using chained APDUs instead of extended APDUs for CTAP2/NFC #1809

Open StarGate01 opened 1 year ago

StarGate01 commented 1 year ago

The CTAP2 transport specification for NFC allows two different encodings for long (fragmented) requests and responses: https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#nfc-fragmentation .

Extended APDUs are simpler to implement, however not all hardware (smartphones) supports these very large (~1KB) commands, some chipsets (e.g NXP PN532) are limited to 255 bytes. See also https://github.com/DangerousThings/flexsecure-applets/blob/master/docs/4-android.md#maximum-nfc-transceive-length , https://github.com/NXPNFCLinux/linux_libnfc-nci/issues/116 .

I suggest checking the chipset capabilities using IsoDep.getMaxTransceiveLength (https://developer.android.com/reference/android/nfc/tech/IsoDep#getMaxTransceiveLength()) before attemting so send extended APDUs, and fall back to chained APDUs otherwise.

mar-v-in commented 1 year ago

Makes sense. To keep the first implementation easy, there are a few shortcuts here and there, including the lack of support for fragmentation.