From 4db7bb38c52971a230df7a35956e566115d9001e Mon Sep 17 00:00:00 2001 From: Jarno Elonen Date: Mon, 29 Jul 2024 10:49:07 +0300 Subject: [PATCH] Use unicurses instad of curses, for Windows compat --- hsm_secrets/utils.py | 21 +++++++++++---------- hsm_secrets/x509/__init__.py | 3 ++- requirements.txt | 2 ++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hsm_secrets/utils.py b/hsm_secrets/utils.py index 52c2512..2449399 100644 --- a/hsm_secrets/utils.py +++ b/hsm_secrets/utils.py @@ -20,7 +20,7 @@ import yubikit.hsmauth as hsmauth import hsm_secrets.config as hscfg -import curses +import unicurses as curses import click from functools import wraps @@ -425,25 +425,26 @@ def secure_display_secret(secret_to_show: str, wipe_char='x'): """ secret = secret_to_show + " " def do_it(stdscr): - stdscr.clear() + from unicurses import getmaxyx, clear, box, mvwaddstr, wrefresh + clear() # Create a new window - height, width = stdscr.getmaxyx() + height, width = getmaxyx(stdscr) win_height = 3 win_width = len(secret) + 4 win = curses.newwin(win_height, win_width, height // 2 - 1, width // 2 - win_width // 2) # Display the secret - win.box() - win.addstr(1, 2, secret) - win.refresh() + box(win) + mvwaddstr(win, 1, 2, secret) + wrefresh(win) click.pause("") # Wait for ENTER key # Overwrite the secret with wipe_char - stdscr.clear() - win.box() - win.addstr(1, 2, wipe_char * len(secret)) - win.refresh() + clear() + box(win) + mvwaddstr(win, 1, 2, wipe_char * len(secret)) + wrefresh(win) curses.wrapper(do_it) diff --git a/hsm_secrets/x509/__init__.py b/hsm_secrets/x509/__init__.py index dd2448d..94b0dc3 100644 --- a/hsm_secrets/x509/__init__.py +++ b/hsm_secrets/x509/__init__.py @@ -119,7 +119,8 @@ def _do_it(ses: HSMSession|None): for cd in creation_order: x509_info = merge_x509_info_with_defaults(scid_to_x509_def[cd.id].x509_info, ctx.conf) issuer = scid_to_opq_def[cd.sign_by] if cd.sign_by and cd.sign_by != cd.id else None - cli_info(f"Creating 0x{cd.id:04x}: '{cd.label}' ({f"signed by: '{issuer.label}'" if issuer else 'self-signed'})") + signer = f"signed by: '{issuer.label}'" if issuer else 'self-signed' + cli_info(f"Creating 0x{cd.id:04x}: '{cd.label}' ({signer})") cli_info(indent(pretty_x509_info(x509_info), " ")) if not dry_run: diff --git a/requirements.txt b/requirements.txt index 55c05db..2169567 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,5 @@ pyescrypt pycryptodome yubihsm-ssh-tool @ git+https://github.com/YubicoLabs/yubihsm-ssh-tool@9cec861 + +uni-curses