From 3a48635edbd2f0269823ce501a10f7d5a7760d5c Mon Sep 17 00:00:00 2001 From: Jamie A Hankins Date: Thu, 8 Jul 2021 17:44:22 -0700 Subject: [PATCH 1/3] Honor digits even for challenge The ykchalresp tool will output a six or eight digit OTP code even if challenge mode is chosen. This change does that for the ykman tool. In order to know if the user has selected six or eight digits, I added a zero selection to digits (although the text still says six). Later, if TOTP mode is selected and digits is zero, we change the zero to six. This way, behavior is the same when TOTP is selected, or no digit count is specified. --- ykman/cli/otp.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ykman/cli/otp.py b/ykman/cli/otp.py index 32f3d88f..03ace573 100644 --- a/ykman/cli/otp.py +++ b/ykman/cli/otp.py @@ -591,8 +591,8 @@ def chalresp(ctx, slot, key, totp, touch, force, generate): @click.option( "-d", "--digits", - type=click.Choice(["6", "8"]), - default="6", + type=click.Choice(["0", "6", "8"]), + default="0", help="Number of digits in generated TOTP code (default: 6).", ) @click.pass_context @@ -633,7 +633,11 @@ def on_keepalive(status): setattr(on_keepalive, "prompted", True) response = session.calculate_hmac_sha1(slot, challenge, event, on_keepalive) - if totp: + + if totp and digits == '0': + digits = '6' + + if digits != '0': value = format_oath_code(response, int(digits)) else: value = response.hex() From d7b7ed8f48c429fb7b9843631fc67a327febb07f Mon Sep 17 00:00:00 2001 From: Jamie A Hankins Date: Thu, 8 Jul 2021 18:00:27 -0700 Subject: [PATCH 2/3] Fix errant whitespace. --- ykman/cli/otp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ykman/cli/otp.py b/ykman/cli/otp.py index 03ace573..ece89679 100644 --- a/ykman/cli/otp.py +++ b/ykman/cli/otp.py @@ -637,7 +637,7 @@ def on_keepalive(status): if totp and digits == '0': digits = '6' - if digits != '0': + if digits != '0': value = format_oath_code(response, int(digits)) else: value = response.hex() From 2bec764180f01cf4d86062f286d70eaa2c2f03c2 Mon Sep 17 00:00:00 2001 From: Jamie A Hankins Date: Thu, 8 Jul 2021 18:22:51 -0700 Subject: [PATCH 3/3] Looks like black wants double quotes. --- ykman/cli/otp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ykman/cli/otp.py b/ykman/cli/otp.py index ece89679..8994c541 100644 --- a/ykman/cli/otp.py +++ b/ykman/cli/otp.py @@ -634,10 +634,10 @@ def on_keepalive(status): response = session.calculate_hmac_sha1(slot, challenge, event, on_keepalive) - if totp and digits == '0': - digits = '6' + if totp and digits == "0": + digits = "6" - if digits != '0': + if digits != "0": value = format_oath_code(response, int(digits)) else: value = response.hex()