Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard layout option to OtpStaticPasswordView.qml #348

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
repos:
- repo: local
hooks:
- id: qmllint
Expand Down
69 changes: 47 additions & 22 deletions ykman-gui/qml/OtpStaticPasswordView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import QtQuick.Controls.Material 2.2

ColumnLayout {

property string keyboardLayout: allowNonModhex.checked ? 'US' : 'MODHEX'
property string keyboardLayoutName: "MODHEX"
property RegExpValidator keyboardLayoutValidator: modHexValidator

function finish() {
if (views.selectedSlotConfigured()) {
Expand All @@ -18,7 +19,7 @@ ColumnLayout {

function programStaticPassword() {
yubiKey.programStaticPassword(views.selectedSlot, passwordInput.text,
keyboardLayout, function (resp) {
keyboardLayoutName, function (resp) {
if (resp.success) {
views.otp()
snackbarSuccess.show(
Expand All @@ -35,7 +36,7 @@ ColumnLayout {
}

function generatePassword() {
yubiKey.generateStaticPw(keyboardLayout, function (resp) {
yubiKey.generateStaticPw(keyboardLayoutName, function (resp) {
if (resp.success) {
passwordInput.text = resp.password
} else {
Expand All @@ -44,15 +45,17 @@ ColumnLayout {
})
}

RegExpValidator {
id: modHexValidator
regExp: /[cbdefghijklnrtuvCBDEFGHIJKLMNRTUV]{1,38}$/
}

RegExpValidator {
id: usLayoutValidator
regExp: /[ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#\$%&'\\`\(\)\*\+,-\.\/:;<=>\?@\[\]\^_{}\|~]{1,38}$/
}
// Update these if the ykman scancodes change: https://github.com/Yubico/yubikey-manager/tree/51a7ae438c923189788a1e31d3de18d452131942/ykman/scancodes
RegExpValidator { id: modHexValidator; regExp: /[bcdefghijklnrtuvBCDEFGHIJKLNRTUV]{1,38}$/ }
RegExpValidator { id: usLayoutValidator; regExp: /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'`\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^_\{\}\|\~\ ]{1,38}$/ }
RegExpValidator { id: ukLayoutValidator; regExp: /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@£\$%\&'`\(\)\*\+,\-\.\/:;<=>\?"\[\#\]\^_\{\}\~¬\ ]{1,38}$/ }
RegExpValidator { id: deLayoutValidator; regExp: /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'\(\)\*\+,\-\.\/:;<=>\?\^_\ `§´ÄÖÜßäöü]{1,38}$/ }
// U+007F : <control> DELETE [DEL] ("") is here because neither \x{007F} nor \u007F worked
RegExpValidator { id: frLayoutValidator; regExp: /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\ !"\$%\&'\(\)\*\+,\-\.\/:;<=_£§°²µàçèéù]{1,38}$/ }
RegExpValidator { id: itLayoutValidator; regExp: /[\ !"\#\$%\&'\(\)\*\+,\-\.\/0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\\^_`abcdefghijklmnopqrstuvwxyz\|£§°çèéàìòù]{1,38}$/ }
// U+00A0 : NO-BREAK SPACE [NBSP] (" ") is here because neither \x{00A0} nor \u00A0 worked
RegExpValidator { id: bepoLayoutValidator; regExp: /[\ !"\#\$%'\(\)\*\+,\-\.\/0123456789:;=\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz «°»ÀÇÈÉÊàçèéê]{1,38}$/ }
RegExpValidator { id: normanLayoutValidator; regExp: /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'`\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^_\{\}\|\~\ ]{1,38}$/ }

CustomContentColumn {

Expand All @@ -71,7 +74,7 @@ ColumnLayout {
CustomTextField {
id: passwordInput
Layout.fillWidth: true
validator: allowNonModhex.checked ? usLayoutValidator : modHexValidator
validator: keyboardLayoutValidator
}
CustomButton {
id: generatePasswordBtn
Expand All @@ -80,15 +83,37 @@ ColumnLayout {
toolTipText: qsTr("Generate a random password")
}
}
CheckBox {
id: allowNonModhex
text: qsTr("Allow any character")
onCheckedChanged: passwordInput.text = ""
font.pixelSize: constants.h3
Material.foreground: yubicoBlue
ToolTip.delay: 1000
ToolTip.visible: hovered
ToolTip.text: qsTr("By default only modhex characters are allowed, enable this option to allow any (US Layout) characters")

RowLayout {
spacing: 15
Label {
text: qsTr("Keyboard Layout")
font.pixelSize: constants.h3
color: yubicoBlue
}
ComboBox {
textRole: "text"
valueRole: "value"
currentIndex: 0
model: ListModel {
// https://stackoverflow.com/a/33161093/19020549
Component.onCompleted: {
append({"text": "MODHEX", value: modHexValidator});
append({"text": "US", value: usLayoutValidator});
append({"text": "UK", value: ukLayoutValidator});
append({"text": "DE", value: deLayoutValidator});
append({"text": "FR", value: frLayoutValidator});
append({"text": "IT", value: itLayoutValidator});
append({"text": "BEPO", value: bepoLayoutValidator});
append({"text": "NORMAN", value: normanLayoutValidator});
}
}
onActivated: {
keyboardLayoutName = currentText
keyboardLayoutValidator = currentValue
passwordInput.text = ""
}
}
}

ButtonsBar {
Expand Down