Initial commit
This commit is contained in:
75
debug_select.py
Normal file
75
debug_select.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Quick diagnostic: test SELECT on the card currently on the reader."""
|
||||
from smartcard.System import readers
|
||||
from smartcard.util import toHexString
|
||||
from smartcard.Exceptions import CardConnectionException, NoCardException
|
||||
|
||||
TESLA_VCSEC_AID = [0xF4, 0x65, 0x73, 0x6C, 0x61, 0x4C, 0x6F, 0x67, 0x69, 0x63]
|
||||
GET_UID_APDU = [0xFF, 0xCA, 0x00, 0x00, 0x00]
|
||||
GET_PUBLIC_KEY_APDU = [0x80, 0x04, 0x00, 0x00, 0x00]
|
||||
|
||||
r = readers()
|
||||
print(f"Readers: {r}")
|
||||
reader = r[0]
|
||||
|
||||
# --- Test 1: fresh connection, SELECT directly (no UID read first) ---
|
||||
print("\n=== Test 1: Fresh connect -> SELECT (no UID read) ===")
|
||||
try:
|
||||
conn = reader.createConnection()
|
||||
conn.connect()
|
||||
select_apdu = [0x00, 0xA4, 0x04, 0x00, len(TESLA_VCSEC_AID)] + TESLA_VCSEC_AID
|
||||
print(f" APDU: {toHexString(select_apdu)}")
|
||||
resp, sw1, sw2 = conn.transmit(select_apdu)
|
||||
print(f" Response: {toHexString(resp) if resp else '(empty)'}")
|
||||
print(f" SW: {sw1:02X} {sw2:02X}")
|
||||
conn.disconnect()
|
||||
except Exception as e:
|
||||
print(f" EXCEPTION: {type(e).__name__}: {e}")
|
||||
|
||||
# --- Test 2: connect, read UID, then SELECT (same connection) ---
|
||||
print("\n=== Test 2: Connect -> UID -> SELECT (same connection) ===")
|
||||
try:
|
||||
conn = reader.createConnection()
|
||||
conn.connect()
|
||||
resp, sw1, sw2 = conn.transmit(GET_UID_APDU)
|
||||
print(f" UID: {toHexString(resp)} (SW: {sw1:02X} {sw2:02X})")
|
||||
select_apdu = [0x00, 0xA4, 0x04, 0x00, len(TESLA_VCSEC_AID)] + TESLA_VCSEC_AID
|
||||
resp, sw1, sw2 = conn.transmit(select_apdu)
|
||||
print(f" SELECT Response: {toHexString(resp) if resp else '(empty)'}")
|
||||
print(f" SELECT SW: {sw1:02X} {sw2:02X}")
|
||||
conn.disconnect()
|
||||
except Exception as e:
|
||||
print(f" EXCEPTION: {type(e).__name__}: {e}")
|
||||
|
||||
# --- Test 3: connect, read UID, disconnect, reconnect, then SELECT ---
|
||||
print("\n=== Test 3: Connect -> UID -> disconnect -> reconnect -> SELECT ===")
|
||||
try:
|
||||
conn = reader.createConnection()
|
||||
conn.connect()
|
||||
resp, sw1, sw2 = conn.transmit(GET_UID_APDU)
|
||||
print(f" UID: {toHexString(resp)} (SW: {sw1:02X} {sw2:02X})")
|
||||
conn.disconnect()
|
||||
conn = reader.createConnection()
|
||||
conn.connect()
|
||||
select_apdu = [0x00, 0xA4, 0x04, 0x00, len(TESLA_VCSEC_AID)] + TESLA_VCSEC_AID
|
||||
resp, sw1, sw2 = conn.transmit(select_apdu)
|
||||
print(f" SELECT Response: {toHexString(resp) if resp else '(empty)'}")
|
||||
print(f" SELECT SW: {sw1:02X} {sw2:02X}")
|
||||
conn.disconnect()
|
||||
except Exception as e:
|
||||
print(f" EXCEPTION: {type(e).__name__}: {e}")
|
||||
|
||||
# --- Test 4: SELECT + GET PUBLIC KEY ---
|
||||
print("\n=== Test 4: SELECT + GET PUBLIC KEY ===")
|
||||
try:
|
||||
conn = reader.createConnection()
|
||||
conn.connect()
|
||||
select_apdu = [0x00, 0xA4, 0x04, 0x00, len(TESLA_VCSEC_AID)] + TESLA_VCSEC_AID
|
||||
resp, sw1, sw2 = conn.transmit(select_apdu)
|
||||
print(f" SELECT SW: {sw1:02X} {sw2:02X}")
|
||||
if (sw1, sw2) == (0x90, 0x00):
|
||||
resp, sw1, sw2 = conn.transmit(GET_PUBLIC_KEY_APDU)
|
||||
print(f" PUBKEY Response: {toHexString(resp) if resp else '(empty)'}")
|
||||
print(f" PUBKEY SW: {sw1:02X} {sw2:02X}")
|
||||
conn.disconnect()
|
||||
except Exception as e:
|
||||
print(f" EXCEPTION: {type(e).__name__}: {e}")
|
||||
Reference in New Issue
Block a user