Python3 update things.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2021-02-19 13:12:48 +09:00
parent 8822fcae77
commit 4d15700580
6 changed files with 36 additions and 25 deletions

View File

@@ -1,5 +1,14 @@
2021-02-19 NIIBE Yutaka <gniibe@fsij.org>
* tool/upgrade_by_passwd.py (main): Use tobytes.
* tool/gnuk_get_random.py: Likewise.
* tool/gnuk_remove_keys_libusb.py (main): Likewise.
Switch to Python3.
* tool/gnuk_put_binary_libusb.py (main): Use tobytes.
Switch to Python3.
* tool/gnuk_upgrade.py (main): Use tobytes.
Switch to Python3.
* chopstx: Update to 1.19.
2021-02-18 Vincent Pelletier <plr.vincent@gmail.com>

View File

@@ -11,7 +11,7 @@ if __name__ == '__main__':
looping = (len(sys.argv) > 1)
while True:
try:
challenge = gnuk.cmd_get_challenge().tostring()
challenge = gnuk.cmd_get_challenge().tobytes()
except Exception as e:
print(count)
raise e

View File

@@ -1,10 +1,10 @@
#! /usr/bin/python
#! /usr/bin/python3
"""
gnuk_put_binary.py - a tool to put binary to Gnuk Token
This tool is for importing certificate, writing serial number, etc.
Copyright (C) 2011, 2012 Free Software Initiative of Japan
Copyright (C) 2011, 2012, 2021 Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org>
This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -56,7 +56,7 @@ def main(fileid, is_update, data, passwd):
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())
compare(data + b'\x00\x00', data_in_device[8:].tobytes())
elif fileid >= 1 and fileid <= 4:
data_in_device = gnuk.cmd_read_binary(fileid)
compare(data, data_in_device)

View File

@@ -1,9 +1,9 @@
#! /usr/bin/python
#! /usr/bin/python3
"""
gnuk_remove_keys_libusb.py - a tool to remove keys in Gnuk Token
Copyright (C) 2012, 2018 Free Software Initiative of Japan
Copyright (C) 2012, 2018, 2021 Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org>
This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -51,7 +51,7 @@ def main(passwd):
gnuk.icc_power_on()
gnuk.cmd_select_openpgp()
# Compute passwd data
kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tostring()
kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tobytes()
if kdf_data == b"":
passwd_data = passwd.encode('UTF-8')
else:

View File

@@ -1,9 +1,9 @@
#! /usr/bin/python
#! /usr/bin/python3
"""
gnuk_upgrade.py - a tool to upgrade firmware of Gnuk Token
Copyright (C) 2012, 2015 Free Software Initiative of Japan
Copyright (C) 2012, 2015, 2021 Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org>
This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -70,7 +70,7 @@ def gpg_sign(keygrip, hash):
raise ValueError(binascii.hexlify(signed))
return signed
def main(keyno,keygrip, data_regnual, data_upgrade):
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')
@@ -91,7 +91,7 @@ def main(keyno,keygrip, data_regnual, data_upgrade):
elif icc.icc_get_status() == 1:
icc.icc_power_on()
icc.cmd_select_openpgp()
challenge = icc.cmd_get_challenge().tostring()
challenge = icc.cmd_get_challenge().tobytes()
signed = gpg_sign(keygrip, binascii.hexlify(challenge))
icc.cmd_external_authenticate(keyno, signed)
icc.stop_gnuk()
@@ -107,17 +107,19 @@ def main(keyno,keygrip, data_regnual, data_upgrade):
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
print("Waiting for device to appear:")
while reg == None:
print(" Wait {} second{}...".format(wait_e, 's' if wait_e > 1 else ''))
time.sleep(wait_e)
for dev in gnuk_devices_by_vidpid():
try:
reg = regnual(dev)
print("Device: %s" % dev.filename)
break
except:
pass
# Then, send upgrade program...
mem_info = reg.mem_info()
print("%08x:%08x" % mem_info)
print("Downloading the program")

View File

@@ -1,10 +1,10 @@
#! /usr/bin/python
#! /usr/bin/python3
"""
upgrade_by_passwd.py - a tool to install another firmware for Gnuk Token
which is just shipped from factory
Copyright (C) 2012, 2013, 2015, 2018
Copyright (C) 2012, 2013, 2015, 2018, 2021
Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org>
@@ -52,7 +52,7 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
gnuk.cmd_select_openpgp()
# Compute passwd data
try:
kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tostring()
kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tobytes()
except:
kdf_data = b""
if kdf_data == b"":
@@ -70,7 +70,7 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
gnuk.cmd_write_binary(1+keyno, rsa_raw_pubkey, False)
gnuk.cmd_select_openpgp()
challenge = gnuk.cmd_get_challenge().tostring()
challenge = gnuk.cmd_get_challenge().tobytes()
digestinfo = binascii.unhexlify(SHA256_OID_PREFIX) + challenge
signed = rsa.compute_signature(rsa_key, digestinfo)
signed_bytes = rsa.integer_to_bytes_256(signed)