diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-09-23 21:49:39 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-09-23 21:49:39 +0000 |
| commit | 9b1903f4b902a4e9d1aa16888f82d8268c2cf4ef (patch) | |
| tree | 4840f09cff2b5d43435eedc28d96dccc5daff374 /src/widgets | |
| parent | 05db351e119beb53ffc0046509a022ae9c471f15 (diff) | |
Add dialogs for hardware key generation UI
The key creation is handed off to the platform implementation. Windows
will show its own Windows Security UI. On Unix, the application itself
provides the PIN directly, enforcing a minimum of six characters.
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/aooptionsdialog.cpp | 15 | ||||
| -rw-r--r-- | src/widgets/aooptionsdialog.h | 1 | ||||
| -rw-r--r-- | src/widgets/hardware_key_generate_dialog.cpp | 86 | ||||
| -rw-r--r-- | src/widgets/hardware_key_generate_dialog.h | 33 |
4 files changed, 133 insertions, 2 deletions
diff --git a/src/widgets/aooptionsdialog.cpp b/src/widgets/aooptionsdialog.cpp index d9cbcb8..95b7420 100644 --- a/src/widgets/aooptionsdialog.cpp +++ b/src/widgets/aooptionsdialog.cpp @@ -8,8 +8,8 @@ #include "networkmanager.h" #include "options.h" -// Hopefully temporary. #include "widgets/key_generate_dialog.h" +#include "widgets/hardware_key_generate_dialog.h" #include <QCollator> #include <QDoubleSpinBox> @@ -607,7 +607,7 @@ void AOOptionsDialog::setupUI() KeyGenerateDialog keygen_dialog(this); if (keygen_dialog.exec() == QDialog::Accepted) { - int err = generate_key(keygen_dialog.key_name(), keygen_dialog.key_password()); + int err = generate_software_key(keygen_dialog.key_name(), keygen_dialog.key_password()); if (err) { QMessageBox::warning(this, "Error", QString("Key generation failed, code %1").arg(err)); @@ -615,6 +615,17 @@ void AOOptionsDialog::setupUI() ao_app->keyring_model.load_keys(); } }); + FROM_UI(QPushButton, key_generate_hw); + connect(ui_key_generate_hw, &QPushButton::clicked, this, [=, this] { + HardwareKeyDialog hw_keygen_dialog(this); + if (hw_keygen_dialog.exec() == QDialog::Accepted) + { + ao_app->keyring_model.load_keys(); + } + }); + + ui_key_generate_hw->setEnabled(keyring_hardware_available()); + FROM_UI(QPushButton, key_delete); FROM_UI(QTableView, keyring_table); diff --git a/src/widgets/aooptionsdialog.h b/src/widgets/aooptionsdialog.h index bc9f282..bd1ca0d 100644 --- a/src/widgets/aooptionsdialog.h +++ b/src/widgets/aooptionsdialog.h @@ -126,6 +126,7 @@ private: // The keyring tab QPushButton *ui_key_generate; + QPushButton *ui_key_generate_hw; QPushButton *ui_key_delete; QTableView *ui_keyring_table; diff --git a/src/widgets/hardware_key_generate_dialog.cpp b/src/widgets/hardware_key_generate_dialog.cpp new file mode 100644 index 0000000..cb79be9 --- /dev/null +++ b/src/widgets/hardware_key_generate_dialog.cpp @@ -0,0 +1,86 @@ +#include <QVBoxLayout> +#include <QFormLayout> +#include <QLabel> +#include <QPushButton> +#include <QMessageBox> + +#include "hardware_key_generate_dialog.h" +#include "keyring.h" + +HardwareKeyDialog::HardwareKeyDialog(QWidget *parent) : QDialog(parent) +{ + setWindowTitle("Generate hardware key"); + auto *layout = new QVBoxLayout(this); + auto *name_lbl = new QLabel("Key name:", this); + m_name_line = new QLineEdit(this); + auto *info = new QLabel("The key will remain in secure hardware and can't be exported.\n" + "You can protect it with a weaker secret (such as 6-digit PIN) because it can't be stolen, but you can't back up or transfer a hardware key as it's bound to this particular machine and unusable anywhere else.\n" + "Your platform will handle the setup.", this); + info->setWordWrap(true); + auto *buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this); + buttons->button(QDialogButtonBox::Ok)->setText("Set up key"); + layout->addWidget(name_lbl); + layout->addWidget(m_name_line); + layout->addWidget(info); + layout->addStretch(); // Does this work? + layout->addWidget(buttons); + + connect(buttons, &QDialogButtonBox::accepted, this, &HardwareKeyDialog::generate); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +void HardwareKeyDialog::generate() +{ + const QString key_name = m_name_line->text().trimmed(); + QByteArray pin; + +#ifdef SOF_AO_HARDWARE_KEY_REQUIRES_PIN_UI + PinEntryDialog pin_dlg(key_name, this); + if (pin_dlg.exec() != QDialog::Accepted) + { + return; + } + pin = pin_dlg.pin(); +#endif + + int keygen_err = generate_hardware_key(key_name, pin); + if (keygen_err) + { + QMessageBox::warning(this, "Error", QString("Key generation failed (code %1).").arg(keygen_err)); + return; + } + + accept(); +} + +PinEntryDialog::PinEntryDialog(QStringView name, QWidget *parent) : QDialog(parent) +{ + auto *layout = new QFormLayout(this); + m_pin_line = new QLineEdit(this); + m_confirm_pin_line = new QLineEdit(this); + m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this); + layout->addRow("PIN:", m_pin_line); + layout->addRow("Confirm PIN:", m_confirm_pin_line); + layout->addRow(m_buttons); + + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(false); + m_pin_line->setEchoMode(QLineEdit::Password); + m_confirm_pin_line->setEchoMode(QLineEdit::Password); + connect(m_pin_line, &QLineEdit::textChanged, this, &PinEntryDialog::validate); + connect(m_confirm_pin_line, &QLineEdit::textChanged, this, &PinEntryDialog::validate); + connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +void PinEntryDialog::validate() +{ + bool valid = !m_pin_line->text().isEmpty() && + (m_pin_line->text().length() >= 6) && + (m_pin_line->text() == m_confirm_pin_line->text()); + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(valid); +} + +QByteArray PinEntryDialog::pin() const +{ + return m_pin_line->text().toUtf8(); +} diff --git a/src/widgets/hardware_key_generate_dialog.h b/src/widgets/hardware_key_generate_dialog.h new file mode 100644 index 0000000..4988573 --- /dev/null +++ b/src/widgets/hardware_key_generate_dialog.h @@ -0,0 +1,33 @@ +#pragma once + +#include <QDialog> +#include <QLineEdit> +#include <QDialogButtonBox> +#include <QByteArray> + +class HardwareKeyDialog : public QDialog +{ + Q_OBJECT + +public: + explicit HardwareKeyDialog(QWidget *parent = nullptr); + void generate(void); + +private: + QLineEdit *m_name_line; +}; + +class PinEntryDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PinEntryDialog(QStringView name, QWidget *parent = nullptr); + QByteArray pin(void) const; + +private: + void validate(void); + QLineEdit *m_pin_line; + QLineEdit *m_confirm_pin_line; + QDialogButtonBox *m_buttons; +}; |
