Skip to content

Commit

Permalink
Use unicurses instad of curses, for Windows compat
Browse files Browse the repository at this point in the history
  • Loading branch information
elonen committed Jul 29, 2024
1 parent 07872c5 commit 4db7bb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
21 changes: 11 additions & 10 deletions hsm_secrets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion hsm_secrets/x509/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ pyescrypt
pycryptodome

yubihsm-ssh-tool @ git+https://github.com/YubicoLabs/yubihsm-ssh-tool@9cec861

uni-curses

0 comments on commit 4db7bb3

Please sign in to comment.