From dd883780b71e2f3eabec815e843e2edf53bb664b Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Fri, 9 Sep 2016 15:16:52 -0700 Subject: [PATCH] yubioath-gui: implement HMAC-SHA256 support in UI Signed-off-by: Steven Noonan --- yubioath/gui/__main__.py | 1 + yubioath/gui/messages.py | 1 + yubioath/gui/view/add_cred.py | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/yubioath/gui/__main__.py b/yubioath/gui/__main__.py index c0a37847..50ea111f 100644 --- a/yubioath/gui/__main__.py +++ b/yubioath/gui/__main__.py @@ -221,6 +221,7 @@ class YubiOathApplication(qt.Application): self._controller.add_cred( dialog.name, dialog.key, oath_type=dialog.oath_type, digits=dialog.n_digits, + algo=dialog.algorithm, require_touch=dialog.require_touch) except NoSpaceError: QtGui.QMessageBox.critical(self.window, m.no_space, m.no_space_desc) diff --git a/yubioath/gui/messages.py b/yubioath/gui/messages.py index c7d9a229..cc321a33 100644 --- a/yubioath/gui/messages.py +++ b/yubioath/gui/messages.py @@ -73,6 +73,7 @@ cred_key = "Secret key (base32)" cred_type = "Credential type" cred_totp = "Time based (TOTP)" cred_hotp = "Counter based (HOTP)" +algorithm = "Algorithm" invalid_name = "Invalid name" invalid_name_desc = "Name must be at least 3 characters" invalid_key = "Invalid key" diff --git a/yubioath/gui/view/add_cred.py b/yubioath/gui/view/add_cred.py index 45e13ee8..863caa56 100644 --- a/yubioath/gui/view/add_cred.py +++ b/yubioath/gui/view/add_cred.py @@ -25,7 +25,7 @@ # for the parts of OpenSSL used as well as that of the covered work. from yubioath.yubicommon import qt -from ...core.standard import TYPE_TOTP, TYPE_HOTP +from ...core.standard import ALG_SHA1, ALG_SHA256, TYPE_TOTP, TYPE_HOTP from ...core.utils import parse_uri from .. import messages as m from ..qrparse import parse_qr_codes @@ -99,6 +99,10 @@ class AddCredDialog(qt.Dialog): self._n_digits.addItems(['6', '8']) layout.addRow(m.n_digits, self._n_digits) + self._algorithm = QtGui.QComboBox() + self._algorithm.addItems(['SHA-1', 'SHA-256']) + layout.addRow(m.algorithm, self._algorithm) + self._require_touch = QtGui.QCheckBox(m.require_touch) # Touch-required support not available before 4.2.6 if self._version >= (4, 2, 6): @@ -132,6 +136,8 @@ class AddCredDialog(qt.Dialog): self._cred_key.setText(parsed['secret']) n_digits = parsed.get('digits', '6') self._n_digits.setCurrentIndex(0 if n_digits == '6' else 1) + algo = parsed.get('algorithm', 'SHA1').upper() + self._algorithm.setCurrentIndex(0 if algo == 'SHA1' else 1) if parsed['type'] == 'totp': self._cred_totp.setChecked(True) else: @@ -177,6 +183,10 @@ class AddCredDialog(qt.Dialog): def n_digits(self): return int(self._n_digits.currentText()) + @property + def algorithm(self): + return ALG_SHA1 if self._algorithm.currentIndex() == 0 else ALG_SHA256 + @property def require_touch(self): return self._require_touch.isChecked()