From ea88c3da667c1a973527e60328dfe2150d45762f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 4 Jul 2018 14:14:07 +0200 Subject: [PATCH] Catch exception, when no KDF data is found While updating from GNUK 1.2.6, upgrade_by_passwd.py script shows exception about not found referenced data: File "./upgrade_by_passwd.py", line 55, in main kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tostring() File "/home/sz/work/nitrokey-start-firmware/tool/gnuk_token.py", line 320, in cmd_get_data raise ValueError("%02x%02x" % (sw[0], sw[1])) ValueError: 6a88 While it is checked, whether the KDF DO is empty, there is no exception catch for not found object. This patch adds it. Tested update paths 1.2.6 -> 1.2.10, 1.2.6 -> 1.2.6, 1.2.10 -> 1.2.10, 1.2.10 -> 1.2.6. Signed-off-by: Szczepan Zalega --- tool/upgrade_by_passwd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tool/upgrade_by_passwd.py b/tool/upgrade_by_passwd.py index 3e038b5..bc185bb 100755 --- a/tool/upgrade_by_passwd.py +++ b/tool/upgrade_by_passwd.py @@ -51,7 +51,10 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade): gnuk = get_gnuk_device() gnuk.cmd_select_openpgp() # Compute passwd data - kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tostring() + try: + kdf_data = gnuk.cmd_get_data(0x00, 0xf9).tostring() + except: + kdf_data = b"" if kdf_data == b"": passwd_data = passwd.encode('UTF-8') else: