X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/452aab1e5958de169a5407b4cbd07f11642d0028..c840385effee20347ec8179a393bf109c681de9d:/client/scripts/calypso.lua?ds=inline diff --git a/client/scripts/calypso.lua b/client/scripts/calypso.lua index 5f834edd..281ea944 100644 --- a/client/scripts/calypso.lua +++ b/client/scripts/calypso.lua @@ -2,6 +2,7 @@ local cmds = require('commands') local getopt = require('getopt') local lib14b = require('read14b') local utils = require('utils') +local iso7816 = require('7816_error') example = "script runs 14b raw commands to query a CAPLYPSO tag" author = "Iceman, 2016" @@ -51,6 +52,7 @@ local function calypso_parse(result) local r = Command.parse(result) local len = r.arg2 * 2 r.data = string.sub(r.data, 0, len); + print('GOT:', r.data) if r.arg1 == 0 then return r, nil end @@ -149,33 +151,60 @@ end local function calypso_apdu_status(apdu) -- last two is CRC -- next two is APDU status bytes. - local sw = apdu:sub( #apdu-7, #apdu-4) - print ('SW', sw ) - -- if 0x9000 OK - if sw == '9000' then return 1 end - return 0 + local status = false + local mess = 'FAIL' + local sw = apdu:sub( #apdu-7, #apdu-4) + desc, err = iso7816.tostring(sw) + print ('SW', sw, desc, err ) + + status = ( sw == '9000' ) + + return status end local _calypso_cmds = { - ["1.Select ICC file"] = "02 94 a4 08 00 04 3f 00 00 02", - ["2.ICC"] = "02 94 b2 01 04 1d", - ["3.Select EnvHol file"]= '02 94 a4 08 00 04 20 00 20 01', - ["4.EnvHol1"] = '02 94 b2 01 04 1d', - ["5.Select EvLog file"] = '02 94 a4 08 00 04 20 00 20 10', - ["6.EvLog1"] = '06 00b2 0104 1d', - ["7.EvLog2"] = '06 00b2 0204 1d', - ["8.EvLog3"] = '06 00b2 0304 1d', - -- ["Select ConList file"]= '42 01 04 0a 00a4 0800 04 2000 2050', - -- ["ConList"] = '42 01 06 06 00b2 0104 1d', - -- ["Select Contra file"]= '42 01 08 0a 00a4 0800 04 2000 2020', - -- ["Contra1"] = '42 01 0a 06 00b2 0104 1d', - -- ["Contra2"] = '42 01 0c 06 00b2 0204 1d', - -- ["Contra3"] = '42 01 0e 06 00b2 0304 1d', - -- ["Contra4"] = '42 01 00 06 00b2 0404 1d', - -- ["Select Counter file"]= '42 01 02 0a 00a4 0800 04 2000 2069', - -- ["Counter"] = '42 01 04 06 00b2 0104 1d', - -- ["Select SpecEv file"]= '42 01 06 0a 00a4 08 0004 2000 2040', - -- ["SpecEv1"] = '42 01 08 06 00b2 0104 1d', + +-- Break down of command bytes: +-- A4 = select +-- Master File 3F00 +-- 0x3F = master file +-- 0x00 = master file id, is constant to 0x00. + +-- DF Dedicated File 38nn +-- can be seen as directories +-- 0x38 +-- 0xNN id +-- ["01.Select ICC file"] = '0294 a4 080004 3f00 0002', + +-- EF Elementary File +-- EF1 Pin file +-- EF2 Key file +-- Grey Lock file +-- Electronic deposit file +-- Electronic Purse file +-- Electronic Transaction log file + + + --["01.Select ICC file"] = '0294 a4 00 0002 3f00', + ["01.Select ICC file"] = '0294 a4 080004 3f00 0002', + ["02.ICC"] = '0394 b2 01 041d', + ["03.Select EnvHol file"] = '0294 a4 080004 2000 2001', + ["04.EnvHol1"] = '0394 b2 01 041d', + ["05.Select EvLog file"] = '0294 a4 080004 2000 2010', + ["06.EvLog1"] = '0394 b2 01 041d', + ["07.EvLog2"] = '0294 b2 02 041d', + ["08.EvLog3"] = '0394 b2 03 041d', + ["09.Select ConList file"] ='0294 a4 080004 2000 2050', + ["10.ConList"] = '0394 b2 01 041d', + ["11.Select Contra file"] = '0294 a4 080004 2000 2020', + ["12.Contra1"] = '0394 b2 01 041d', + ["13.Contra2"] = '0294 b2 02 041d', + ["14.Contra3"] = '0394 b2 03 041d', + ["15.Contra4"] = '0294 b2 04 041d', + ["16.Select Counter file"]= '0394 a4 080004 2000 2069', + ["17.Counter"] = '0294 b2 01 041d', + ["18.Select SpecEv file"]= '0394 a4 080004 2000 2040', + ["19.SpecEv1"] = '0294 b2 01 041d', } --- @@ -208,17 +237,20 @@ function main(args) P2 5 LEN_ 0 1 2 3 4 5 6 7 - apdu = '0a 00 94 a4 08 00 04 3f 00 00 02' --select ICC file + apdu = '02 94 a4 08 00 04 3f 00 00 02' --select ICC file DF_NAME = "1TIC.ICA" --]] --for i = 1,10 do --result, err = calypso_send_cmd_raw('0294a40800043f000002',false) --select ICC file for i, apdu in spairs(_calypso_cmds) do + print('>>', i ) apdu = apdu:gsub("%s+","") result, err = calypso_send_cmd_raw(apdu , false) if result then calypso_apdu_status(result.data) - print( result.data ) + print('<<', result.data ) + else + print('<< no answer') end end calypso_switch_off_field()