From 04238509ee42d774d7fbd66b3d75382de4330078 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 6 Nov 2023 11:48:32 +0100 Subject: [PATCH] Generate a secure key if it is not found. Should fix #23. Signed-off-by: Pol Henarejos --- tools/pico-fido-tool.py | 2 +- tools/secure_key/macos.py | 4 +++- tools/secure_key/windows.py | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/pico-fido-tool.py b/tools/pico-fido-tool.py index a12bce1..89d1615 100644 --- a/tools/pico-fido-tool.py +++ b/tools/pico-fido-tool.py @@ -442,7 +442,7 @@ def attestation(vdr, args): vdr.upload_ea(cert.public_bytes(Encoding.DER)) def main(args): - print('Pico Fido Tool v1.5') + print('Pico Fido Tool v1.6') print('Author: Pol Henarejos') print('Report bugs to https://github.com/polhenarejos/pico-fido/issues') print('') diff --git a/tools/secure_key/macos.py b/tools/secure_key/macos.py index 381ee21..1ccc1a4 100644 --- a/tools/secure_key/macos.py +++ b/tools/secure_key/macos.py @@ -51,7 +51,9 @@ def get_secure_key(): try: backend = get_backend(False) key = backend.get_password(DOMAIN, USERNAME)[0] - except keyring.errors.KeyringError: + if (key is None): + raise TypeError + except (keyring.errors.KeyringError, TypeError): try: key = generate_secure_key(False)[0] # It should be True, but secure enclave causes python segfault except keyring.errors.PasswordSetError: diff --git a/tools/secure_key/windows.py b/tools/secure_key/windows.py index d1c5845..844190a 100644 --- a/tools/secure_key/windows.py +++ b/tools/secure_key/windows.py @@ -1,6 +1,4 @@ import sys -import os -import base64 DOMAIN = "PicoKeys.com" USERNAME = "Pico-Fido" @@ -39,6 +37,8 @@ def get_secure_key(): key = None try: key = keyring.get_password(DOMAIN, USERNAME) - except keyring.errors.KeyringError: + if (key is None): + raise TypeError + except (keyring.errors.KeyringError, TypeError): key = generate_secure_key() return get_d(key.encode())