ZeroPass / dmrtd

Dart library for reading Biometric Passport
Other
43 stars 19 forks source link

An exception was encountered while trying to read Passport: FormatException: Invalid number (at character 1) #2

Closed SimonVillage closed 2 years ago

SimonVillage commented 2 years ago

I am receiving the following error log when reading a passport. It works with other apps so I assume that it is not an issue with the passport I am using. What could this issue be related to?

Not the full log:

flutter: icc FINE: 2022-02-17 14:18:29.292117: Transceiving to ICC: C-APDU(CLA:00 INS:B0 P1:00 P2:08 Le:256 Lc:0 Data:null)
flutter: mrtd.sm FINE: 2022-02-17 14:18:29.292228: Protecting APDU
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.292453:   header=00b00008
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.292623:   data=null
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.292725:   Le=256
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.292887: masked APDU header=0cb00008
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.293006: Generated data DO=
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.293149: Generated data DO97=970100
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.293304: Generated M=0cb0000880000000970100
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.293693: Generated N=4af8b0801b9fe1eb0cb00008800000009701008000000000
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.293901:   used SSC=4af8b0801b9fe1eb
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.295125: Calculated CC=c2a335e25877dfdd
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.295230: Generated data DO8E=8e08c2a335e25877dfdd
flutter: icc FINE: 2022-02-17 14:18:29.295355: Sending 19 byte(s) to ICC: data='0cb000080d9701008e08c2a335e25877dfdd00'
flutter: icc FINE: 2022-02-17 14:18:29.324454: Received 107 byte(s) from ICC
flutter: icc FINE: 2022-02-17 14:18:29.324789:  data='<..redacted...>93963ad39000'
flutter: mrtd.sm FINE: 2022-02-17 14:18:29.325054: Unprotecting RAPDU: sw=9000 data=<..redacted...>693963ad3
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.329571: Generated K=<..redacted...>2900080
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.330052:   used SSC=4af8b0801b9fe1ec
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.330334: APDU CC=a8a7551693963ad3
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.330453: Calculated CC=a8a7551693963ad3
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.330644: Decrypting data=<..redacted...>2ef5c2
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.337735: Decrypted data=<..redacted...>3c38800000
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.337933: Decrypted data is padded: true
flutter: mrtd.sm FINER: 2022-02-17 14:18:29.338026: Decrypted and upadded data=<..redacted...>3c38
flutter: icc FINE: 2022-02-17 14:18:29.338224: Received response from ICC: sw=9000 data_len=85
flutter: icc FINE: 2022-02-17 14:18:29.338420:  data=<..redacted...>3c3c38
flutter: mrtdeg.app SEVERE: 2022-02-17 14:18:29.339651: An exception was encountered while trying to read Passport: FormatException: Invalid number (at character 1)

^
flutter: nfc.provider FINE: 2022-02-17 14:18:29.340014: Disconnecting
smlu commented 2 years ago

Thank you for reporting this issue! From what I greathearted from above log the problem is the check digit character for optional data which is special character '<' in this case. Could you test the develop branch and see if it fixes your problem?

SimonVillage commented 2 years ago

I can confirm that dev branch works with my German passport.

When trying a Thai passport I am receiving:

flutter: passport FINE: 2022-02-20 11:43:18.051408: Selecting MF
flutter: mrtd.api FINE: 2022-02-20 11:43:18.051810: Selecting MF
[CoreNFC] 00000002 816b5ef0 -[NFCTagReaderSession setAlertMessage:]:90  (null)
flutter: icc FINE: 2022-02-20 11:43:18.052137: Transceiving to ICC: C-APDU(CLA:00 INS:A4 P1:00 P2:0C Le:0 Lc:2 Data:3f00)
flutter: icc FINE: 2022-02-20 11:43:18.053044: Sending 7 byte(s) to ICC: data='00a4000c023f00'
flutter: icc FINE: 2022-02-20 11:43:18.075544: Received 2 byte(s) from ICC
flutter: icc FINE: 2022-02-20 11:43:18.075764:  data='6a86'
flutter: icc FINE: 2022-02-20 11:43:18.075882: Received response from ICC: sw=6A86 data_len=0
flutter: icc FINE: 2022-02-20 11:43:18.076007:  data=null
flutter: mrtdeg.app SEVERE: 2022-02-20 11:43:18.076428: PassportError: Incorrect parameters P1-P2
flutter: nfc.provider FINE: 2022-02-20 11:43:18.076659: Disconnecting
smlu commented 2 years ago

It looks like the Thai passport doesn't support select command for Master File (example app tries to read EF.CardAccess). I made some changes how master file is selected in develop branch. Could you check if dev branch now works with Thai & German passport?

SimonVillage commented 2 years ago

Still the same error. I commented EF.CardAccess and EF.CardSecurity but now I am receiving

flutter: icc FINE: 2022-02-21 13:27:24.793685: Transceiving to ICC: C-APDU(CLA:00 INS:B0 P1:35 P2:45 Le:256 Lc:0 Data:null)
flutter: mrtd.sm FINE: 2022-02-21 13:27:24.793735: Protecting APDU
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793775:   header=00b03545
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793811:   data=null
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793845:   Le=256
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793880: masked APDU header=0cb03545
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793915: Generated data DO=
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793955: Generated data DO97=970100
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793994: Generated M=0cb0354580000000970100
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794047: Generated N=53a98c4dbd45205e0cb03545800000009701008000000000
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794092:   used SSC=53a98c4dbd45205e
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794531: Calculated CC=ec71a3dd9112c00e
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794573: Generated data DO8E=8e08ec71a3dd9112c00e
flutter: icc FINE: 2022-02-21 13:27:24.794623: Sending 19 byte(s) to ICC: data='0cb035450d9701008e08ec71a3dd9112c00e00'
flutter: mrtdeg.app SEVERE: 2022-02-21 13:27:24.795285: An exception was encountered while trying to read Passport: NfcProviderError: PlatformException(500, Communication error, Session invalidated, null)
flutter: nfc.provider FINE: 2022-02-21 13:27:24.795439: Disconnecting

I assume that this error is related to the flutter_nfc_kit lib?

Anyways, I only need MRZ data for now. Do you know if we can also get the passport picture?

smlu commented 2 years ago

Still the same error.

Do you get all this logs when MrtdApi.selectMasterFile is called?

I commented EF.CardAccess and EF.CardSecurity but now I am receiving

flutter: icc FINE: 2022-02-21 13:27:24.793685: Transceiving to ICC: C-APDU(CLA:00 INS:B0 P1:35 P2:45 Le:256 Lc:0 Data:null)
flutter: mrtd.sm FINE: 2022-02-21 13:27:24.793735: Protecting APDU
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793775:   header=00b03545
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793811:   data=null
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793845:   Le=256
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793880: masked APDU header=0cb03545
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793915: Generated data DO=
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793955: Generated data DO97=970100
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.793994: Generated M=0cb0354580000000970100
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794047: Generated N=53a98c4dbd45205e0cb03545800000009701008000000000
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794092:   used SSC=53a98c4dbd45205e
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794531: Calculated CC=ec71a3dd9112c00e
flutter: mrtd.sm FINER: 2022-02-21 13:27:24.794573: Generated data DO8E=8e08ec71a3dd9112c00e
flutter: icc FINE: 2022-02-21 13:27:24.794623: Sending 19 byte(s) to ICC: data='0cb035450d9701008e08ec71a3dd9112c00e00'
flutter: mrtdeg.app SEVERE: 2022-02-21 13:27:24.795285: An exception was encountered while trying to read Passport: NfcProviderError: PlatformException(500, Communication error, Session invalidated, null)
flutter: nfc.provider FINE: 2022-02-21 13:27:24.795439: Disconnecting

I assume that this error is related to the flutter_nfc_kit lib?

Are you reading passport with Android phone? If so, can you try raising transceive timeout. By default timeout is 10 sec. In example app after _nfc is constructed you can set timeout to e.g.: _nfc.timeout = Duration(seconds: 30)

Anyways, I only need MRZ data for now. Do you know if we can also get the passport picture?

The picture is stored in EF.DG2 file on passport. This library for now supports only reading raw bytes of EF.DG2 (i.e. passport.readEfDG2()). Note the image in EF.DG2 is usually stored in jpeg 2000 (JP2) image format. I haven't found any good flutter library yet to support this format.