aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/hardware_key_generate_dialog.cpp
diff options
context:
space:
mode:
authorOsmium Sorcerer <os@sof.beauty>2026-09-23 21:49:39 +0000
committerOsmium Sorcerer <os@sof.beauty>2026-09-23 21:49:39 +0000
commit9b1903f4b902a4e9d1aa16888f82d8268c2cf4ef (patch)
tree4840f09cff2b5d43435eedc28d96dccc5daff374 /src/widgets/hardware_key_generate_dialog.cpp
parent05db351e119beb53ffc0046509a022ae9c471f15 (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/hardware_key_generate_dialog.cpp')
-rw-r--r--src/widgets/hardware_key_generate_dialog.cpp86
1 files changed, 86 insertions, 0 deletions
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();
+}