flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

NFC - Machine Readable Travel Documents

Open qistoph opened this issue 3 years ago • 38 comments

Maybe not quite a finished PR yet. I'm looking for some feedback to make sure I'm going in the right direction.

Especially with the new FAP's, I can see you might prefer this to be an external application (FAP). On the other hand, maybe you're looking to support more and more NFC cards with the base firmware.

Please let me know your thoughts and any feedback on the code.

What's new

  • Read some basic info from Machine Readable Travel Documents (spec. ICAO9303)
  • Support Basic Access Authentication

Verification

  • Start NFC reader
  • Offer an MRTD to the reader
  • Perform the Auth step

TODO

  • [ ] PACE authentication
  • [x] Indicate used authentication (BAC / PACE)
  • [ ] Card Access Number access
  • [ ] Active Authentication
  • [ ] Passive Authentication (maybe even against ICAO Master List)
  • [ ] Dump (selected) files (for external usage)
  • [ ] Save (as much info as possible)
  • [ ] Emulate (as much as possible) a saved MRTD
  • [x] Support NFC-B MRTDs
  • [x] Move helper files to helper folder
  • [ ] Determine size of files from header, instead of reading till end
  • [ ] Remove some testing/debug statements and logging
  • [ ] Show information about LDSv2 apps
  • [x] Save/Load authentication parameters

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

qistoph avatar Oct 11 '22 20:10 qistoph

Would it be possible to add support for NFC-B EMRTDs? Also there is a compilation error right now (I think a few string-related functions were changed in dev).

Semptum avatar Oct 11 '22 20:10 Semptum

Theoretically, yes NFC-B is possible. However I don't have a card to test and verify anything.

Oops, I forgot the remove some testing strings. Additional commit should be available tomorrow. From the top of my head, any lines using the missing strings could be removed.

qistoph avatar Oct 11 '22 21:10 qistoph

I wonder if showing the ATS might be more interesting than ATQA/SAK? It might allow to determine the country even if the user does not wish to authenticate. Also if the auth fails perhaps it tell that to the user, otherwise it just loops back.

Semptum avatar Oct 12 '22 11:10 Semptum

Thanks for your suggestions. I'm not really an NFC guy, so I'm curious to learn more about the ATS details and will look into that.

The authentication failed feedback is indeed one of the open TODOs. There is quite a lot more that's on my mind. I'll add these to the description.

qistoph avatar Oct 12 '22 15:10 qistoph

Hello @qistoph ! Great work! We are looking for some suitable travel documents to test your PR and come back with feedback

gornekich avatar Oct 14 '22 09:10 gornekich

Have you tried to recognize driving licenses as well? They should obey ISO/IEC FCD 18013-2 and the AID should be A0 00 00 02 48 and the PIX should be 02 00. I asked someone on telegram with a NL driving license to test this out but no luck, perhaps the PIX was chosen different. Screenshot_20221015_162824 Screenshot_20221015_162441

Not sure if this falls under the category of MRTDs but it might be interesting to add it (unfortunately in my country they stopped producing licenses with chips so I can't test anything).

Semptum avatar Oct 15 '22 14:10 Semptum

My documents are either NFC-A (PACE) or NFC-B (BAC), so will be glad to test when/if those are implemented

oleksiikutuzov avatar Oct 15 '22 15:10 oleksiikutuzov

It looks to me like some of the code implemented in mrtd parts is actually iso7816-related. For example, the mrtd_select_app seems to me just like sending a classic iso7816 SELECT (by AID) APDU. Is that so?

I'm just asking cause if that's the case, carving out such code to an encapsulated iso7816 library could allow it to be better reused for other iso7816 cards. (I've been meaning to attempt to write some code for an iso7816 card myself)

jagotu avatar Oct 16 '22 20:10 jagotu

Have you tried to recognize driving licenses as well? They should obey ISO/IEC FCD 18013-2 and the AID should be A0 00 00 02 48 and the PIX should be 02 00. I asked someone on telegram with a NL driving license to test this out but no luck, perhaps the PIX was chosen different.

I am focussing on reading Machine Readable Travel Documents as specified by ICAO9303. Driver license is not one of them. My Dutch (NL) driver's license doesn't have an NFC chip, so I probably won't be including it in the future either.

My documents are either NFC-A (PACE) or NFC-B (BAC), so will be glad to test when/if those are implemented

Thanks, @oleksiikutuzov! If either is implemented I'll let you know.

It looks to me like some of the code implemented in mrtd parts is actually iso7816-related. For example, the mrtd_select_app seems to me just like sending a classic iso7816 SELECT (by AID) APDU. Is that so?

I'm just asking cause if that's the case, carving out such code to an encapsulated iso7816 library could allow it to be better reused for other iso7816 cards. (I've been meaning to attempt to write some code for an iso7816 card myself)

I noticed and realized this too. Some methods were already explicitly put into iso7816.c. There are of course many more. Even the already implemented EMV is actually using some ISO7816 commands.

qistoph avatar Oct 17 '22 09:10 qistoph

I think there is a bug, someone whose non passport card replies 6A82 to the request 00 A4 04 0C 07 A0 00 00 02 47 10 01 has it recognized as a passport. It's from an unofficial firmware that I think pulled your PR

Semptum avatar Oct 24 '22 14:10 Semptum

I think there is a bug, someone whose non passport card replies 6A82 to the request 00 A4 04 0C 07 A0 00 00 02 47 10 01 has it recognized as a passport. It's from an unofficial firmware that I think pulled your PR

I'm afraid you're correct about that. I was working on the implementation and am using the mrtd_test() function for that. The call however doesn't use a return value to confirm an MRTD was present. I'll try to fix it this week.

Could you, afterwards, inform the maintainers of that fork to update?

qistoph avatar Oct 24 '22 15:10 qistoph

I'm afraid you're correct about that. I was working on the implementation and am using the mrtd_test() function for that. The call however doesn't use a return value to confirm an MRTD was present. I'll try to fix it this week.

Could you, afterwards, inform the maintainers of that fork to update?

Ok, that's what I thought when looking at the code, thanks for confirming. I'm not sure which fork that is but I'll contact the person who encountered the problem.

Semptum avatar Oct 24 '22 15:10 Semptum

@gornekich still need your review

skotopes avatar Oct 28 '22 16:10 skotopes

When testing with a Slovenian passport, I get a MemManage restart.

craftbyte avatar Nov 08 '22 14:11 craftbyte

When testing with a Slovenian passport, I get a MemManage restart.

@craftbyte, would you be able to share some logging and debugging details with me? You can reach me at [my username]@gmail.com

qistoph avatar Nov 08 '22 15:11 qistoph

<3

ivorsmorenburg avatar Nov 10 '22 09:11 ivorsmorenburg

Just to inform, Brazilian passports work flawlessly, I've tested 5 different and all worked as expected, awesome job @qistoph !

soter19 avatar Nov 11 '22 15:11 soter19

While I was testing with Russian international passport, no data from EF_DG1 were extracted I will look into it and maybe send you a patch to fix it

ezhevita avatar Nov 20 '22 15:11 ezhevita

Log fragment:

66841725 [D][Mrtd] Read and parse COM (011E)
66841728 [D][Mrtd] Send select EF: COM (0x011E)
DES add: ***
DES buf: ***
DES add: ***
DES buf: ***
MAC: ***
DES add: ***
DES buf: ***
66841772 [D][Mrtd] Selected COM
66841774 [D][Mrtd] Read binary, offset: 0
DES add: ***
DES buf: ***
DES buf: ***
MAC: ***
66841808 [I][Mrtd] APDU answer is not 0x9000, but 0x6B00
66841810 [E][Mrtd] Failed to read
66841812 [E][Mrtd] Could not read COM
66841814 [D][Mrtd] Read and parse DG1 (0101)
66841817 [D][Mrtd] Send select EF: DG1 (0x0101)
DES add: ***
DES buf: ***
DES add: ***
DES buf: ***
MAC: ***
66841846 [I][Mrtd] APDU answer is not 0x9000, but 0x6988
66841848 [I][Mrtd] 'secure messaging data objects are incorrect'
66841851 [E][Mrtd] Failed select EF 0x0101
66841853 [E][Mrtd] Could not select DG1
66841876 [D][NFC] Read passport, auth: 1, success: 1

ezhevita avatar Nov 20 '22 16:11 ezhevita

Hi ;-) Looks like it make sense to move this feature into separate application, doesn't it?

I'll switch this PR to Draft, un-draft it when ready.

skotopes avatar Dec 10 '22 20:12 skotopes

Hi ;-) Looks like it make sense to move this feature into separate application, doesn't it?

I'll switch this PR to Draft, un-draft it when ready.

Maybe decoding yes but I'd argue it makes sense to at least detect mrtds in stock firmware.

Semptum avatar Dec 10 '22 20:12 Semptum

@gornekich what do you think?

skotopes avatar Dec 10 '22 20:12 skotopes

wow good job

Llama-Master avatar Jan 12 '23 02:01 Llama-Master

Hey! Fantastic job! Need any help?

pawisoon avatar Jan 30 '23 13:01 pawisoon

Thanks @pawisoon!

I was really hoping to have this included in the firmware. The suggestion to convert into an app is a bit of a disappointment.

If anyone is willing to help me get that started, I'm willing to reconsider working on it.

qistoph avatar Jan 30 '23 13:01 qistoph

@qistoph is there a limitation to what travel passports can be read? When I try to authenticate US passport flipper crashes with furi_check error.

skynet01 avatar Mar 11 '23 20:03 skynet01

@qistoph is there a limitation to what travel passports can be read? When I try to authenticate US passport flipper crashes with furi_check error.

You need to do BAC/PACE access control - based on DoE, DoB and document number in order to access Chip data. You can read everything whats present on data page + high resolution photo + sometimes some optional data is present (see ICAO 9303).

The fingerprints are not readable by regular users in any passports, need a cert that only country officials have access to. Most agencies won't even do this themselves due to the complexity and cost of reading them from the chip.

pawisoon avatar Mar 11 '23 20:03 pawisoon

@qistoph is there a limitation to what travel passports can be read? When I try to authenticate US passport flipper crashes with furi_check error.

Sorry to reply again. Have you checked your DoE, DoB and document number correctness? Im not sure but maybe you are holding some newest model of US passport(post 2020) that migth be PACE only. You could verify this with a passport reader e.g. https://apps.apple.com/us/app/readid-me/id1463949991 After you read NFC using the above app, in result screen, go to security tab and see value of "Type of access control". You can also see what features chip supports above it.

pawisoon avatar Mar 11 '23 21:03 pawisoon

I tried different access types (BAC and Any). If I mistype any of the fields on purpose I get the can't authenticate error. My passport is before 2020. I tried it with 2 different passports that are both US and have the same issues on both of them.

skynet01 avatar Mar 11 '23 21:03 skynet01

I tried different access types (BAC and Any). If I mistype any of the fields on purpose I get the can't authenticate error. My passport is before 2020. I tried it with 2 different passports that are both US and have the same issues on both of them.

Maybe its the implementation issue specific to US passport. Is the passport reader app I linked working with your document? Making sure NFC chip is intact and working.

pawisoon avatar Mar 11 '23 21:03 pawisoon