Giter Club home page Giter Club logo

nfcpassportreader's Introduction

NFCPassportReader

This package handles reading an NFC Enabled passport using iOS 13 CoreNFC APIS

Version 2 (and the main branch) now uses Swift Async/Await for communication. If you need an earlier version, please use 1.1.9 or below!

Supported features:

  • Basic Access Control (BAC)
  • Secure Messaging
  • Reads DG1 (MRZ data) and DG2 (Image) in both JPEG and JPEG2000 formats, DG7, DG11, DG12, DG14 and DG15 (also SOD and COM datagroups)
  • Passive Authentication
  • Active Authentication
  • Chip Authentication (ECDH DES and AES keys tested, DH DES AES keys implemented ad should work but currently not tested)
  • PACE - currently only Generic Mapping (GM) supported
  • Ability to dump passport stream and read it back in
  • Uses Async/Await

This is still very early days - the code is by no means perfect and there are still some rough edges - there ARE most definitely bugs and I'm sure I'm not doing things perfectly.

It reads and verifies my passport (and others I've been able to test) fine, however your mileage may vary.

Installation

Swift Package Manager (recommended)

NFCPassportReader may be installed via Swift Package Manager, by pointing to this repo's URL.

CocoaPods (deprecated and unsupported)

Install using CocoaPods by adding this line to your Podfile:

use_frameworks!
pod 'NFCPassportReader', git:'https://github.com/AndyQ/NFCPassportReader.git'  

Then, run the following command:

$ pod install

Note - ** Don't use Bitcode ** - its not supported by this and has been deprecated by Apple

Usage

To use, you first need to create the Passport MRZ Key which consists of the passport number, date of birth and expiry date (including the checksums). Dates are in YYMMDD format

For example:

<passport number><passport number checksum><date of birth><date of birth checksum><expiry date><expiry date checksum>

e.g. for Passport nr 12345678, Date of birth 27-Jan-1998, Expiry 30-Aug-2025 the MRZ Key would be:

Passport number - 12345678
Passport number checksum - 8
Date Of birth - 980127
Date of birth checksum - 7
Expiry date - 250831
Expiry date checksum - 5

mrzKey = "12345678898012772508315"

Then on an instance of PassportReader, call the readPassport method passing in the mrzKey, the datagroups to read and a completion block.
e.g.

passportReader.readPassport(mrzKey: mrzKey, tags: [.COM, .DG1, .DG2], completed: { (error) in
   ...
}

Currently the datagroups supported are: COM, DG1, DG2, DG7, DG11, DG12, DG14 (partial), DG15, and SOD

This will then handle the reading of the passport, and image and will call the completion block either with an TagError error if there was an error of some kind, or nil if successful.

If successful, the passportReader object will then contain valid data for the passportMRZ and passportImage fields. Note - JPEG2000 images are currently unsupported - access to the raw data is available if you need to implement support for those.

In addition, you can customise the messages displayed in the NFC Session Reader by providing a customDisplayMessage callback e.g. to override just the initial request to present passport message:

passportReader.readPassport(mrzKey: mrzKey, tags: [.COM, .DG1, .DG2],
    customDisplayMessage: { (displayMessage) in
        switch displayMessage {
            case .requestPresentPassport:
                return "Hold your iPhone near an NFC enabled passport."
            default: 
                return nil
    }, completed: { (error) in
        ...
}

Logging

Additional logging (very verbose) can be enabled on the PassportReader by passing in a log level on creation: e.g.

let reader = PassportReader(logLevel: .debug)

NOTE - currently this is just printing out to the console - I'd like to implement better logging later - probably using SwiftyBeaver

PassiveAuthentication

Passive Authentication is now part of the main library and can be used to ensure that an E-Passport is valid and hasn't been tampered with.

It requires a set of CSCA certificates in PEM format from a master list (either from a country that publishes their master list, or the ICAO PKD repository). See the scripts folder for details on how to get and create this file.

The masterList.pem file included in the Sample app is purely there to ensure no compiler warnings and contains only a single PEM file that was self-generated and won't be able to verify anything!

Sample app

There is a sample app included in the repo which demonstrates the functionality.

Troubleshooting

  • If when doing the initial Mutual Authenticate challenge, you get an error with and SW1 code 0x63, SW2 code 0x00, reason: No information given, then this is usualy because your MRZ key is incorrect, and possibly because your passport number is not quite right. If your passport number in the MRZ contains a '<' then you need to include this in the MRZKey - the checksum should work out correct too. For more details, check out App-D2 in the ICAO 9303 Part 11 document (https://www.icao.int/publications/Documents/9303_p11_cons_en.pdf)

    e.g. if the bottom line on the MRZ looks like: 12345678<8AUT7005233M2507237<<<<<<<<<<<<<<06

    In this case the passport number is 12345678 but is padded out with an additonal <. This needs to be included in the MRZ key used for BAC. e.g. 12345678<870052332507237 would be the key used.

To do

There are a number of things I'd like to implement in no particular order:

  • Finish off PACE authentication (IM and CAM)

Thanks

I'd like to thank the writers of pypassport (Jean-Francois Houzard and Olivier Roger - can't find their website but referenced from https://github.com/andrew867/epassportviewer) who's work this is based on.

The EPassport section on YobiWiki (http://wiki.yobi.be/wiki/EPassport) This has been an invaluable resource especially around Passive Authentication.

Marcin Krzyżanowski for his OpenSSL-Universal repo.

nfcpassportreader's People

Contributors

andyq avatar christiannorbertbraun avatar danydev avatar haydarkarkin avatar jakub-vallo avatar jakubdolejs avatar jusstas avatar markus-mohemian avatar nmccann avatar petteri-huusko-op avatar pmitche avatar ruudk avatar tlon1 avatar wood1k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nfcpassportreader's Issues

Tag connection Lost

The passport is italian and when i try to scan it i receive this error:
xcode: 11.0
device IPhone 7 (ios 13.1)

tagReaderSessionDidBecomeActive
tagReaderSession:didDetect - iso7816(<NFCISO7816Tag: 0x2815545a0>)
2019-10-01 13:42:36.797989+0200 NFCPassportReaderApp[3356:752688] [CoreNFC] 00000002 835cd200 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Calculate the SHA-1 hash of MRZ_information
Hsha1(MRZ_information): 94DABEBC97DA3236463B7FF71ADD120253FCAD34
Take the most significant 16 bytes to form the Kseed
Kseed: 94DABEBC97DA3236463B7FF71ADD1202
Calculate the Basic Acces Keys (Kenc and Kmac) using Appendix 5.1
Compute Encryption key (c: 00000001
Concatenate Kseed and c
D: 94DABEBC97DA3236463B7FF71ADD120200000001
Calculate the SHA-1 hash of D
Hsha1(D): 8D15C29688D0D5EDAF2DB94307B47A5706C874C9
Form keys Ka and Kb
Ka: 8D15C29688D0D5ED
Kb: AF2DB94307B47A57
Adjust parity bits
Ka: 8C15C29789D0D5EC
Kb: AE2CB94307B57A57
Compute MAC Computation key (c: 00000002
Concatenate Kseed and c
D: 94DABEBC97DA3236463B7FF71ADD120200000002
Calculate the SHA-1 hash of D
Hsha1(D): 7F6F3B84ACF542303C1E93784FEE5082EA0B8BE1
Form keys Ka and Kb
Ka: 7F6F3B84ACF54230
Kb: 3C1E93784FEE5082
Adjust parity bits
Ka: 7F6E3B85ADF44331
Kb: 3D1F92794FEF5183
2019-10-01 13:42:37.207573+0200 NFCPassportReaderApp[3356:752688] [CoreNFC] 00000002 835cd200 -[NFCTagReaderSession transceive:tagUpdate:error:]:726 Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}
Error reading tag - Tag connection lost

About OpenSSL

Hi @AndyQ. I want to use the basic details from the passport like Photo, name, DOB, Address etc. I don't want to use X.509 certificate. So, If I don't want to use x.509 certificate after that also I need to use OpenSSL for fetching the Image or no need.
If yes then how can you I use Open SSL through cocoapods? Because when I install the pod 'OpenSSL-Universal' then also I am unable to Import the OpenSSL Module. Is there any need to make a bridge header too. Can you please explain little more?
Thanks in advance.

NFC passport scan

I am getting this error while scanning a US passport. It gets read by other NFC scan apps. Can you guide me please?

2020-02-13 15:19:57.248987+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:57.364957+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - COM
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:57.375848+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:57.493178+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - COM
2020-02-13 15:19:57.520187+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
2020-02-13 15:19:57.537983+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
DG Found - ["DG1", "DG2", "DG11", "DG12"]
Reading tag - SOD
2020-02-13 15:19:57.566349+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:57.574000+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:57.700107+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:57.746153+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:57.757292+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:57.888485+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:57.926971+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:57.937910+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.058225+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:58.090904+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:58.104587+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.231395+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:58.265572+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:58.278917+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.408888+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:58.449162+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:58.462672+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.592511+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:58.632989+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:58.646445+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.778940+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:58.821636+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:58.832487+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:58.972073+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:59.009567+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:59.018347+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:59.141294+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:59.154674+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-13 15:19:59.280097+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Reading tag - SOD
2020-02-13 15:19:59.322133+0530 Smart Path™[1133:378176] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-13 15:19:59.334274+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession setAlertMessage:]:92 (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
2020-02-13 15:20:00.604755+0530 Smart Path™[1133:378337] [CoreNFC] 00000002 81daf300 -[NFCTagReaderSession transceive:tagUpdate:error:]:735 Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}
Error reading tag - Tag connection lost
BAC Failed
Error

SM data objects incorrect / Wrong length

Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
got resp - ResponseAPDU(data: [95, 1, 4, 48, 49, 48, 55, 95, 54, 6, 48, 52, 48, 48, 48, 48, 92, 6, 97, 117, 103, 107, 108, 109], sw1: 144, sw2: 0)
DG Found - ["DG1", "DG2", "DG7", "DG11", "DG12", "DG13"]
Reading tag - SOD
Error reading tag: sw1 - 6C, sw2 - 0E - reason: Wrong length Le: SW2 indicates the exact length - (exact length :14)
ERROR - Wrong length Le: SW2 indicates the exact length - (exact length :14)
Reading tag - SOD
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
ERROR - SM data objects incorrect

then

Starting Basic Access Control (BAC)
BAC Successful
Reading tag - SOD
Error reading tag: sw1 - 6C, sw2 - 0E - reason: Wrong length Le: SW2 indicates the exact length - (exact length :14)
ERROR - Wrong length Le: SW2 indicates the exact length - (exact length :14)
Reading tag - SOD
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
ERROR - SM data objects incorrect

repeats endlessly till the session expired

Affected version: 1.0.4
Document: ID card from Kazakhstan

Fix the issue

adding self.tagReader?.reduceDataReadingAmount() inside the condition

} else if errMsg == "SM data objects incorrect" {
  // Can't read this element security objects now invalid - and return out so we re-do BAC
  completed(nil)
}

fixes the issue:

} else if errMsg == "SM data objects incorrect" {
   // Can't read this element security objects now invalid - and return out so we re-do BAC
   self.tagReader?.reduceDataReadingAmount()
   completed(nil)
}

About NFC Tag Data Validation?

Hi @AndyQ ,
Can you please let me know if I need to give some security checks with backend then which data(Something like Json data) need to validate with the DB?
I mean like somehow we can validate DG(all Data Groups e.g. DG1, DG2......DG15) or after tag detecting we can store all chip data somewhere and validate it from the database.

Problem with the script

Hi, i have an issue with the script.
i'm executing this: python3 extract.py icaopkd-delta-004358.ldif

And i obtained this error:

File "extract.py", line 181, in
main( sys.argv[1] )
File "extract.py", line 32, in main
masterLists = readAndExtractLDIFFile( filename )
File "extract.py", line 63, in readAndExtractLDIFFile
if cert != "":
UnboundLocalError: local variable 'cert' referenced before assignment

my openssl version:
openssl version
OpenSSL 1.1.1g 21 Apr 2020

BAC Failed on AUT Passport

Authentication error with an austrian passport

Debug log (values changed with XXX):
2020-03-05 10:44:23.550712+0100 Identity Reader[405:15932] Metal API Validation Enabled tagReaderSessionDidBecomeActive tagReaderSession:didDetect - iso7816(<NFCISO7816Tag: 0x28096e0d0>) 2020-03-05 10:44:32.340169+0100 Identity Reader[405:15932] [CoreNFC] 00000002 8298ff00 -[NFCTagReaderSession setAlertMessage:]:92 (null) Starting Basic Access Control (BAC) Calculate the SHA-1 hash of MRZ_information Hsha1(MRZ_information): XXX Take the most significant 16 bytes to form the Kseed Kseed: XXX Calculate the Basic Acces Keys (Kenc and Kmac) using Appendix 5.1 Compute Encryption key (c: 00000001 Concatenate Kseed and c D: XXX Calculate the SHA-1 hash of D Hsha1(D): XXX Form keys Ka and Kb Ka: XXX Kb: XXX Adjust parity bits Ka: XXX Kb: XXX Compute MAC Computation key (c: 00000002 Concatenate Kseed and c D: XXX Calculate the SHA-1 hash of D Hsha1(D): XXX Form keys Ka and Kb Ka: XXX Kb: XXX Adjust parity bits Ka: XXX Kb: XXX DATA - [238, 245, 231, 210, 85, 24, 100, 226] Request an 8 byte random number from the MRTD's chip RND.ICC: XXX Generate an 8 byte random and a 16 byte random RND.IFD: XXX RND.Kifd: XXX Concatenate RND.IFD, RND.ICC and Kifd S: XXX Encrypt S with TDES key Kenc as calculated in Appendix 5.2 Eifd: XXX x0: XXX y0: XXX x1: XXX y1: XXX x2: XXX y2: XXX x3: XXX y3: XXX x4: XXX y4: XXX y: XXX bkey: XXX akey: XXX b: XXX a: XXX Compute MAC over eifd with TDES key Kmac as calculated in-Appendix 5.2 Mifd: XXX Construct command data for MUTUAL AUTHENTICATE cmd_data: XXX Error reading tag: sw1 - 0x63, sw2 - 0x00 ERROR - The operation couldn’t be completed. (NFCPassportReader.TagError error 20.) BAC Failed

Error reading tag: sw1 - 62, sw2 - 82 - reason: End of file/record reached before reading Le bytes

With version 1.0.7 it works, with versions 1.0.8 to 1.0.10 I get the following error messages:

Starting Basic Access Control (BAC)
BAC Successful
2020-02-11 13:18:09.655779+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
Reading tag - COM
2020-02-11 13:18:09.701659+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
Expected response length: 22
Error reading tag: sw1 - 62, sw2 - 82 - reason: End of file/record reached before reading Le bytes
2020-02-11 13:18:09.720678+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
ERROR - End of file/record reached before reading Le bytes
Reading tag - COM
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-11 13:18:09.741806+0100 Identity Reader[3574:1702453] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
2020-02-11 13:18:09.812785+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
Reading tag - COM
2020-02-11 13:18:09.861595+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
Expected response length: 22
Error reading tag: sw1 - 62, sw2 - 82 - reason: End of file/record reached before reading Le bytes
2020-02-11 13:18:09.882241+0100 Identity Reader[3574:1702498] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
ERROR - End of file/record reached before reading Le bytes
Reading tag - COM
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
2020-02-11 13:18:09.904574+0100 Identity Reader[3574:1702514] [CoreNFC] 00000002 834bd800 -[NFCTagReaderSession setAlertMessage:]:92  (null)
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)

this repeats endlessly

Affected version: > 1.0.7
Document: Passport from spain

Cannot read DG15

Hi , i am having problem with reading DG15 data, there is no problem with DG1, DG2 etc.
In the code below , OpenSSLUtils.readECPublicKey( data:body ) cannot read data here, returns empty. And throws unable to read ec public key error. What might be the reason ? Thank you

public class DataGroup15 : DataGroup {

public private(set) var rsaPublicKey : OpaquePointer?
public private(set) var ecdsaPublicKey : UnsafeMutablePointer<EVP_PKEY>?

deinit {
    EVP_PKEY_free(ecdsaPublicKey);
}

required init( _ data : [UInt8] ) throws {
    try super.init(data)
    datagroupType = .DG15
}


override func parse(_ data: [UInt8]) throws {
    
    // the public key can either be in EC (elliptic curve) or RSA format
    // Try ec
    
    if let key = try OpenSSLUtils.readECPublicKey( data:body ) {
        // NOTE We are responsible for freeing the key!
        ecdsaPublicKey = key
    }
}

}

Error while building

i am getting below issue:
Showing Recent Messages : the Package.resolved file is most likely severely out-of-date and is preventing correct resolution; delete the resolved file and try

i am running the project on xcode 11 beta 4.Tried downloading XCode 11 beta 2 , but could not succeed.

Could you help me?

"Unknown error - sw1: 0x63, sw2 - 0xCF ", 99, 207

With version 1.0.11 it works well with pretty much all passports. However, I get the following error message when tried with a Chinese passport:
Sorry, there was a problem reading the passport. ("Unknown error - sw1: 0x63, sw2 - 0xCF ", 99, 207)

IMAGE 2020-07-08 12:53:21

Passport showed NFCError Code=200 (DEUTSCHLAND)

Hello there
Thank you very much for preparing such a beautiful package. And of course, congratulations. I'd be happy to say we used it seriously.
I want to talk about a problem written by someone else and get help. You can view the closed topic from the link below. Actually, I'd like to continue with that. But it's closed. Therefore, the answer you specify there is not the correct answer.

We want to solve the problem that we have identified but cannot solve with your help. We can reach the solution with the speed that you will gain when you develop the package.
In fact, the causes of this problem in reality are;

The same passport was failing on android devices. The reason is that the dg12 file is not in that passport. If you do not have that file on the Android side of the other file, but I was able to switch to the ios side. [DOCATCH] gets error even though I do not. I don't know where to fix it, please help.

Accessing certificate items

How do I retrieve certificate items from the X509Wrapper? Any time I try to retrieve them I am receiving a nil value

App got crashed while fetching datagroups from french passport

while reading the datagroups it got crashed

tag.sendCommand(apdu: toSend) { [unowned self] (data, sw1, sw2, error) in
if let error = error {
Log.error( "Error reading tag - (error.localizedDescription)" )
completed( nil, TagError.ResponseError( error.localizedDescription, sw1, sw2 ) )
} else {
var rep = ResponseAPDU(data: UInt8, sw1: sw1, sw2: sw2)

            if let sm = self.secureMessaging {
                do {
                    rep = try sm.unprotect(rapdu:rep)

I tried to debug, the "data" was empty and also there is no error(nil). So while "unprotect" response it got crashed.

    // Mandatory, only absent if SM error occurs
    do99 = [UInt8](rapduBin[offset..<offset+4])

This the exact line, it got crashed

readerSession Invalidate Error Handling.

Hi @AndyQ
I am not getting the invalidate error form the PassportReader class. I need to handle the error when user cancel the session. Something like I need to call

if (readerError.code != .readerSessionInvalidationErrorFirstNDEFTagRead)
            && (readerError.code != .readerSessionInvalidationErrorUserCanceled) { }

Can you please let me know how can I access this method so when I cancel the session then display the alert message and on alert button call the session again.

Error performing active authentication

When running the example app, I get my data from the passport. However the authentication fails.

Starting Basic Access Control (BAC)
Error reading tag: sw1 - 63, sw2 - 00 - reason: No information given
BAC Failed
Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
DG Found - ["DG1", "DG2", "DG15", "DG3", "DG14"]
Reading tag - SOD
Reading tag - DG1
Reading tag - DG2
Reading tag - DG15
Reading tag - DG14
Performing Active Authentication
Error reading tag: sw1 - 67, sw2 - 00 - reason: Wrong length
IN CALLBACK
error 20 at 0 depth lookup:unable to get local issuer certificate

Quick debug shows that something goes wrong in the send in doInternalAuthentication, maybe the expectedResponseLength should be different?

This is with a passport from The Netherlands.

BTW Great project! Since a few days it is possible in the digital ID app of The Netherlands to verify yourself by reading your passport in their app, so I wanted to know how it's done :)

could not install pods and run example

When I try to $ pod install in the Example directory, I get the message:

[!] CocoaPods could not find compatible versions for pod "OpenSSL-Universal/Framework":
In Podfile:
NFCPassportReader (from https://github.com/AndyQ/NFCPassportReader.git) was resolved to 0.0.10, which depends on
OpenSSL-Universal/Framework

None of your spec sources contain a spec satisfying the dependency: OpenSSL-Universal/Framework.

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

When I start the workspace in Xcode, it shows errors with missing files in Pods/Target Support Files/

[German ID] Conditions of use not satisfied

Affected version: 1.0.4
Document: ID card from Germany

Info Logs:

Starting Basic Access Control (BAC)
Error reading tag: sw1 - 69, sw2 - 85 - reason: Conditions of use not satisfied
BAC Failed

Debug Logs:

tagReaderSessionDidBecomeActive
tagReaderSession:didDetect - iso7816(<NFCISO7816Tag: 0x28393a070>)
Starting Basic Access Control (BAC)
Calculate the SHA-1 hash of MRZ_information
	Hsha1(MRZ_information): <value>
Take the most significant 16 bytes to form the Kseed
	Kseed: <value>
Calculate the Basic Acces Keys (Kenc and Kmac) using Appendix 5.1
Compute Encryption key (c: 00000001
	Concatenate Kseed and c
		D: <value>
	Calculate the SHA-1 hash of D
		Hsha1(D): <value>
	Form keys Ka and Kb
		Ka: <value>
		Kb: <value>
	Adjust parity bits
		Ka: <value>
		Kb: <value>
Compute MAC Computation key (c: 00000002
	Concatenate Kseed and c
		D: <value>
	Calculate the SHA-1 hash of D
		Hsha1(D): <value>
	Form keys Ka and Kb
		Ka: <value>
		Kb: <value>
	Adjust parity bits
		Ka: <value>
		Kb: <value>
DATA - [73, 198, 230, 113, 14, 75, 117, 52]
Request an 8 byte random number from the MRTD's chip
	RND.ICC: <value>
Generate an 8 byte random and a 16 byte random
	RND.IFD: <value>
	RND.Kifd: <value>
Concatenate RND.IFD, RND.ICC and Kifd
	S: <value>
Encrypt S with TDES key Kenc as calculated in Appendix 5.2
	Eifd: <value>
x0: <value>
y0: <value>
x1: <value>
y1: <value>
x2: <value>
y2: <value>
x3: <value>
y3: <value>
x4: <value>
y4: <value>
y: <value>
bkey: <value>
akey: <value>
b: <value>
a: <value>
Compute MAC over eifd with TDES key Kmac as calculated in-Appendix 5.2
	Mifd: <value>
Construct command data for MUTUAL AUTHENTICATE
	cmd_data: <value>
Error reading tag: sw1 - 69, sw2 - 85 - reason: Conditions of use not satisfied
ERROR - The operation couldn’t be completed. (NFCPassportReader.TagError error 0.)
BAC Failed
tagReaderSession:didInvalidateWithError - Error Domain=NFCError Code=200 "Session invalidated by user" UserInfo={NSLocalizedDescription=Session invalidated by user}

Getting the error with ReadID demo app as well.

Nil signature image

I'm testing with the Spanish idcard and I can retrieve data groups 1, and 2 with no problem (also SOD and COM), but data group 7 (signature image) is nil. Has anyone been able to retrieve signature image?

Guide to running the example

Hi,

Could you please provide a guide for building and running the example? I tried using iOS 13, but the example app does not seem to respond the inputs. Did I build it wrong, or am I using the incorrect inputs?

Thanks!

Roy

Implementing Chip Authentication

Hey,
are you thinking of implementing Chip Authentication(CA) besides the Active Authentication(AA)?
Even if CA mostly aims to provide the same verification features as AA, CA seems to be more commonly supported in current passports.

Just for some context, a short summary of CA can be found here.

error 10 at 2 depth lookup:certificate has expired

I'm testing out the Example application with 2 EU passports from The Netherlands.

One is from 2017 and is marked as ✅ Genuine.
One is from 2015 and is marked as ❌ Not Genuine

For this one I see the following error in the console:

error 10 at 2 depth lookup: certificate has expired

I wonder what the problem is? It says the certificate has expired. Which certificate is this? The masterList.pem file? Or the certificate on the chip?

When I use RealID app on iOS it works perfectly.

I've constructed the masterList.pem file from the latest icaopkd-002-ml-000150.ldif file.

TagError.InvalidResponse file specification

It will be usefull if on throwing a TagError.InvalidResponse will be possible to retrieve which datagroup triggered the error, maybe adding a DatagroupID param to the TagError.InvalidResponse

Which LDIF files to parse, what countries test ok?

I retrieved the ICAO's master list version icaopkd-002-ml-000137.ldif which was referred to as "The latest collection of CSCA Master Lists." I attempted to parse from LDIF into the PEM format using scripts/extract.py and it caught some encoding errors see below.

# b'unable to load certificate
# \r\n14136:error:0D078094:asn1 encoding routines:asn1_item_embed_d2i:sequence length mismatch:../openssl-1.1.1c/crypto/asn1/tasn_dec.c:386:Type=X509_NAME_ENTRY
# \r\n14136:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:../openssl-1.1.1c/crypto/asn1/tasn_dec.c:596:
# \r\n14136:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:../openssl-1.1.1c/crypto/asn1/tasn_dec.c:596:
# \r\n14136:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:../openssl-1.1.1c/crypto/asn1/tasn_dec.c:627:Field=issuer, Type=X509_CINF
# \r\n14136:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:../openssl-1.1.1c/crypto/asn1/tasn_dec.c:627:Field=cert_info, Type=X509

I am debugging python on vscode for the first time, would be happy to learn what else to gather to document the problem. I don't know if I am using the right file. It's name includes ml for master list so it looked correct. On visual inspection it contains 10 certs for various countries:
image

ICAO also has icaopkd-001-dsccrl-004079.ldif which is much larger and appears to have more countries. This was named "The latest collection of Document Signing Certificates(DSCs) and Certificate Revocation Lists(CRLs) to verify electronic passports." This has my country's certs.

  1. Which are you testing with and what countries' passports have you tested with? Can we start a list somewhere of what's tested ok?
  2. Can we document how to build a smaller test case for a single country?
  3. Are there any test or developer mocks that the ICAO has or we could develop ourselves?

PACE becomes urgent

I am getting user reports indicating that BAC is not supported anymore on some passports issued in late 2019 early 2020.

UAE Passport

While scanning UAE Passport, I am getting this error.

(NFCPassportReader.OpenSSLError *)0x282db30a8)):
▿ OpenSSLError
  - UnableToVerifyX509CertificateForSOD : "Verification of certificate failed - errorCode 20"

Complete log list -

Starting Basic Access Control (BAC)
Error reading tag - Tag connection lost
BAC Failed
Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
Error reading tag: sw1 - 0x69, sw2 - 0x88
reason: SM data objects incorrect
ERROR - SM data objects incorrect
Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
Expected response length: 25
DG Found - ["DG1", "DG3", "DG11", "DG12", "DG13", "DG14", "DG2"]
Reading tag - SOD
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 244
Expected response length: 13
Reading tag - DG1
Expected response length: 91
Reading tag - DG11
Expected response length: 102
Reading tag - DG12
Expected response length: 26
Reading tag - DG13
Expected response length: 6
TagError reading tag - NotImplemented
Reading tag - DG14
Expected response length: 255
Expected response length: 131
Reading tag - DG2
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 255
Expected response length: 235
Expected response length: 4
error 20 at 0 depth lookup:unable to get local issuer certificate

With version - 1.0.10 -

And changed to this - expectedResponseLength : Int(readAmount)

Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
DG Found - ["DG1", "DG3", "DG11", "DG12", "DG13", "DG14", "DG2"]
Reading tag - SOD
Reading tag - DG1
Reading tag - DG11
Reading tag - DG12
Reading tag - DG13
TagError reading tag - NotImplemented
Reading tag - DG14
Reading tag - DG2
error 20 at 0 depth lookup:unable to get local issuer certificate

Unable to open Pods-NFCPassportReaderApp

I can't seem to build the project, as It gives the following error.

Showing Recent Messages
/Users/user/Downloads/NFCPassportReader/Example/Pods/Target Support Files/Pods-NFCPassportReaderApp/Pods-NFCPassportReaderApp.debug.xcconfig: unable to open file (in target "NFCPassportReaderApp" in project "NFCPassportReaderApp")

Running pod deintegrate and pod install again returns these errors.

[!] [!] Xcodeproj doesn't know about the following attributes {"productRef"=>"A16FC0C922B11E7200144B5B"} for the 'PBXBuildFile' isa.
If this attribute was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new

[!] [!] Xcodeproj doesn't know about the following attributes {"packageProductDependencies"=>["A16FC0C922B11E7200144B5B"]} for the 'PBXNativeTarget' isa.
If this attribute was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new

[!] [!] Xcodeproj doesn't know about the following attributes {"packageReferences"=>["A16FC0C822B11E7200144B5B"]} for the 'PBXProject' isa.
If this attribute was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new

Scanning Passport

Hi, thank you for this library.

I have a question. I am trying your example project. I have added my pem file.
i got some error like that

Starting Basic Access Control (BAC)
Error reading tag: sw1 - 0x65, sw2 - 0x81
reason: Memory failure
BAC Failed

or

Starting Basic Access Control (BAC)
Error reading tag: sw1 - 0x69, sw2 - 0x82
reason: Security status not satisfied
BAC Failed

how can i fix this ?

mrzKey is wrong for non 9-digits passport numbers

Hi! I found this issue when trying to debug why not Swedish passports worked with this scanner.

Sample here

The problem is this piece of code:

let mrzKey = "\(passportNumber)\(passportNrChksum)\(dateOfBirth)\(dateOfBirthChksum)\(expiryDate)\(expiryDateChksum)"

The passportNumber must be 9 chars in the key. I solved the problem with this code

let filler = "<<<<".prefix(max(0, 9 - passportNumber.count))
let mrzKey = "\(passportNumber)\(filler)\(passportNrChksum)\(dateOfBirth)\(dateOfBirthChksum)\(expiryDate)\(expiryDateChksum)"

I'm very impressed by this framework! Really good piece of work.

Best regards // Jens

UIImage not found

In DataGroupPareser.swift UIImage seems to not be found by XCode. I solved adding UIKit import.

No information

Just started playing with this and get this log in the console

tagReaderSessionDidBecomeActive
tagReaderSession:didDetect - iso7816(<NFCISO7816Tag: 0x2826fce20>)
2019-07-05 13:07:02.143849+0200 NFCPassportReaderApp[3327:1102765] [CoreNFC] 00000002 808f0500 -[NFCTagReaderSession setAlertMessage:]:92  (null)
Calculate the SHA-1 hash of MRZ_information
	Hsha1(MRZ_information): C06AEF680289C5B215A5A44F8B436C518641680C
Take the most significant 16 bytes to form the Kseed
	Kseed: C06AEF680289C5B215A5A44F8B436C51
Calculate the Basic Acces Keys (Kenc and Kmac) using Appendix 5.1
Compute Encryption key (c: 00000001
	Concatenate Kseed and c
		D: C06AEF680289C5B215A5A44F8B436C5100000001
	Calculate the SHA-1 hash of D
		Hsha1(D): 7E70C4819710ECBFE199B53ECA24E30F6A2844AF
	Form keys Ka and Kb
		Ka: 7E70C4819710ECBF
		Kb: E199B53ECA24E30F
	Adjust parity bits
		Ka: 7F70C4809710ECBF
		Kb: E098B53ECB25E30E
Compute MAC Computation key (c: 00000002
	Concatenate Kseed and c
		D: C06AEF680289C5B215A5A44F8B436C5100000002
	Calculate the SHA-1 hash of D
		Hsha1(D): 00E55AD96F1EC5E179B1676E77DC796F19B5A5A8
	Form keys Ka and Kb
		Ka: 00E55AD96F1EC5E1
		Kb: 79B1676E77DC796F
	Adjust parity bits
		Ka: 01E55BD96E1FC4E0
		Kb: 79B0676E76DC796E
DATA - [163, 226, 37, 23, 62, 202, 242, 13]
Request an 8 byte random number from the MRTD's chip
	RND.ICC: A3E225173ECAF20D
Generate an 8 byte random and a 16 byte random
	RND.IFD: 4E1B5C8FABC350C9
	RND.Kifd: 5842FCEDF71298DBC91817A6FDD4289E
Concatenate RND.IFD, RND.ICC and Kifd
	S: 4E1B5C8FABC350C9A3E225173ECAF20D5842FCEDF71298DBC91817A6FDD4289E
Encrypt S with TDES key Kenc as calculated in Appendix 5.2
	Eifd: 52551BB50E3A810CD41D897D3DC701FBBA7AFD9962C310E145252431EB63744B
x0: 52551BB50E3A810C
y0: A7D44DF6F4158315
x1: D41D897D3DC701FB
y1: 170284638F1041C0
x2: BA7AFD9962C310E1
y2: 129D2A638CEF5C9A
x3: 45252431EB63744B
y3: 2BD51054FAAB6E46
x4: 8000000000000000
y4: 90933F700050255A
y: 90933F700050255A
bkey: 79B0676E76DC796E
akey: 01E55BD96E1FC4E0
b: 497A8D0860359C36
a: 1F2CE3C9895BBD52
Compute MAC over eifd with TDES key Kmac as calculated in-Appendix 5.2
	Mifd: 1F2CE3C9895BBD52
Construct command data for MUTUAL AUTHENTICATE
	cmd_data: 52551BB50E3A810CD41D897D3DC701FBBA7AFD9962C310E145252431EB63744B1F2CE3C9895BBD52
Error reading tag: sw1 - 63, sw2 - 00 - reason: No information given
ERROR - The operation couldn’t be completed. (NFCPassportReader.TagError error 0.)
tagReaderSession:didInvalidateWithError - Error Domain=NFCError Code=200 "Session invalidated by user" UserInfo={NSLocalizedDescription=Session invalidated by user}

Any pointers to what could have gone wrong? It is a Swedish passport btw.

Package is out of date

Hello.

I'm getting this error when trying to build the project:

Showing Recent Messages : the Package.resolved file is most likely severely out-of-date and is preventing correct resolution; delete the resolved file and try again

Any ideas? Thanks.

NFC Scan timeouts does not scan

I have generated the MRZKey. when start to Scan Details it opens the NFC view, the method gets invoke - "tagReaderSessionDidBecomeActive".
After a while it timeouts.
"invalidate - Session timeout ".
master.pem file is also generated as mention in the scripts folder
May I know what I am missing.

ld: warning: Could not find auto-linked library

After flip flopping bitcode build settings all over I finally end up with the link error in the subject. I can not find the proper build setting to resolve this. I know it has something to do with OpenSSL having bitcode off, but beyond that, suggestions? I am trying to deliver the functionality of your pod through my own framework. It all compiles fine while working directly with the framework, not so much when I try to link that framework to my app. Tossing the framework is not an option and I would rather not turn it into a pod.

tagReaderSessionDidBecomeActive() not being called

Hi,

I use pods for the library. The nfc pop-up appears on the screen however when i hold a Turkish passport or Turkish ID Card (which has similar nfc chip) , the methods tagReaderSessionDidBecomeActive() or tagReaderSession() not being called.

I configured info.plist, entitlements and capabilities also checked it from apple developer account.
However ReadID just works fine.

I also tried to use sample app but, it also didn't work.

Am i missing anything ? Can you give me some clue about the issue ?

Thanks and regards...

Buying specimen passports

Has someone experience with buying specimen passports?
I know that almost all countries distribute specimen passports (Except Germany), but I don't know how to get my hands on them.
I would like to buy some so that I can use them for testing.

Not working in device

I'm just trying to run the code, it's working in the simulator but in a real device, it's crash with below log.

dyld: Symbol not found: _$s7SwiftUI19UIViewRepresentableP13_layoutTraits3forAA07_LayoutF0VSg0C4TypeQz_tFTq Referenced from: /var/containers/Bundle/Application/EF99674A-73B5-4DB7-800E-3FDFBA3B32A1/NFCPassportReaderApp.app/NFCPassportReaderApp Expected in: /System/Library/Frameworks/SwiftUI.framework/SwiftUI in /var/containers/Bundle/Application/EF99674A-73B5-4DB7-800E-3FDFBA3B32A1/NFCPassportReaderApp.app/NFCPassportReaderApp (lldb)

Screen Shot 2019-07-09 at 3 38 14 PM

Chinese passport showed NFCError Code=200

hello author,
I want to identify my Chinese passport with CoreNFC in iOS 13 by using your this project. But when I input passport Num,Date of birth and Passport expiry date and tap the scan button, it output the error on the console:

Build DO'8E
	DO8E: 8E08057D0E40499415A3
Construct and send protected APDU
	ProtectedAPDU: 0CA4020C1587090136D7EC32E9FADAD78E08057D0E40499415A300
[SM] <NFCISO7816APDU: 0x280715e00>
Error reading tag: sw1 - 6A, sw2 - 82 - reason: File not found
tagReaderSession:didInvalidateWithError - Error Domain=NFCError Code=200 "Session invalidated by user" UserInfo={NSLocalizedDescription=Session invalidated by user}

And sometimes the error is that:

NFCPassportReaderApp[9722:648432] [CoreNFC] 00000002 82754700 -[NFCTagReaderSession transceive:tagUpdate:error:]:710  Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}
Error reading tag - Tag connection lost
tagReaderSession:didInvalidateWithError - Error Domain=NFCError Code=200 "Session invalidated by user" UserInfo={NSLocalizedDescription=Session invalidated by user}

I really want to know what happen,and next what should i do. Please tell me the steps that solve these problems.

How can I got the DSC?

Hi @AndyQ
After matching the all hashes then how can I verify signature of SOD using the DSC? Can you please confirm the DSC available in chip OR compulsory to receive it from Issuing Authority?

[German ID] Error reading DG3 tag. Reason: Security status not satisfied.

Reading tag - COM
Reading tag - SOD
Reading tag - DG1

are successful.

when reading DG3 tag, getting error:

Reading tag - DG3
Mask class byte and pad command header
	CmdHeader: <value>
Pad data
	Data: <value><value>
Encrypt data with KSenc
	EncryptedData: <value>
Build DO'87
	DO87: <value>
Concatenate CmdHeader and DO87
	M: <value>
		SSC: <value>
Compute MAC of M
	Increment SSC with 1
		SSC: <value>
	Concatenate SSC and M and add padding
		N: <value>
x0: <value>
y0: <value>
x1: <value>
y1: <value>
x2: <value>
y2: <value>
x3: <value>
y3: <value>
y: <value>
bkey: <value>
akey: <value>
b: <value>
a: <value>
	Compute MAC over N with KSmac
		CC: <value>
Build DO'8E
	DO8E: <value>
Construct and send protected APDU
	ProtectedAPDU: <value>
[SM] <NFCISO7816APDU: 0x283c67570>
Error reading tag: sw1 - 69, sw2 - 82 - reason: Security status not satisfied
2019-11-09 19:17:56.458315+0100 NFCPassportReaderApp[669:36407] [CoreNFC] 00000002 81c70900 -[NFCTagReaderSession setAlertMessage:]:92  (null)
ERROR - Security status not satisfied
Calculate the SHA-1 hash of MRZ_information
	Hsha1(MRZ_information): <value>
Take the most significant 16 bytes to form the Kseed
	Kseed: <value>
Calculate the Basic Acces Keys (Kenc and Kmac) using Appendix 5.1
Compute Encryption key (c: 00000001
	Concatenate Kseed and c
		D: <value>
	Calculate the SHA-1 hash of D
		Hsha1(D): <value>
	Form keys Ka and Kb
		Ka: <value>
		Kb: <value>
	Adjust parity bits
		Ka: <value>
		Kb: <value>
Compute MAC Computation key (c: 00000002
	Concatenate Kseed and c
		D: <value>
	Calculate the SHA-1 hash of D
		Hsha1(D): <value>
	Form keys Ka and Kb
		Ka: <value>
		Kb: <value>
	Adjust parity bits
		Ka: <value>
		Kb: <value>
DATA - [135, 254, 118, 14, 193, 128, 176, 231]
Request an 8 byte random number from the MRTD's chip
	RND.ICC: <value>
Generate an 8 byte random and a 16 byte random
	RND.IFD: <value>
	RND.Kifd: <value>
Concatenate RND.IFD, RND.ICC and Kifd
	S: <value>
Encrypt S with TDES key Kenc as calculated in Appendix 5.2
	Eifd: <value>
x0: <value>
y0: <value>
x1: <value>
y1: <value>
x2: <value>
y2: <value>
x3: <value>
y3: <value>
x4: <value>
y4: <value>
y: <value>
bkey: <value>
akey: <value>
b: <value>
a: <value>
Compute MAC over eifd with TDES key Kmac as calculated in-Appendix 5.2
	Mifd: <value>
Construct command data for MUTUAL AUTHENTICATE
	cmd_data: <value>
Error reading tag: sw1 - 6A, sw2 - 88 - reason: Referenced data not found
ERROR - The operation couldn’t be completed. (NFCPassportReader.TagError error 0.)
tagReaderSession:didInvalidateWithError - Error Domain=NFCError Code=200 "Session invalidated by user" UserInfo={NSLocalizedDescription=Session invalidated by user}

<value> replaces real values just to hide them in public.

Affected version: 1.0.0
ID country: Germany
Running on Example app

Version 0.0.8 reads the same document with the same MRZ Key successfully.

Error session.connect( to: NFCTag).

I always have an error when I am trying to connect to tag. I couldn't find any information how to resolve this problem.
I tried on Xcode 11 beta 4 and iOS 13 beta 4, Xcode 11 beta 5 and iOS 13 beta 5
Error Domain=NFCError Code=100 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error, NSUnderlyingError=0x2800d7000 {Error Domain=nfcd Code=28 "Tag Not Found" UserInfo={NSLocalizedDescription=Tag Not Found}}}

Wrong length Le: SW2 indicates the exact length

Hi @AndyQ
I get this error in some passports

Reading tag - SOD 2019-12-02 12:20:37.508446+0300 TryRead[14053:3034689] [CoreNFC] 00000002 83c1c080 -[NFCTagReaderSession setAlertMessage:]:92 (null) Error reading tag: sw1 - 6C, sw2 - E7 - reason: Wrong length Le: SW2 indicates the exact length - (exact length :231)

Tag name changing but error same.
What I should do ?
Are there any temp solution ?

Memory management crash

Hi!

There is a crash:
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x60000001a).

if passportreader read the document, and we had the NFCPassportModel object in the response, and we would like to use for example data group 11

passport.getDataGroup(.DG11)

code satarts like this:

            let dataGroups : [DataGroupId] = [.COM, .DG1, .DG2, .DG7, .DG11, .DG15, .SOD]
            self?.passportReader.readPassport(mrzKey: mrzKey, tags: dataGroups, completed: { (passport, error) 

in completion closure if you want to get the data group 11, it's a crash.

Bests,
Norbi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.