Skip to content

Commit

Permalink
Some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Oct 1, 2021
1 parent a760f9f commit 589bf1b
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 88 deletions.
137 changes: 95 additions & 42 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,10 +1442,6 @@ If you do not have a key file, please leave the field empty.</source>
<source>Key file to unlock the database</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please touch the button on your YubiKey!</source>
<translation type="unfinished">Please touch the button on your YubiKey!</translation>
</message>
<message>
<source>Detecting hardware keys…</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -1479,6 +1475,10 @@ If you do not have a key file, please leave the field empty.</source>
<source>You are using an old key file format which KeePassXC may&lt;br&gt;stop supporting in the future.&lt;br&gt;&lt;br&gt;Please consider generating a new key file by going to:&lt;br&gt;&lt;strong&gt;Database &amp;gt; Database Security &amp;gt; Change Key File.&lt;/strong&gt;&lt;br&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please present or touch your YubiKey to continue…</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatabaseSettingWidgetMetaData</name>
Expand Down Expand Up @@ -4755,10 +4755,6 @@ Are you sure you want to continue with this file?</source>
<source>Quit KeePassXC</source>
<translation>Quit KeePassXC</translation>
</message>
<message>
<source>Please touch the button on your YubiKey!</source>
<translation>Please touch the button on your YubiKey!</translation>
</message>
<message>
<source>&amp;Donate</source>
<translation>&amp;Donate</translation>
Expand Down Expand Up @@ -5119,6 +5115,10 @@ Expect some bugs and minor issues, this version is meant for testing purposes.</
We recommend you use the AppImage available on our downloads page.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please present or touch your YubiKey to continue…</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ManageDatabase</name>
Expand Down Expand Up @@ -6889,10 +6889,6 @@ Kernel: %3 %4</source>
<source>Invalid YubiKey serial %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please touch the button on your YubiKey to continue…</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you want to create a database with an empty password? [y/N]: </source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -7233,6 +7229,10 @@ Please consider generating a new key file.</source>
<source>Warning: Failed to prevent screenshots on a top level window!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please present or touch your YubiKey to continue…</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QtIOCompressor</name>
Expand Down Expand Up @@ -8268,104 +8268,157 @@ Example: JBSWY3DPEHPK3PXP</source>
<context>
<name>YubiKey</name>
<message>
<source>%1 [%2] Configured Slot - %3</source>
<source>%1 No interface, slot %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 Invalid slot specified - %2</source>
<source>General: </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The YubiKey interface has not been initialized.</source>
<source>Could not find interface for hardware key with serial number %1. Please connect it to continue.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YubiKeyEditWidget</name>
<message>
<source>Hardware key is currently in use.</source>
<source>Refresh</source>
<translation>Refresh</translation>
</message>
<message>
<source>Refresh hardware tokens</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Could not find hardware key with serial number %1. Please plug it in to continue.</source>
<source>Hardware key slot selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key timed out waiting for user interaction.</source>
<source>Could not find any hardware keys!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to complete a challenge-response, the specific error was: %1</source>
<source>Selected hardware key slot does not support challenge-response!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 [%2] Challenge-Response - Slot %3 - %4</source>
<source>Detecting hardware keys…</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Press</source>
<comment>Challenge-Response Key interaction request</comment>
<translation type="unfinished">Press</translation>
<source>No hardware keys detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Passive</source>
<comment>Challenge-Response Key no interaction required</comment>
<translation type="unfinished">Passive</translation>
<source>Challenge-Response</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>A USB error occurred when accessing the hardware key: %1</source>
<source>Add Challenge-Response</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change Challenge-Response</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Challenge-Response</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Challenge-Response set, click to change or remove</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;If you own a &lt;a href=&quot;https://www.yubico.com/&quot;&gt;YubiKey&lt;/a&gt; or &lt;a href=&quot;https://onlykey.io&quot;&gt;OnlyKey&lt;/a&gt;, you can use it for additional security.&lt;/p&gt;&lt;p&gt;The key requires one of its slots to be programmed as &lt;a href=&quot;https://www.yubico.com/products/services-software/challenge-response/&quot;&gt;HMAC-SHA1 Challenge-Response&lt;/a&gt;.&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YubiKeyEditWidget</name>
<name>YubiKeyInterface</name>
<message>
<source>Refresh</source>
<translation>Refresh</translation>
<source>%1 Invalid slot specified - %2</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YubiKeyInterfacePCSC</name>
<message>
<source>Refresh hardware tokens</source>
<source>(PCSC) %1 [%2] Challenge-Response - Slot %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key slot selection</source>
<source>The YubiKey PCSC interface has not been initialized.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Could not find any hardware keys!</source>
<source>Hardware key is currently in use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Selected hardware key slot does not support challenge-response!</source>
<source>Could not find or access hardware key with serial number %1. Please present it to continue. </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Detecting hardware keys…</source>
<source>Hardware key is locked or timed out. Unlock or re-present it to continue.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No hardware keys detected</source>
<source>Hardware key was not found or is misconfigured.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Challenge-Response</source>
<source>Failed to complete a challenge-response, the PCSC error code was: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YubiKeyInterfaceUSB</name>
<message>
<source>Add Challenge-Response</source>
<source>Unknown</source>
<translation type="unfinished">Unknown</translation>
</message>
<message>
<source>(USB) %1 [%2] Configured Slot - %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change Challenge-Response</source>
<source>(USB) %1 [%2] Challenge-Response - Slot %3 - %4</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Challenge-Response</source>
<source>Press</source>
<comment>USB Challenge-Response Key interaction request</comment>
<translation type="unfinished">Press</translation>
</message>
<message>
<source>Passive</source>
<comment>USB Challenge-Response Key no interaction required</comment>
<translation type="unfinished">Passive</translation>
</message>
<message>
<source>The YubiKey USB interface has not been initialized.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Challenge-Response set, click to change or remove</source>
<source>Hardware key is currently in use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;If you own a &lt;a href=&quot;https://www.yubico.com/&quot;&gt;YubiKey&lt;/a&gt; or &lt;a href=&quot;https://onlykey.io&quot;&gt;OnlyKey&lt;/a&gt;, you can use it for additional security.&lt;/p&gt;&lt;p&gt;The key requires one of its slots to be programmed as &lt;a href=&quot;https://www.yubico.com/products/services-software/challenge-response/&quot;&gt;HMAC-SHA1 Challenge-Response&lt;/a&gt;.&lt;/p&gt;</source>
<source>Could not find hardware key with serial number %1. Please plug it in to continue.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key timed out waiting for user interaction.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>A USB error occurred when accessing the hardware key: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to complete a challenge-response, the specific error was: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace Utils
}

auto conn = QObject::connect(YubiKey::instance(), &YubiKey::userInteractionRequest, [&] {
err << QObject::tr("Please interface with your YubiKey to continue…") << "\n\n" << flush;
err << QObject::tr("Please present or touch your YubiKey to continue…") << "\n\n" << flush;
});

auto key = QSharedPointer<ChallengeResponseKey>(new ChallengeResponseKey({serial, slot}));
Expand Down
5 changes: 3 additions & 2 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
connect(YubiKey::instance(), &YubiKey::userInteractionRequest, this, [this] {
// Show the press notification if we are in an independent window (e.g., DatabaseOpenDialog)
if (window() != getMainWindow()) {
m_ui->messageWidget->showMessage(
tr("Please interface with your YubiKey!"), MessageWidget::Information, MessageWidget::DisableAutoHide);
m_ui->messageWidget->showMessage(tr("Please present or touch your YubiKey to continue…"),
MessageWidget::Information,
MessageWidget::DisableAutoHide);
}
});
connect(YubiKey::instance(), &YubiKey::challengeCompleted, this, [this] { m_ui->messageWidget->hide(); });
Expand Down
6 changes: 4 additions & 2 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,10 @@ void MainWindow::hideGlobalMessage()

void MainWindow::showYubiKeyPopup()
{
displayGlobalMessage(
tr("Please interface with your YubiKey!"), MessageWidget::Information, false, MessageWidget::DisableAutoHide);
displayGlobalMessage(tr("Please present or touch your YubiKey to continue…"),
MessageWidget::Information,
false,
MessageWidget::DisableAutoHide);
setEnabled(false);
}

Expand Down
21 changes: 6 additions & 15 deletions src/keys/drivers/YubiKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,23 @@ QList<YubiKeySlot> YubiKey::foundKeys()
QList<YubiKeySlot> foundKeys;

auto keys = YubiKeyInterfaceUSB::instance()->foundKeys();
QList<unsigned int> handledSerials;
for (auto serial : keys.keys()) {
// This check is needed to prevent duplicate keys
// when more than one slot is configured
if(handledSerials.contains(serial)) {
continue;
}

QList<unsigned int> handledSerials = keys.uniqueKeys();
for (auto serial : handledSerials) {
for (const auto& key : keys.values(serial)) {
foundKeys.append({serial, key.slot});
foundKeys.append({serial, key.first});
}
handledSerials.append(serial);
}

keys = YubiKeyInterfacePCSC::instance()->foundKeys();
for (auto serial : keys.keys()) {
for (auto serial : keys.uniqueKeys()) {
// Ignore keys that were detected on USB interface already
// This also prevents duplicate keys (see above)
if(handledSerials.contains(serial)) {
if (handledSerials.contains(serial)) {
continue;
}

for (const auto& key : keys.values(serial)) {
foundKeys.append({serial, key.slot});
foundKeys.append({serial, key.first});
}
handledSerials.append(serial);
}

return foundKeys;
Expand Down
8 changes: 4 additions & 4 deletions src/keys/drivers/YubiKeyInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ bool YubiKeyInterface::isInitialized() const
return m_initialized;
}

QMultiHash<unsigned int, YubiKeyInterface::KeyData> YubiKeyInterface::foundKeys()
QMultiMap<unsigned int, QPair<int, QString>> YubiKeyInterface::foundKeys()
{
return m_foundKeys;
}

bool YubiKeyInterface::hasFoundKey(YubiKeySlot slot)
{
for (const auto& key : m_foundKeys.values(slot.first)) {
if (slot.second == key.slot) {
if (slot.second == key.first) {
return true;
}
}
Expand All @@ -48,8 +48,8 @@ bool YubiKeyInterface::hasFoundKey(YubiKeySlot slot)
QString YubiKeyInterface::getDisplayName(YubiKeySlot slot)
{
for (const auto& key : m_foundKeys.values(slot.first)) {
if (slot.second == key.slot) {
return key.desc;
if (slot.second == key.first) {
return key.second;
}
}
return tr("%1 Invalid slot specified - %2").arg(QString::number(slot.first), QString::number(slot.second));
Expand Down
13 changes: 3 additions & 10 deletions src/keys/drivers/YubiKeyInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "YubiKey.h"

#include <QMultiHash>
#include <QMultiMap>

/**
* Abstract base class to manage the interfaces to hardware key(s)
Expand All @@ -31,15 +31,8 @@ class YubiKeyInterface : public QObject
Q_OBJECT

public:
struct KeyData
{
unsigned int serial;
int slot;
QString desc;
};

bool isInitialized() const;
QMultiHash<unsigned int, KeyData> foundKeys();
QMultiMap<unsigned int, QPair<int, QString>> foundKeys();
bool hasFoundKey(YubiKeySlot slot);
QString getDisplayName(YubiKeySlot slot);

Expand Down Expand Up @@ -75,7 +68,7 @@ class YubiKeyInterface : public QObject
Botan::secure_vector<char>& response) = 0;
virtual bool performTestChallenge(void* key, int slot, bool* wouldBlock) = 0;

QMultiHash<unsigned int, KeyData> m_foundKeys;
QMultiMap<unsigned int, QPair<int, QString>> m_foundKeys;

QMutex m_mutex;
QTimer m_interactionTimer;
Expand Down
Loading

0 comments on commit 589bf1b

Please sign in to comment.