From f30592e39c1cb924860c99efd185447a60a4e3a5 Mon Sep 17 00:00:00 2001 From: Vadim Kaushan Date: Wed, 8 Jan 2025 20:44:59 +0200 Subject: [PATCH] Add initial support for ykman 5.5 and fix error reporting --- ykman-gui/py/yubikey.py | 14 +++++++++++--- ykman-gui/qml/ContentStack.qml | 4 ++-- ykman-gui/qml/OtpChalRespView.qml | 3 +-- ykman-gui/qml/OtpOathHotpView.qml | 3 +-- ykman-gui/qml/OtpStaticPasswordView.qml | 3 +-- ykman-gui/qml/OtpView.qml | 2 +- ykman-gui/qml/OtpYubiOtpView.qml | 3 +-- ykman-gui/qml/SnackBarError.qml | 2 ++ 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ykman-gui/py/yubikey.py b/ykman-gui/py/yubikey.py index 2c91bc48..65800ccf 100644 --- a/ykman-gui/py/yubikey.py +++ b/ykman-gui/py/yubikey.py @@ -50,9 +50,11 @@ if int(ykman_v.split(".")[0] ) > 4: from yubikit.support import get_name from ykman.device import list_all_devices, scan_devices - from ykman.otp import ( - _PrepareUploadFailed as PrepareUploadFailed - , _prepare_upload_key as prepare_upload_key, generate_static_pw) + if int(ykman_v.split(".")[0]) == 5 and int(ykman_v.split(".")[1]) < 5: + from ykman.otp import ( + _PrepareUploadFailed as PrepareUploadFailed + , _prepare_upload_key as prepare_upload_key) + from ykman.otp import generate_static_pw else: from ykman import connect_to_device, scan_devices, get_name from ykman.otp import PrepareUploadFailed, prepare_upload_key, generate_static_pw @@ -401,6 +403,12 @@ def program_otp(self, slot, public_id, private_id, key, upload=False, with self._open_device([OtpConnection]) as conn: if upload: + # Automated YubiCloud upload support has been ended. It's not supported in ykman>=5.5.0. + ykman_v_major = int(ykman_v.split(".")[0]) + ykman_v_minor = int(ykman_v.split(".")[1]) + if ykman_v_major > 5 or (ykman_v_major == 5 and ykman_v_minor >= 5): + return failure('yubicloud_upload_not_supported') + try: upload_url = prepare_upload_key( key, public_id, private_id, diff --git a/ykman-gui/qml/ContentStack.qml b/ykman-gui/qml/ContentStack.qml index 671a1dd8..555ddf69 100644 --- a/ykman-gui/qml/ContentStack.qml +++ b/ykman-gui/qml/ContentStack.qml @@ -182,10 +182,10 @@ StackView { SlotUtils.slotNameCapitalized(views.selectedSlot))) } - function otpFailedToConfigureErrorPopup(error) { + function otpFailedToConfigureErrorPopup(resp) { snackbarError.show(qsTr("Failed to configure %1. %2").arg( SlotUtils.slotNameCapitalized( - views.selectedSlot)).arg(snackbarError.getDefaultMessage(error))) + views.selectedSlot)).arg(snackbarError.getDefaultMessage(resp))) } function snackbarErrorMessage(error) { diff --git a/ykman-gui/qml/OtpChalRespView.qml b/ykman-gui/qml/OtpChalRespView.qml index b8f3c6d5..3fd39c0d 100644 --- a/ykman-gui/qml/OtpChalRespView.qml +++ b/ykman-gui/qml/OtpChalRespView.qml @@ -33,8 +33,7 @@ ColumnLayout { if (resp.error_id === 'write error') { views.otpWriteError() } else { - views.otpFailedToConfigureErrorPopup( - resp.error_id) + views.otpFailedToConfigureErrorPopup(resp) } } }) diff --git a/ykman-gui/qml/OtpOathHotpView.qml b/ykman-gui/qml/OtpOathHotpView.qml index e3f1539b..0540cc97 100644 --- a/ykman-gui/qml/OtpOathHotpView.qml +++ b/ykman-gui/qml/OtpOathHotpView.qml @@ -25,8 +25,7 @@ ColumnLayout { if (resp.error_id === 'write error') { views.otpWriteError() } else { - views.otpFailedToConfigureErrorPopup( - resp) + views.otpFailedToConfigureErrorPopup(resp) } } }) diff --git a/ykman-gui/qml/OtpStaticPasswordView.qml b/ykman-gui/qml/OtpStaticPasswordView.qml index ef2a63f5..71e339dd 100644 --- a/ykman-gui/qml/OtpStaticPasswordView.qml +++ b/ykman-gui/qml/OtpStaticPasswordView.qml @@ -27,8 +27,7 @@ ColumnLayout { if (resp.error_id === 'write error') { views.otpWriteError() } else { - views.otpFailedToConfigureErrorPopup( - resp.error_id) + views.otpFailedToConfigureErrorPopup(resp) } } }) diff --git a/ykman-gui/qml/OtpView.qml b/ykman-gui/qml/OtpView.qml index 15426778..94dc8112 100644 --- a/ykman-gui/qml/OtpView.qml +++ b/ykman-gui/qml/OtpView.qml @@ -59,7 +59,7 @@ ColumnLayout { if (resp.error_id === 'write error') { views.otpWriteError() } else { - views.otpFailedToConfigureErrorPopup(resp.error_id) + views.otpFailedToConfigureErrorPopup(resp) } } }) diff --git a/ykman-gui/qml/OtpYubiOtpView.qml b/ykman-gui/qml/OtpYubiOtpView.qml index 43edb8b7..dd37e778 100644 --- a/ykman-gui/qml/OtpYubiOtpView.qml +++ b/ykman-gui/qml/OtpYubiOtpView.qml @@ -73,8 +73,7 @@ ColumnLayout { getUploadErrorMessage( resp.upload_errors[0]))) } else { - views.otpFailedToConfigureErrorPopup( - resp.error_id) + views.otpFailedToConfigureErrorPopup(resp) } } }) diff --git a/ykman-gui/qml/SnackBarError.qml b/ykman-gui/qml/SnackBarError.qml index c208d91b..50fbfb43 100644 --- a/ykman-gui/qml/SnackBarError.qml +++ b/ykman-gui/qml/SnackBarError.qml @@ -55,6 +55,8 @@ SnackBar { return qsTr("Failed to parse file") case 'incorrect_padding': return qsTr("Incorrect padding.") + case 'yubicloud_upload_not_supported': + return qsTr("Automated YubiCloud upload support has been ended.") } }