def main(passwd): gnuk = None for (dev, config, intf) in gnuk_devices(): try: gnuk = gnuk_token(dev, config, intf) print("Device: %s" % dev.filename) print("Configuration: %d" % config.value) print("Interface: %d" % intf.interfaceNumber) break except: pass if gnuk.icc_get_status() == 2: raise ValueError("No ICC present") elif gnuk.icc_get_status() == 1: gnuk.icc_power_on() gnuk.cmd_select_openpgp() gnuk.cmd_verify(BY_ADMIN, passwd.encode('UTF-8')) gnuk.cmd_select_openpgp() gnuk.cmd_put_data_remove(0x00, 0xc7) # FP_SIG gnuk.cmd_put_data_remove(0x00, 0xce) # KGTIME_SIG gnuk.cmd_put_data_key_import_remove(1) gnuk.cmd_put_data_remove(0x00, 0xc8) # FP_DEC gnuk.cmd_put_data_remove(0x00, 0xcf) # KGTIME_DEC gnuk.cmd_put_data_key_import_remove(2) gnuk.cmd_put_data_remove(0x00, 0xc9) # FP_AUT gnuk.cmd_put_data_remove(0x00, 0xd0) # KGTIME_AUT gnuk.cmd_put_data_key_import_remove(3) gnuk.icc_power_off() return 0
def main(fileid, is_update, data, passwd): gnuk = None for (dev, config, intf) in gnuk_devices(): try: gnuk = gnuk_token(dev, config, intf) print("Device: %s" % dev.filename) print("Configuration: %d" % config.value) print("Interface: %d" % intf.interfaceNumber) break except: pass if gnuk.icc_get_status() == 2: raise ValueError("No ICC present") elif gnuk.icc_get_status() == 1: gnuk.icc_power_on() gnuk.cmd_verify(BY_ADMIN, passwd.encode('UTF-8')) gnuk.cmd_write_binary(fileid, data, is_update) gnuk.cmd_select_openpgp() if fileid == 0: data_in_device = gnuk.cmd_get_data(0x00, 0x4f) print(' '.join(["%02x" % d for d in data_in_device])) compare(data + b'\x00\x00', data_in_device[8:].tostring()) elif fileid >= 1 and fileid <= 4: data_in_device = gnuk.cmd_read_binary(fileid) compare(data, data_in_device) else: data_in_device = gnuk.cmd_get_data(0x7f, 0x21) compare(data, data_in_device) gnuk.icc_power_off() return 0
def main(fileid, is_update, data, passwd): gnuk = None for (dev, config, intf) in gnuk_devices(): try: gnuk = gnuk_token(dev, config, intf) print "Device: ", dev.filename print "Configuration: ", config.value print "Interface: ", intf.interfaceNumber break except: pass if gnuk.icc_get_status() == 2: raise ValueError, "No ICC present" elif gnuk.icc_get_status() == 1: gnuk.icc_power_on() gnuk.cmd_verify(BY_ADMIN, passwd) gnuk.cmd_write_binary(fileid, data, is_update) gnuk.cmd_select_openpgp() if fileid == 0: data_in_device = gnuk.cmd_get_data(0x00, 0x4f) for d in data_in_device: print "%02x" % ord(d), print compare(data + '\x00\x00', data_in_device[8:]) elif fileid >= 1 and fileid <= 4: data_in_device = gnuk.cmd_read_binary(fileid) compare(data, data_in_device) else: data_in_device = gnuk.cmd_get_data(0x7f, 0x21) compare(data, data_in_device) gnuk.icc_power_off() return 0
def main(fileid, is_update, data, passwd): gnuk = None for (dev, config, intf) in gnuk_devices(): try: gnuk = gnuk_token(dev, config, intf) print("Device: %s" % dev.filename) print("Configuration: %d" % config.value) print("Interface: %d" % intf.interfaceNumber) break except: pass if gnuk.icc_get_status() == 2: raise ValueError("No ICC present") elif gnuk.icc_get_status() == 1: gnuk.icc_power_on() gnuk.cmd_select_openpgp() gnuk.cmd_verify(BY_ADMIN, passwd.encode('UTF-8')) gnuk.cmd_write_binary(fileid, data, is_update) gnuk.cmd_select_openpgp() if fileid == 0: data_in_device = gnuk.cmd_get_data(0x00, 0x4f) print(' '.join([ "%02x" % d for d in data_in_device ])) compare(data + b'\x00\x00', data_in_device[8:].tostring()) elif fileid >= 1 and fileid <= 4: data_in_device = gnuk.cmd_read_binary(fileid) compare(data, data_in_device) else: data_in_device = gnuk.cmd_get_data(0x7f, 0x21) compare(data, data_in_device) gnuk.icc_power_off() return 0
def main(keyno, keygrip, data_regnual, data_upgrade): l = len(data_regnual) if (l & 0x03) != 0: data_regnual = data_regnual.ljust(l + 4 - (l & 0x03), b'\x00') crc32code = crc32(data_regnual) print("CRC32: %04x\n" % crc32code) data_regnual += pack('<I', crc32code) for (dev, config, intf) in gnuk_devices(): try: icc = gnuk_token(dev, config, intf) print("Device: %s" % dev.filename) print("Configuration: %d" % config.value) print("Interface: %d" % intf.interfaceNumber) break except: icc = None if icc.icc_get_status() == 2: raise ValueError("No ICC present") elif icc.icc_get_status() == 1: icc.icc_power_on() icc.cmd_select_openpgp() challenge = icc.cmd_get_challenge().tostring() signed = gpg_sign(keygrip, binascii.hexlify(challenge)) icc.cmd_external_authenticate(keyno, signed) icc.stop_gnuk() mem_info = icc.mem_info() print("%08x:%08x" % mem_info) print("Downloading flash upgrade program...") icc.download(mem_info[0], data_regnual) print("Run flash upgrade program...") icc.execute(mem_info[0] + len(data_regnual) - 4) # time.sleep(3) icc.reset_device() del icc icc = None # print("Wait 3 seconds...") time.sleep(3) # Then, send upgrade program... reg = None for dev in gnuk_devices_by_vidpid(): try: reg = regnual(dev) print("Device: %d" % dev.filename) break except: pass mem_info = reg.mem_info() print("%08x:%08x" % mem_info) print("Downloading the program") reg.download(mem_info[0], data_upgrade) reg.protect() reg.finish() reg.reset_device() return 0
def main(keyno,keygrip, data_regnual, data_upgrade): l = len(data_regnual) if (l & 0x03) != 0: data_regnual = data_regnual.ljust(l + 4 - (l & 0x03), b'\x00') crc32code = crc32(data_regnual) print("CRC32: %04x\n" % crc32code) data_regnual += pack('<I', crc32code) for (dev, config, intf) in gnuk_devices(): try: icc = gnuk_token(dev, config, intf) print("Device: %s" % dev.filename) print("Configuration: %d" % config.value) print("Interface: %d" % intf.interfaceNumber) break except: icc = None if icc.icc_get_status() == 2: raise ValueError("No ICC present") elif icc.icc_get_status() == 1: icc.icc_power_on() icc.cmd_select_openpgp() challenge = icc.cmd_get_challenge().tostring() signed = gpg_sign(keygrip, binascii.hexlify(challenge)) icc.cmd_external_authenticate(keyno, signed) icc.stop_gnuk() mem_info = icc.mem_info() print("%08x:%08x" % mem_info) print("Downloading flash upgrade program...") icc.download(mem_info[0], data_regnual) print("Run flash upgrade program...") icc.execute(mem_info[0] + len(data_regnual) - 4) # time.sleep(3) icc.reset_device() del icc icc = None # print("Wait 3 seconds...") time.sleep(3) # Then, send upgrade program... reg = None for dev in gnuk_devices_by_vidpid(): try: reg = regnual(dev) print("Device: %d" % dev.filename) break except: pass mem_info = reg.mem_info() print("%08x:%08x" % mem_info) print("Downloading the program") reg.download(mem_info[0], data_upgrade) reg.protect() reg.finish() reg.reset_device() return 0