This shows you the differences between two versions of the page.
ac:laboratoare:09 [2024/12/15 06:31] dimitrie.valu |
ac:laboratoare:09 [2024/12/15 06:42] (current) dimitrie.valu |
||
---|---|---|---|
Line 322: | Line 322: | ||
<solution -hidden> | <solution -hidden> | ||
- | </solution> | + | We should allow students to select the data somewhat arbitrarily as it's not **entirely** provided in the exercises above, as per the minimum spec mentioned in EMV Book 2, page 87, section 8.1.1, table 28. |
- | <hidden> | + | <code python> |
- | ==== Getting data from your card ==== | + | from Crypto.Cipher import DES3 |
+ | from Crypto.Util.Padding import pad | ||
- | First, get pyscard from | + | master_key = bytes.fromhex("79610497EFCB67E5546EF8CEBCB05D85") |
- | [[https://pypi.python.org/pypi/pyscard|here]]. | + | aip = bytes.fromhex("1000") |
- | Then, install pyscard (check the readme). Do the following (as root): | + | # concatenation of amount authorised and amount other, |
- | * Install pcsclite-dev: | + | # terminal country code, transaction currency code, |
- | <code> | + | # transaction date, transaction type, |
- | sudo apt-get install libpcsclite-dev | + | # unpredictable number, given AIP and the ATC |
- | </code> | + | # we aren't given the terminal verification results, |
- | * Only if the above doesn't work, then install these packages: | + | # so I assumed that it's gonna be 5 * b'00' |
- | <code> | + | transaction_data = bytes.fromhex( |
- | #apt-get install swig libudev-dev git autoconf libtool libsystemd-dev flex | + | "00000000000000000000000008000000000000000000000034000000000000000010000134" |
- | </code> | + | ) # from task 5 |
- | * Get and install Pyscard from [[https://pypi.python.org/pypi/pyscard|here]] | + | |
- | <code> | + | |
- | #python setup.py build_ext install | + | |
- | </code> | + | |
- | * Install Pyserial | + | |
- | <code> | + | |
- | #sudo pip install pyserial | + | |
- | </code> | + | |
- | If this doesn't work, then get pyserial from [[https://pypi.python.org/pypi/pyserial#downloads|here]] | + | |
- | * Install pcsc related libs: | + | |
- | <code> | + | |
- | sudo apt-get install libusb-dev libusb++-0.1-4v5 libccid pcscd libpcsclite1 | + | |
- | </code> | + | |
- | * Only if desired, additional tools can be installed from here: | + | |
- | <code> | + | |
- | #apt-get install libpcsc-perl | + | |
- | #apt-get install pcsc-tools | + | |
- | </code> | + | |
- | See details [[http://support.gemalto.com/fileadmin/user_upload/IAM/FAQ/How_to_install_the_PC-Link_reader_on_Linux.pdf|here]]. | + | |
+ | # 3DES block size is 8 bytes | ||
+ | padded_data = pad(transaction_data, 8) | ||
+ | # 3DES encryption | ||
+ | cipher = DES3.new(master_key, DES3.MODE_ECB) | ||
+ | mac = cipher.encrypt(padded_data) | ||
- | Files for accessing card data [[https://ocw.cs.pub.ro/courses/_media/ac/laboratoare/sclink.zip|here]]. | + | mac = mac.hex() |
- | </hidden> | + | print(mac) |
+ | </code> | ||
+ | </solution> | ||