Introduction: RFID Reader for EPassports by Android Phone (TfCD)
(Part of TfCD Assignment 2 for the Master IPD at TU Delft)
This instructable shows how to use your phone as an RFID reader. The goal is to read the data stored on the chip of an ePassport including names, gender, nationality, expiry date, date of birth and the photo. This is done using the NFC technology on android based smartphones.
One way of doing this is to download one of the available apps that are able to scan and read passports. However, we hesitate to do this. Since we are going to scan our private and sensitive passport data, we want to prevent that this is being shared to any other party at all costs. We are not completely sure that this sharing doesn’t happen while using the available apps. That’s why we decided to use another approach.
This approach is shown in the following steps of the instructable. We're going to search for parts of code that are needed to get our own ePassport reader app, and implement the code manually. Having more control over what the app does and doesn’t do. The downside of this is that some programming knowledge (java/android) is needed.
To be able to complete this instructable you will need:
- An Android based smartphone with NFC enabled
- A computer capable of running Eclipse software
- An ePassport
- Java/Android programming knowledge
Step 1: Install Eclipse
To create the application we're going to use Eclipse. Eclipse is a development platform that enables users to develop, compile and edit android applications. Installing takes multiple steps and can be quite hard, since some plugins and additional downloads are required to get a proper installation. Explaining how this is done doesn't fit within the goal of this instructable. Besides, this is already thoroughly explained in the instructable about setting up eclipse.
After you've installed Eclipse, the Android SDK and the ADT plugin properly, you can proceed to the next step.
Step 2: Search for Existing Code
Our experience is that almost all code has already been written. Websites like github.com and stackoverflow.com often hold usable parts of the code you'll need. Especially for inexperienced developers sites like these are essential.
Browsing these sites quickly gives results on how to read NFC tags, communicate with ePassports and implement this into your own application
Step 3: Create an Android Application Project & Import Code
To use the found pieces of code for your own application, a new Android Application Project needs to be started. Starting a new project can be done in Eclipse under file > new (Alt+Shift+N) > Android Application Project. Proceeding through the wizard will generate the required files and folders to start working in.
Downloaded/found code should be placed in Eclipse to start editting/analysing it. This is where programming knowledge comes in handy. Knowing what to place where can be hard to figure out exactly. That is why the next steps contain information about the setup of our source code.
Step 4: Check and Change
Now the hard part begins: Creating a working app. The first step is to check out the Android manifest file. This file stores essential data about the app, like the version, the icon, permissions (what it is allowed to use) and activities (the actions the user can perform, usually the different windows/interfaces).
In Eclipse this file can be found in the package explorer at the left side of the screen in the folder where the app is located. It is called AndroidManifest.xml. When you open it you should paste the code about 'uses-permission' and 'uses-feature' into the file. The permission and feature shown in the image are the neccesary ones: these enable the application to use the NFC reader in the phone. Basically these are the only permission and feature needed to read the ePassport data.
Step 5: What Should Be in There: Libraries
Now that we've made a start with the manifest, we can continue with other parts. One highly useful library we've found is the JMRTD API. This software library can read machine readable travel documents such as ePassports. Placing this API inside the project enables to use all of its functionality, without having to write a single line of code by yourself. More information and documentation about the applet and about the installation can be found at jmrtd.org.
Step 6: What Should Be in There: Source Files
The source files of the project are divided into different classes:
- About a database and it's handling (DataBase.java, DataBaseHelper.java)
- Some activities (BACeditor.java, PassportReader.java, PassportResult.java)
- Some additional needed classes (ListAdapter.java, Utils.java)
To get access to the passport data several protocols have to be executed. The first protocol (BAC) sends passport data (date of birth, date of expiry and document number) to the chip. If this data is correct the chip allows further communication. This is a security feature that prevents unauthorised reading of the card.
For the application, this means that the three variables (date of birth, date of expiry and document number) need to be stored on the device to be used when needed. A local database is created to store this data. Thereby a class is created that inserts data into and retrieves data from this database. Documentation about databases in Android can be found here.
The activities are in our case linked to the different interfaces of our application. The PassportReader class is shown when the app is launched and waits for a passport to get close and starts the communication (NFC intent). Similar to this. With a button you can insert the BAC data, as mentioned earlier. The screen that opens up is linked to the BACeditor class. After a machine readable travel document (as an ePassport) is recognized, the PassportResult class is opened. This activity reads the data stored on the ePassport and displays it. Here it uses the JMRTD library. For implementation it is useful to use the source code of this library from here with an instruction from here.
Step 7: Install and Scan
After completing the code and creating the needed layouts, the application can be installed and tested. This testing is shown in the video. It takes approximately 13 seconds to read the card and transfer the data (including the passport photo)
We have a be nice policy.
Please be positive and constructive.