Read EMV data from Mastercard/VISA Debit/Credit Card [closed]

我的梦境 提交于 2020-02-25 09:44:07

问题


I am trying to build an application to read/encode data on Cards, information like PAN, expiry, customer name, PIN etc, So far I could figure out that I need to send APDU commands to read data from Card but there seems to be no clear documentation available as to what commands are used for what purpose and in what particular sequence, I couldn't find out specifications from Mastercard/VISA. Is there some documentation that can be referred to?

Thanks, Null


回答1:


Extending answer above:

1) SELECT PSE:

T-->C - 00A404000E315041592E5359532E444446303100   # select PSE
T<--C - response with FCI
T-->C - 00B2010C00
T<--C - reponse with record from selected file, read records starting from 1 until receive 6A83 (optional step in your case)

2) SELECT application DF with AID received in step 1):

T-->C - 00A4040007A000000003101000   # as example, Visa AID
T<--C - response with application DF FCI

3) GET PROCESSING OPTIONS - initialize transaction:

T-->C - 80A8000002830000    # check if PDOL presents on card, if not, only 8300 should be added to DATA filed of APDU
T<--C - 771282023C00940C0802020010010300180102019000  # just example reswponse, it will differ on different cards

The response on GET PROCESSING OPTIONS above is TLV encoded:

77 12 - response templait, containing response data
    82 02 3C00 - AUC
    94 0C 080202001001030018010201 - AFL
    9000 - SW (Status Word), response ofapplication, telling you, that no errors occured

Note, that response to GET PROCESSING OPTIONS may be returned as 80 template, in that case, you must parse it yourelf:

80 0E - response templait, containing response data
    3C00 - AUC (always 2 bytes long)
    080202001001030018010201 - AFL
    9000 - SW (Status Word), response ofapplication, telling you, that no errors

You are interesting in AFL, which points you, where to read data from (files and record numbers):

94 0C 
    08020200
        08 - SFI (Short File Identifier)
        02 - first record in file
        02 - last record in file
        00 - no of records to be added to Static Data Authentication
    10010300
        10 - SFI
        01 - first record in file
        03 - last record in file (respectively, 3 records to be read - 01, 02, 03)
        00 - no of records to be added to Static Data Authentication
    18010201
        18 - SFI
        01 - first record in file
        03 - last record of file
        01 - count of records from first record to be used for Static Data Authentication (01 record must be used)

SFI is encoded as follows:

08 = 0000 1000 - first 5 bits are real SFI, it equals to 01, last 3 bits are always set to 0

4) READ APPLICATION DATA - for precize READ APPLICATION DATA command coding check 3rd EMV Book:

T-->C - 00B2020C00   # SFI = 01, record = 02
T<--C - response with record
T-->C - 00B2021400   # SFI = 02, record = 01
T<--C - response with record
T-->C - 00B2031400   # SFI = 02, record = 02
T<--C - response with record
etc until you process last AFL record...

PAN, expiry, effective date, track 2 equivalent data, etc... usually is located in records which are set to be used in Sighed Data Authentication in AFL.

The example above is for T=1 protocol. If card runs T=0 protocol, in response to each APDU which assumes R-APDU (Response APDU) to contain Data field, card will return byte count ready to be read and you should issue GET RESPONSE commands which is described in Book 1 of EMV specification.

Hope it helps.




回答2:


You must check EMV ICC card specifications to understand, how to read data from ICC, specifications are freely available to download. Specification is splitted into 4 parts (4 books). You are interested in 1st and 3rd books to read application. The sequence of APDUs to read application data is the following:

1) SELECT PSE (Payment System Environment file), it contains a list of Application DFs installed on smart card. DFs are named by AID (Application ID), which you will use to create a list of available applications (candidate list) for selection, if you want it, or just find AID with the most less Application Priority Indicator (check EMV Book 1 for more information). This is optional step, you can start from step 2) and try to select both Visa and MasterCard AIDs to check which of them is available on ICC.

2) SELECT application which you want to run using correct AID from list you have got in step 1). AIDs of Visa and MasterCard:

A0000000041010 - MasterCard
A0000000031010 - Visa

It will return FCI (File Control Information) of Application file and make Application SELECTED on ICC itself (Check EMV Book 1 for more information).

3) GET PROCESSING OPTIONS - initiate transaction on ICC. This APDU increments ATC (Application Transaction Counter) and returns AUC (Application Usage Control) and AFL (Application File Locator), which must be used to read data you need (Check EMV Book 3 for info).

4) READ APPLICATION DATA - using AFL returned in 3) you can read Application data. AFL is constructed from several parts: containing information about file (SFI - Short File Identifier), first record number, last record number and count of records used in Signed Data Authentication:

1st byte - SFI
2nd byte - First record ID
3rd byte - Last record ID
4th byte - Count of records in file to be used in Signing Data Authentication

It contains 4 byte long information on every file with records to be read during transaction. Just run over AFL and read records from every SFI from first to last records, that is all (consult book 3 for more information).

You will be unable to read PIN from card, PIN is personalized in records, which are not available to read from outside. ICC uses PIN only inside using VERIFY command, and ICC just returns PIN verification result and PIN try counter if PIN was wrong.

EMV Book 1,also, describes 2 used data transmission protocols, T=0 and T=1. To work with ICCs it is essential to understand a difference between these protocols.

Each step above starts from APDU name to make you easier find information into EMV Books 1 and 3.

To encode data to different card - it is completely different story. You should check EMV CPS (Common Personalization Specification) and GlobalPlatorm specifications. Personalization process is much more complex.



来源:https://stackoverflow.com/questions/58299515/read-emv-data-from-mastercard-visa-debit-credit-card

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!