tool: switch to python3
python2 is no longer maintained upstream
This commit is contained in:
committed by
NIIBE Yutaka
parent
c3e9db14e8
commit
81d6945081
@@ -109,15 +109,15 @@ def build_rsakey_from_ssh_key_under_gpg_agent(g, timestamp=None):
|
|||||||
# The information is in SEXP format, extract N and E
|
# The information is in SEXP format, extract N and E
|
||||||
s = sexp(pubkey_info_str)
|
s = sexp(pubkey_info_str)
|
||||||
if s[0] != 'public-key':
|
if s[0] != 'public-key':
|
||||||
print s
|
print(s)
|
||||||
exit(1)
|
exit(1)
|
||||||
rsa = s[1]
|
rsa = s[1]
|
||||||
if rsa[0] != 'rsa':
|
if rsa[0] != 'rsa':
|
||||||
print rsa
|
print(rsa)
|
||||||
exit(1)
|
exit(1)
|
||||||
n_x = rsa[1]
|
n_x = rsa[1]
|
||||||
if n_x[0] != 'n':
|
if n_x[0] != 'n':
|
||||||
print n_x
|
print(n_x)
|
||||||
exit(1)
|
exit(1)
|
||||||
n_byte_str = n_x[1]
|
n_byte_str = n_x[1]
|
||||||
while n_byte_str[0] == '\x00':
|
while n_byte_str[0] == '\x00':
|
||||||
@@ -125,7 +125,7 @@ def build_rsakey_from_ssh_key_under_gpg_agent(g, timestamp=None):
|
|||||||
n = n_byte_str
|
n = n_byte_str
|
||||||
e_x = rsa[2]
|
e_x = rsa[2]
|
||||||
if e_x[0] != 'e':
|
if e_x[0] != 'e':
|
||||||
print e_x
|
print(e_x)
|
||||||
exit(1)
|
exit(1)
|
||||||
e = e_x[1]
|
e = e_x[1]
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
|
|||||||
@@ -8,21 +8,21 @@ def print_nG(n):
|
|||||||
nGy_str = "%064x" % nG.y()
|
nGy_str = "%064x" % nG.y()
|
||||||
print256(nGx_str)
|
print256(nGx_str)
|
||||||
print256(nGy_str)
|
print256(nGy_str)
|
||||||
print
|
print()
|
||||||
|
|
||||||
def print256(s):
|
def print256(s):
|
||||||
print("0x%s, 0x%s, 0x%s, 0x%s," % (s[56:64], s[48:56], s[40:48], s[32:40]))
|
print("0x%s, 0x%s, 0x%s, 0x%s," % (s[56:64], s[48:56], s[40:48], s[32:40]))
|
||||||
print("0x%s, 0x%s, 0x%s, 0x%s" % (s[24:32], s[16:24], s[8:16], s[0:8]))
|
print("0x%s, 0x%s, 0x%s, 0x%s" % (s[24:32], s[16:24], s[8:16], s[0:8]))
|
||||||
print
|
print()
|
||||||
|
|
||||||
|
|
||||||
for i in range(1,16):
|
for i in range(1,16):
|
||||||
n = (i & 1) + (i & 2) * 0x8000000000000000L + (i & 4) * 0x40000000000000000000000000000000L + (i & 8) * 0x200000000000000000000000000000000000000000000000L
|
n = (i & 1) + (i & 2) * 0x8000000000000000 + (i & 4) * 0x40000000000000000000000000000000 + (i & 8) * 0x200000000000000000000000000000000000000000000000
|
||||||
print "%064x" % n
|
print("%064x" % n)
|
||||||
print_nG(n)
|
print_nG(n)
|
||||||
|
|
||||||
for i in range(1,16):
|
for i in range(1,16):
|
||||||
n = (i & 1) + (i & 2) * 0x8000000000000000L + (i & 4) * 0x40000000000000000000000000000000L + (i & 8) * 0x200000000000000000000000000000000000000000000000L
|
n = (i & 1) + (i & 2) * 0x8000000000000000 + (i & 4) * 0x40000000000000000000000000000000 + (i & 8) * 0x200000000000000000000000000000000000000000000000
|
||||||
n = n * 0x100000000L
|
n = n * 0x100000000
|
||||||
print "%064x" % n
|
print("%064x" % n)
|
||||||
print_nG(n)
|
print_nG(n)
|
||||||
|
|||||||
@@ -104,9 +104,9 @@ class DFU_STM32(object):
|
|||||||
interface: usb.Interface object representing the interface and altenate setting.
|
interface: usb.Interface object representing the interface and altenate setting.
|
||||||
"""
|
"""
|
||||||
if interface.interfaceClass != DFU_CLASS:
|
if interface.interfaceClass != DFU_CLASS:
|
||||||
raise ValueError, "Wrong interface class"
|
raise ValueError("Wrong interface class")
|
||||||
if interface.interfaceSubClass != DFU_SUBCLASS:
|
if interface.interfaceSubClass != DFU_SUBCLASS:
|
||||||
raise ValueError, "Wrong interface sub class"
|
raise ValueError("Wrong interface sub class")
|
||||||
self.__protocol = interface.interfaceProtocol
|
self.__protocol = interface.interfaceProtocol
|
||||||
self.__devhandle = device.open()
|
self.__devhandle = device.open()
|
||||||
self.__devhandle.setConfiguration(configuration)
|
self.__devhandle.setConfiguration(configuration)
|
||||||
@@ -170,7 +170,7 @@ class DFU_STM32(object):
|
|||||||
while s[4] == STATE_DFU_DOWNLOAD_BUSY:
|
while s[4] == STATE_DFU_DOWNLOAD_BUSY:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
s = self.ll_get_status()
|
s = self.ll_get_status()
|
||||||
raise ValueError, "Read memory failed (%d)" % s[0]
|
raise ValueError("Read memory failed (%d)" % s[0])
|
||||||
|
|
||||||
def dfuse_set_address_pointer(self, address):
|
def dfuse_set_address_pointer(self, address):
|
||||||
bytes = get_four_bytes (address)
|
bytes = get_four_bytes (address)
|
||||||
@@ -181,7 +181,7 @@ class DFU_STM32(object):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
s = self.ll_get_status()
|
s = self.ll_get_status()
|
||||||
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
||||||
raise ValueError, "Set Address Pointer failed"
|
raise ValueError("Set Address Pointer failed")
|
||||||
|
|
||||||
def dfuse_erase(self, address):
|
def dfuse_erase(self, address):
|
||||||
bytes = get_four_bytes (address)
|
bytes = get_four_bytes (address)
|
||||||
@@ -191,7 +191,7 @@ class DFU_STM32(object):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
s = self.ll_get_status()
|
s = self.ll_get_status()
|
||||||
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
||||||
raise ValueError, "Erase failed"
|
raise ValueError("Erase failed")
|
||||||
|
|
||||||
def dfuse_write_memory(self, block):
|
def dfuse_write_memory(self, block):
|
||||||
blocknum = self.__blocknum
|
blocknum = self.__blocknum
|
||||||
@@ -202,7 +202,7 @@ class DFU_STM32(object):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
s = self.ll_get_status()
|
s = self.ll_get_status()
|
||||||
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
if s[4] != STATE_DFU_DOWNLOAD_IDLE:
|
||||||
raise ValueError, "Write memory failed"
|
raise ValueError("Write memory failed")
|
||||||
|
|
||||||
def download(self, ih):
|
def download(self, ih):
|
||||||
# First, erase pages
|
# First, erase pages
|
||||||
@@ -280,7 +280,7 @@ class DFU_STM32(object):
|
|||||||
elif s[4] == STATE_DFU_MANIFEST_WAIT_RESET:
|
elif s[4] == STATE_DFU_MANIFEST_WAIT_RESET:
|
||||||
self.__devhandle.reset()
|
self.__devhandle.reset()
|
||||||
elif s[4] != STATE_DFU_IDLE:
|
elif s[4] != STATE_DFU_IDLE:
|
||||||
raise ValueError, "write failed (%d)." % s[4]
|
raise ValueError("write failed (%d)." % s[4])
|
||||||
else:
|
else:
|
||||||
self.ll_clear_status()
|
self.ll_clear_status()
|
||||||
self.ll_clear_status()
|
self.ll_clear_status()
|
||||||
@@ -315,7 +315,7 @@ class DFU_STM32(object):
|
|||||||
j = 0
|
j = 0
|
||||||
for c in data[0:(addr + 1024 - start_addr)]:
|
for c in data[0:(addr + 1024 - start_addr)]:
|
||||||
if (ord(c)&0xff) != block[j + start_addr - addr]:
|
if (ord(c)&0xff) != block[j + start_addr - addr]:
|
||||||
raise ValueError, "verify failed at %08x" % (addr + i*1024+j)
|
raise ValueError("verify failed at %08x" % (addr + i*1024+j))
|
||||||
j += 1
|
j += 1
|
||||||
data = data[(addr + 1024 - start_addr):]
|
data = data[(addr + 1024 - start_addr):]
|
||||||
addr += 1024
|
addr += 1024
|
||||||
@@ -330,7 +330,7 @@ class DFU_STM32(object):
|
|||||||
j = 0
|
j = 0
|
||||||
for c in data[i*1024:(i+1)*1024]:
|
for c in data[i*1024:(i+1)*1024]:
|
||||||
if (ord(c)&0xff) != block[j]:
|
if (ord(c)&0xff) != block[j]:
|
||||||
raise ValueError, "verify failed at %08x" % (addr + i*1024+j)
|
raise ValueError("verify failed at %08x" % (addr + i*1024+j))
|
||||||
j += 1
|
j += 1
|
||||||
if i & 0x03 == 0x03:
|
if i & 0x03 == 0x03:
|
||||||
sys.stdout.write("#")
|
sys.stdout.write("#")
|
||||||
@@ -367,25 +367,25 @@ def get_device():
|
|||||||
(alt.interfaceProtocol == DFU_STM32PROTOCOL_0 or \
|
(alt.interfaceProtocol == DFU_STM32PROTOCOL_0 or \
|
||||||
alt.interfaceProtocol == DFU_STM32PROTOCOL_2):
|
alt.interfaceProtocol == DFU_STM32PROTOCOL_2):
|
||||||
return dev, config, alt
|
return dev, config, alt
|
||||||
raise ValueError, "Device not found"
|
raise ValueError("Device not found")
|
||||||
|
|
||||||
def main(filename):
|
def main(filename):
|
||||||
dev, config, intf = get_device()
|
dev, config, intf = get_device()
|
||||||
print "Device:", dev.filename
|
print("Device:", dev.filename)
|
||||||
print "Configuration", config.value
|
print("Configuration", config.value)
|
||||||
print "Interface", intf.interfaceNumber
|
print("Interface", intf.interfaceNumber)
|
||||||
dfu = DFU_STM32(dev, config, intf)
|
dfu = DFU_STM32(dev, config, intf)
|
||||||
print dfu.ll_get_string(intf.iInterface)
|
print(dfu.ll_get_string(intf.iInterface))
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
if s[4] == STATE_DFU_ERROR:
|
if s[4] == STATE_DFU_ERROR:
|
||||||
dfu.ll_clear_status()
|
dfu.ll_clear_status()
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
print s
|
print(s)
|
||||||
if s[4] == STATE_DFU_IDLE:
|
if s[4] == STATE_DFU_IDLE:
|
||||||
exit
|
exit
|
||||||
transfer_size = 1024
|
transfer_size = 1024
|
||||||
if s[0] != DFU_STATUS_OK:
|
if s[0] != DFU_STATUS_OK:
|
||||||
print s
|
print(s)
|
||||||
exit
|
exit
|
||||||
ih = intel_hex(filename)
|
ih = intel_hex(filename)
|
||||||
dfu.download(ih)
|
dfu.download(ih)
|
||||||
|
|||||||
@@ -27,22 +27,22 @@ from dfuse import *
|
|||||||
|
|
||||||
dev, config, intf = get_device()
|
dev, config, intf = get_device()
|
||||||
dfu = DFU_STM32(dev, config, intf)
|
dfu = DFU_STM32(dev, config, intf)
|
||||||
print dfu.ll_get_string(intf.iInterface)
|
print(dfu.ll_get_string(intf.iInterface))
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
dfu.ll_clear_status()
|
dfu.ll_clear_status()
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
print s
|
print(s)
|
||||||
dfu.dfuse_set_address_pointer(int(sys.argv[1], 16))
|
dfu.dfuse_set_address_pointer(int(sys.argv[1], 16))
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
dfu.ll_clear_status()
|
dfu.ll_clear_status()
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
dfu.ll_clear_status()
|
dfu.ll_clear_status()
|
||||||
s = dfu.ll_get_status()
|
s = dfu.ll_get_status()
|
||||||
print s
|
print(s)
|
||||||
block = dfu.dfuse_read_memory()
|
block = dfu.dfuse_read_memory()
|
||||||
count = 0
|
count = 0
|
||||||
for d in block:
|
for d in block:
|
||||||
print "%02x" % d,
|
print("%02x" % d)
|
||||||
if count & 0x0f == 0x0f:
|
if count & 0x0f == 0x0f:
|
||||||
print
|
print
|
||||||
count += 1
|
count += 1
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def get_gpg_public_key(keygrip):
|
|||||||
pos_last = key.index(")(1:e3:")
|
pos_last = key.index(")(1:e3:")
|
||||||
key = key[pos:pos_last]
|
key = key[pos:pos_last]
|
||||||
if len(key) != 256:
|
if len(key) != 256:
|
||||||
raise ValueError, binascii.hexlify(key)
|
raise ValueError(binascii.hexlify(key))
|
||||||
return key
|
return key
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from sexp import sexp
|
|||||||
# Assume it's only OPENPGP.3 key and it's 2048-bit
|
# Assume it's only OPENPGP.3 key and it's 2048-bit
|
||||||
|
|
||||||
def debug(string):
|
def debug(string):
|
||||||
print "DEBUG: %s" % string
|
print("DEBUG: %s" % string)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def get_keygrip_list(keyinfo_result):
|
def get_keygrip_list(keyinfo_result):
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class Card(object):
|
|||||||
elif code == FEATURE_MODIFY_PIN_DIRECT:
|
elif code == FEATURE_MODIFY_PIN_DIRECT:
|
||||||
self.modify_ioctl = ioctl
|
self.modify_ioctl = ioctl
|
||||||
if self.verify_ioctl == -1:
|
if self.verify_ioctl == -1:
|
||||||
raise ValueError, "Not supported"
|
raise ValueError("Not supported")
|
||||||
|
|
||||||
def cmd_select_openpgp(self):
|
def cmd_select_openpgp(self):
|
||||||
apdu = [0x00, 0xa4, 0x04, 0x00, 6, 0xd2, 0x76, 0x00, 0x01, 0x24, 0x01 ]
|
apdu = [0x00, 0xa4, 0x04, 0x00, 6, 0xd2, 0x76, 0x00, 0x01, 0x24, 0x01 ]
|
||||||
@@ -90,7 +90,7 @@ class Card(object):
|
|||||||
if sw1 == 0x61: # More data
|
if sw1 == 0x61: # More data
|
||||||
response, sw1, sw2 = self.connection.transmit([0x00, 0xc0, 0, 0, sw2])
|
response, sw1, sw2 = self.connection.transmit([0x00, 0xc0, 0, 0, sw2])
|
||||||
elif not (sw1 == 0x90 and sw2 == 0x00):
|
elif not (sw1 == 0x90 and sw2 == 0x00):
|
||||||
raise ValueError, ("cmd_select_openpgp %02x %02x" % (sw1, sw2))
|
raise ValueError("cmd_select_openpgp %02x %02x" % (sw1, sw2))
|
||||||
|
|
||||||
def possibly_add_dummy_byte(self):
|
def possibly_add_dummy_byte(self):
|
||||||
if self.another_byte:
|
if self.another_byte:
|
||||||
@@ -135,11 +135,11 @@ class Card(object):
|
|||||||
sw1 = data[0]
|
sw1 = data[0]
|
||||||
sw2 = data[1]
|
sw2 = data[1]
|
||||||
if not (sw1 == 0x90 and sw2 == 0x00):
|
if not (sw1 == 0x90 and sw2 == 0x00):
|
||||||
raise ValueError, ("cmd_verify_pinpad %02x %02x" % (sw1, sw2))
|
raise ValueError("cmd_verify_pinpad %02x %02x" % (sw1, sw2))
|
||||||
|
|
||||||
def send_modify_pinpad(self, apdu, single_step, command):
|
def send_modify_pinpad(self, apdu, single_step, command):
|
||||||
if self.modify_ioctl == -1:
|
if self.modify_ioctl == -1:
|
||||||
raise ValueError, "Not supported"
|
raise ValueError("Not supported")
|
||||||
pin_modify = [ 0x00, # bTimerOut
|
pin_modify = [ 0x00, # bTimerOut
|
||||||
0x00, # bTimerOut2
|
0x00, # bTimerOut2
|
||||||
0x82, # bmFormatString: Byte, pos=0, left, ASCII.
|
0x82, # bmFormatString: Byte, pos=0, left, ASCII.
|
||||||
@@ -171,7 +171,7 @@ class Card(object):
|
|||||||
sw1 = data[0]
|
sw1 = data[0]
|
||||||
sw2 = data[1]
|
sw2 = data[1]
|
||||||
if not (sw1 == 0x90 and sw2 == 0x00):
|
if not (sw1 == 0x90 and sw2 == 0x00):
|
||||||
raise ValueError, ("%s %02x %02x" % (command, sw1, sw2))
|
raise ValueError("%s %02x %02x" % (command, sw1, sw2))
|
||||||
|
|
||||||
def cmd_reset_retry_counter(self, who, data):
|
def cmd_reset_retry_counter(self, who, data):
|
||||||
if who == BY_ADMIN:
|
if who == BY_ADMIN:
|
||||||
@@ -180,7 +180,7 @@ class Card(object):
|
|||||||
apdu = [0x00, 0x2c, 0x00, 0x81, len(data) ] + data # BY_USER with resetcode
|
apdu = [0x00, 0x2c, 0x00, 0x81, len(data) ] + data # BY_USER with resetcode
|
||||||
response, sw1, sw2 = self.connection.transmit(apdu)
|
response, sw1, sw2 = self.connection.transmit(apdu)
|
||||||
if not (sw1 == 0x90 and sw2 == 0x00):
|
if not (sw1 == 0x90 and sw2 == 0x00):
|
||||||
raise ValueError, ("cmd_reset_retry_counter %02x %02x" % (sw1, sw2))
|
raise ValueError("cmd_reset_retry_counter %02x %02x" % (sw1, sw2))
|
||||||
|
|
||||||
# Note: CCID specification doesn't permit this (only 0x20 and 0x24)
|
# Note: CCID specification doesn't permit this (only 0x20 and 0x24)
|
||||||
def cmd_reset_retry_counter_pinpad(self, who):
|
def cmd_reset_retry_counter_pinpad(self, who):
|
||||||
@@ -195,7 +195,7 @@ class Card(object):
|
|||||||
apdu = [0x00, 0xda, 0x00, 0xd3, len(data) ] + data # BY_ADMIN
|
apdu = [0x00, 0xda, 0x00, 0xd3, len(data) ] + data # BY_ADMIN
|
||||||
response, sw1, sw2 = self.connection.transmit(apdu)
|
response, sw1, sw2 = self.connection.transmit(apdu)
|
||||||
if not (sw1 == 0x90 and sw2 == 0x00):
|
if not (sw1 == 0x90 and sw2 == 0x00):
|
||||||
raise ValueError, ("cmd_put_resetcode %02x %02x" % (sw1, sw2))
|
raise ValueError("cmd_put_resetcode %02x %02x" % (sw1, sw2))
|
||||||
|
|
||||||
# Note: CCID specification doesn't permit this (only 0x20 and 0x24)
|
# Note: CCID specification doesn't permit this (only 0x20 and 0x24)
|
||||||
def cmd_put_resetcode_pinpad(self):
|
def cmd_put_resetcode_pinpad(self):
|
||||||
@@ -225,8 +225,8 @@ def main(who, method, add_a_byte, pinmin, pinmax, change_by_two_steps, fixed):
|
|||||||
card.connection.connect()
|
card.connection.connect()
|
||||||
|
|
||||||
ident = card.connection.getReader()
|
ident = card.connection.getReader()
|
||||||
print "Reader/Token:", ident
|
print("Reader/Token:", ident)
|
||||||
print "ATR:", toHexString( card.connection.getATR() )
|
print("ATR:", toHexString( card.connection.getATR() ))
|
||||||
|
|
||||||
if ident == COVADIS_VEGA_ALPHA:
|
if ident == COVADIS_VEGA_ALPHA:
|
||||||
card.cmd_vega_alpha_disable_empty_verify()
|
card.cmd_vega_alpha_disable_empty_verify()
|
||||||
@@ -236,29 +236,29 @@ def main(who, method, add_a_byte, pinmin, pinmax, change_by_two_steps, fixed):
|
|||||||
card.cmd_select_openpgp()
|
card.cmd_select_openpgp()
|
||||||
if method == "verify":
|
if method == "verify":
|
||||||
if who == BY_USER:
|
if who == BY_USER:
|
||||||
print "Please input User's PIN"
|
print("Please input User's PIN")
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(who)
|
card.cmd_verify_pinpad(who)
|
||||||
elif method == "change":
|
elif method == "change":
|
||||||
if change_by_two_steps:
|
if change_by_two_steps:
|
||||||
if who == BY_USER:
|
if who == BY_USER:
|
||||||
print "Please input User's PIN"
|
print("Please input User's PIN")
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(who)
|
card.cmd_verify_pinpad(who)
|
||||||
if who == BY_USER:
|
if who == BY_USER:
|
||||||
print "Please input New User's PIN twice"
|
print("Please input New User's PIN twice")
|
||||||
else:
|
else:
|
||||||
print "Please input New Admin's PIN twice"
|
print("Please input New Admin's PIN twice")
|
||||||
card.cmd_change_reference_data_pinpad(who, True)
|
card.cmd_change_reference_data_pinpad(who, True)
|
||||||
else:
|
else:
|
||||||
if who == BY_USER:
|
if who == BY_USER:
|
||||||
print "Please input User's PIN"
|
print("Please input User's PIN")
|
||||||
print "and New User's PIN twice"
|
print("and New User's PIN twice")
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
print "and New Admin's PIN twice"
|
print("and New Admin's PIN twice")
|
||||||
card.cmd_change_reference_data_pinpad(who, False)
|
card.cmd_change_reference_data_pinpad(who, False)
|
||||||
elif method == "unblock":
|
elif method == "unblock":
|
||||||
if change_by_two_steps:
|
if change_by_two_steps:
|
||||||
@@ -268,66 +268,66 @@ def main(who, method, add_a_byte, pinmin, pinmax, change_by_two_steps, fixed):
|
|||||||
newpin=s2l(getpass("Please input New User's PIN from keyboard: "))
|
newpin=s2l(getpass("Please input New User's PIN from keyboard: "))
|
||||||
card.cmd_reset_retry_counter(who,resetcode+newpin)
|
card.cmd_reset_retry_counter(who,resetcode+newpin)
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(BY_ADMIN)
|
card.cmd_verify_pinpad(BY_ADMIN)
|
||||||
newpin=s2l(getpass("Please input New User's PIN from keyboard: "))
|
newpin=s2l(getpass("Please input New User's PIN from keyboard: "))
|
||||||
card.cmd_reset_retry_counter(who,newpin)
|
card.cmd_reset_retry_counter(who,newpin)
|
||||||
else:
|
else:
|
||||||
if who == BY_USER:
|
if who == BY_USER:
|
||||||
print "Please input reset code"
|
print("Please input reset code")
|
||||||
print "and New User's PIN twice"
|
print("and New User's PIN twice")
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(BY_ADMIN)
|
card.cmd_verify_pinpad(BY_ADMIN)
|
||||||
print "Please input New User's PIN twice"
|
print("Please input New User's PIN twice")
|
||||||
card.cmd_reset_retry_counter_pinpad(who)
|
card.cmd_reset_retry_counter_pinpad(who)
|
||||||
elif method == "put":
|
elif method == "put":
|
||||||
if change_by_two_steps:
|
if change_by_two_steps:
|
||||||
# It means using keyboard for new PIN
|
# It means using keyboard for new PIN
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(BY_ADMIN)
|
card.cmd_verify_pinpad(BY_ADMIN)
|
||||||
resetcode=s2l(getpass("Please input New Reset Code from keyboard: "))
|
resetcode=s2l(getpass("Please input New Reset Code from keyboard: "))
|
||||||
card.cmd_put_resetcode(resetcode)
|
card.cmd_put_resetcode(resetcode)
|
||||||
else:
|
else:
|
||||||
print "Please input Admin's PIN"
|
print("Please input Admin's PIN")
|
||||||
card.cmd_verify_pinpad(BY_ADMIN)
|
card.cmd_verify_pinpad(BY_ADMIN)
|
||||||
print "Please input New Reset Code twice"
|
print("Please input New Reset Code twice")
|
||||||
card.cmd_put_resetcode_pinpad()
|
card.cmd_put_resetcode_pinpad()
|
||||||
else:
|
else:
|
||||||
raise ValueError, method
|
raise ValueError(method)
|
||||||
card.connection.disconnect()
|
card.connection.disconnect()
|
||||||
|
|
||||||
print "OK."
|
print("OK.")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print "pinpad-test: testing pinentry of PC/SC card reader"
|
print("pinpad-test: testing pinentry of PC/SC card reader")
|
||||||
print " help:"
|
print(" help:")
|
||||||
print "\t--help:\t\tthis message"
|
print("\t--help:\t\tthis message")
|
||||||
print " method:\t\t\t\t\t\t\t[verify]"
|
print(" method:\t\t\t\t\t\t\t[verify]")
|
||||||
print "\t--verify:\tverify PIN"
|
print("\t--verify:\tverify PIN")
|
||||||
print "\t--change:\tchange PIN (old PIN, new PIN twice)"
|
print("\t--change:\tchange PIN (old PIN, new PIN twice)")
|
||||||
print "\t--change2:\tchange PIN by two steps (old PIN, new PIN twice)"
|
print("\t--change2:\tchange PIN by two steps (old PIN, new PIN twice)")
|
||||||
print "\t--unblock:\tunblock PIN (admin PIN/resetcode, new PIN twice)"
|
print("\t--unblock:\tunblock PIN (admin PIN/resetcode, new PIN twice)")
|
||||||
print "\t--unblock2:\tunblock PIN (admin PIN:pinpad, new PIN:kbd)"
|
print("\t--unblock2:\tunblock PIN (admin PIN:pinpad, new PIN:kbd)")
|
||||||
print "\t--put:\t\tsetup resetcode (admin PIN, new PIN twice)"
|
print("\t--put:\t\tsetup resetcode (admin PIN, new PIN twice)")
|
||||||
print "\t--put2::\t\tsetup resetcode (admin PIN:pinpad, new PIN:kbd)"
|
print("\t--put2::\t\tsetup resetcode (admin PIN:pinpad, new PIN:kbd)")
|
||||||
print " options:"
|
print(" options:")
|
||||||
print "\t--fixed N:\tUse fixed length input"
|
print("\t--fixed N:\tUse fixed length input")
|
||||||
print "\t--admin:\tby administrator\t\t\t[False]"
|
print("\t--admin:\tby administrator\t\t\t[False]")
|
||||||
print "\t--add:\t\tadd a dummy byte at the end of APDU\t[False]"
|
print("\t--add:\t\tadd a dummy byte at the end of APDU\t[False]")
|
||||||
print "\t--pinmin:\tspecify minimum length of PIN\t\t[6]"
|
print("\t--pinmin:\tspecify minimum length of PIN\t\t[6]")
|
||||||
print "\t--pinmax:\tspecify maximum length of PIN\t\t[15]"
|
print("\t--pinmax:\tspecify maximum length of PIN\t\t[15]")
|
||||||
print "EXAMPLES:"
|
print("EXAMPLES:")
|
||||||
print " $ pinpad-test # verify user's PIN "
|
print(" $ pinpad-test # verify user's PIN ")
|
||||||
print " $ pinpad-test --admin # verify admin's PIN "
|
print(" $ pinpad-test --admin # verify admin's PIN ")
|
||||||
print " $ pinpad-test --change # change user's PIN "
|
print(" $ pinpad-test --change # change user's PIN ")
|
||||||
print " $ pinpad-test --change --admin # change admin's PIN "
|
print(" $ pinpad-test --change --admin # change admin's PIN ")
|
||||||
print " $ pinpad-test --change2 # change user's PIN by two steps"
|
print(" $ pinpad-test --change2 # change user's PIN by two steps")
|
||||||
print " $ pinpad-test --change2 --admin # change admin's PIN by two steps"
|
print(" $ pinpad-test --change2 --admin # change admin's PIN by two steps")
|
||||||
print " $ pinpad-test --unblock # change user's PIN by reset code"
|
print(" $ pinpad-test --unblock # change user's PIN by reset code")
|
||||||
print " $ pinpad-test --unblock --admin # change user's PIN by admin's PIN"
|
print(" $ pinpad-test --unblock --admin # change user's PIN by admin's PIN")
|
||||||
print " $ pinpad-test --put # setup resetcode "
|
print(" $ pinpad-test --put # setup resetcode ")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
who = BY_USER
|
who = BY_USER
|
||||||
@@ -374,7 +374,7 @@ if __name__ == '__main__':
|
|||||||
print_usage()
|
print_usage()
|
||||||
exit(0)
|
exit(0)
|
||||||
else:
|
else:
|
||||||
raise ValueError, option
|
raise ValueError(option)
|
||||||
main(who, method, add_a_byte, pinmin, pinmax, change_by_two_steps, fixed)
|
main(who, method, add_a_byte, pinmin, pinmax, change_by_two_steps, fixed)
|
||||||
|
|
||||||
# Failure
|
# Failure
|
||||||
|
|||||||
Reference in New Issue
Block a user