Commit 16ac79ee authored by Arturo Hernandez's avatar Arturo Hernandez

working init + to sL1

needs more test with classic read/write.
parent c2cafa0b
......@@ -14,6 +14,11 @@ MST_KEY = os.environ.get("MST_KEY", 'cert/server.key')
DEBUG = str2bool(os.environ.get("DEBUG", 'False'))
INIT_CM_KEY = os.environ.get("INIT_CM_KEY", '41 47 45 54 49 43 52 55 4c 45 53 21 31 6f 6e 65')
INIT_CM_KEY = list(bytes.fromhex(os.environ.get("INIT_CM_KEY", '41 47 45 54 49 43 52 55 4c 45 53 21 31 6f 6e 65')))
INIT_CC_KEY = list(bytes.fromhex(os.environ.get("INIT_CC_KEY", '48 45 4c 4c 4f 20 44 61 72 6b 6e 65 73 73 2e 2e')))
INIT_L2_KEY = list(bytes.fromhex(os.environ.get("INIT_L2_KEY", '4d 79 20 46 72 69 65 6e 64 20 49 20 63 61 6d 65')))
INIT_L3_KEY = list(bytes.fromhex(os.environ.get("INIT_L3_KEY", '74 6f 20 54 61 6c 6b 20 77 69 74 68 20 79 6f 75')))
INIT_CA_KEY = list(bytes.fromhex(os.environ.get("INIT_CA_KEY", '61 67 61 69 6e 2c 20 42 65 63 61 75 73 65 20 61')))
if __name__ == '__main__':
print("configs")
......@@ -141,11 +141,12 @@ class ReadCardHandler(tornado.web.RequestHandler):
#try auth_
auth = False
try:
LOGGER.warn("Trying keyA")
card.auth_block(block, TYPE_KEYA, 0)
auth = True
except SWException as e:
LOGGER.warn("Trying keyB")
try:
LOGGER.warn("Trying keyB")
card.auth_block(block, TYPE_KEYB, 1)
auth = True
except SWException as e:
......@@ -219,16 +220,23 @@ class InitCardHandler(tornado.web.RequestHandler):
card.APDU_set_speed()
card.APDU_transcieve([0x26], valid_bits=7) #REQA
adata = card.APDU_transcieve([0x93, 0x20]) #AntiCol1
sak = card.APDU_transcieve([0x93, 0x70] + adata, txrx_flags=0x0F)
if sak == [0x04]: #incomplete
sak = card.APDU_transcieve([0x93, 0x70] + adata, txrx_flags=0x03)
if sak[0] == 0x04: #incomplete
adata2 = card.APDU_transcieve([0x95, 0x20]) #AntiCol1
sak = card.APDU_transcieve([0x95, 0x70] + adata2, txrx_flags=0x0F)
if sak == [0x04]: #incomplete
sak = card.APDU_transcieve([0x95, 0x70] + adata2, txrx_flags=0x03)
if sak[0] == 0x04: #incomplete
adata3 = card.APDU_transcieve([0x97, 0x20]) #AntiCol1
sak = card.APDU_transcieve([0x97, 0x70] + adata3, txrx_flags=0x0F)
sak = card.APDU_transcieve([0x97, 0x70] + adata3, txrx_flags=0x03)
if sak[0] & 0x20: #compliant with iso14443-4 (T=cl commands)
LOGGER.info("iso-4")
ats = card.APDU_transcieve([0xE0, 0x80], txrx_flags=0x0F) #rats
#ats = card.APDU_transcieve([0xE0, 0x80], txrx_flags=0x03) #rats
## init here
card.APDU_transcieve([0xA8, 0x00, 0x90] + config.INIT_CM_KEY, txrx_flags=0x03)
card.APDU_transcieve([0xA8, 0x01, 0x90] + config.INIT_CC_KEY, txrx_flags=0x03)
card.APDU_transcieve([0xA8, 0x02, 0x90] + config.INIT_L2_KEY, txrx_flags=0x03)
card.APDU_transcieve([0xA8, 0x03, 0x90] + config.INIT_L3_KEY, txrx_flags=0x03)
card.APDU_transcieve([0xA8, 0x04, 0x90] + config.INIT_CA_KEY, txrx_flags=0x03)
card.APDU_transcieve([0xAA], txrx_flags=0x03)
except SmartcardException as e:
LOGGER.error("SmartcardException: %s", e)
print(traceback.format_exc())
......
......@@ -1401,7 +1401,7 @@ if __name__ == "__main__":
print(red + "Error: " + atr["warning"] + normal)
print()
card = match_atr_differentiated(ATR)
card = match_atr_differentiated(ATR, "./smartcard_list.txt")
if card:
# exact match
if ATR in card:
......
This diff is collapsed.
......@@ -82,7 +82,7 @@ $(function() {
$("#uiid").text("UUID: " + data.UUIDHex);
$("#reader").text("Lector: " + data.reader);
$("#atr").html("ATR: <a href=\"https://smartcard-atr.apdu.fr/parse?ATR=" + encodeURIComponent(data.ATR) + "\" target=\"_blank\"> " + data.ATR + "</a>");
if (data.ATR_match.length){
if (data.ATR_match.length || data.ATR_possible.length){
$("#atr").append("<h5>Tipo de tarjeta</h5>");
data.ATR_match.forEach(function(e,i){
$("#atr").append((i==0?"<strong class=\"alert-success\">":"") + e + (i==0?"</strong>":"") + "<br/>");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment