Skip to content

Commit

Permalink
Automatically detect USB device changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phoerious committed Feb 22, 2024
1 parent 956e3d0 commit 844fafb
Show file tree
Hide file tree
Showing 43 changed files with 1,506 additions and 822 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
if(WITH_XC_YUBIKEY)
find_package(PCSC REQUIRED)
include_directories(SYSTEM ${PCSC_INCLUDE_DIRS})

if(UNIX AND NOT APPLE)
find_library(LIBUSB_LIBRARIES NAMES usb-1.0 REQUIRED)
find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h PATH_SUFFIXES "libusb-1.0" "libusb" REQUIRED)
include_directories(SYSTEM ${LIBUSB_INCLUDE_DIR})
endif()
endif()

if(UNIX)
Expand Down
1 change: 1 addition & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Files: share/icons/application/scalable/actions/application-exit.svg
share/icons/application/scalable/actions/username-copy.svg
share/icons/application/scalable/actions/view-history.svg
share/icons/application/scalable/actions/web.svg
share/icons/application/scalable/actions/yubikey-refresh.svg
share/icons/application/scalable/apps/internet-web-browser.svg
share/icons/application/scalable/apps/keepassxc.svg
share/icons/application/scalable/apps/keepassxc-dark.svg
Expand Down
9 changes: 8 additions & 1 deletion cmake/FindQREncode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

find_path(QRENCODE_INCLUDE_DIR NAMES qrencode.h)

find_library(QRENCODE_LIBRARY qrencode)
if(WIN32 AND MSVC)
find_library(QRENCODE_LIBRARY_RELEASE qrencode)
find_library(QRENCODE_LIBRARY_DEBUG qrencoded)
set(QRENCODE_LIBRARY optimized ${QRENCODE_LIBRARY_RELEASE} debug ${QRENCODE_LIBRARY_DEBUG})
else()
find_library(QRENCODE_LIBRARY qrencode)
endif()

mark_as_advanced(QRENCODE_LIBRARY QRENCODE_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
Expand Down
10 changes: 10 additions & 0 deletions share/icons/application/scalable/actions/yubikey-refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions share/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<file>application/scalable/actions/username-copy.svg</file>
<file>application/scalable/actions/view-history.svg</file>
<file>application/scalable/actions/web.svg</file>
<file>application/scalable/actions/yubikey-refresh.svg</file>
<file>application/scalable/apps/freedesktop.svg</file>
<file>application/scalable/apps/internet-web-browser.svg</file>
<file>application/scalable/apps/keepassxc.svg</file>
Expand Down
129 changes: 49 additions & 80 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,39 +1488,10 @@ Backup database located at %2</source>
<source>Password field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter Additional Credentials (if any):</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Key File:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;In addition to a password, you can use a secret file to enhance the security of your database. This file can be generated in your database&apos;s security settings.&lt;/p&gt;&lt;p&gt;This is &lt;strong&gt;not&lt;/strong&gt; your *.kdbx database file!&lt;br&gt;If you do not have a key file, leave this field empty.&lt;/p&gt;&lt;p&gt;Click for more information…&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Key file help</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key slot selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware Key:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;p&gt;You can use a hardware security key such as a &lt;strong&gt;YubiKey&lt;/strong&gt; or &lt;strong&gt;OnlyKey&lt;/strong&gt; with slots configured for HMAC-SHA1.&lt;/p&gt;
&lt;p&gt;Click for more information…&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key help</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Key file to unlock the database</source>
<translation type="unfinished"></translation>
Expand All @@ -1533,14 +1504,6 @@ Backup database located at %2</source>
<source>Browse…</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh hardware tokens</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unlock Database</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -1627,28 +1590,59 @@ To prevent this error from appearing, you must go to &quot;Database Settings / S
<translation type="unfinished"></translation>
</message>
<message>
<source>You cannot use your database file as a key file.
If you do not have a key file, please leave the field empty.</source>
<source>authenticate to access the database</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Detecting hardware keys…</source>
<source>Failed to authenticate with Quick Unlock: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No hardware keys detected</source>
<source>Select Key File:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Select hardware key…</source>
<source>&lt;p&gt;In addition to a password, you can use a secret file to enhance the security of your database. This file can be generated in your database&apos;s security settings.&lt;/p&gt;&lt;p&gt;This is &lt;strong&gt;not&lt;/strong&gt; your *.kdbx database file!&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>authenticate to access the database</source>
<source>Click to add a key file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to authenticate with Quick Unlock: %1</source>
<source>&lt;a href=&quot;#&quot; style=&quot;text-decoration: underline&quot;&gt;I have a key file&lt;/a&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use hardware key [Serial: %1]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use hardware key</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Your database file is NOT a key file!
If you don&apos;t have a key file or don&apos;t know what that is, you don&apos;t have to select one.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>KeePassXC database file selected</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The file you selected looks like a database file.
A database file is NOT a key file!

Are you sure you want to continue with this file?.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No hardware keys found.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh Hardware Keys</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down Expand Up @@ -9593,10 +9587,6 @@ Example: JBSWY3DPEHPK3PXP</source>
</context>
<context>
<name>YubiKey</name>
<message>
<source>%1 No interface, slot %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>General: </source>
<translation type="unfinished"></translation>
Expand All @@ -9608,14 +9598,6 @@ Example: JBSWY3DPEHPK3PXP</source>
</context>
<context>
<name>YubiKeyEditWidget</name>
<message>
<source>Refresh hardware tokens</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key slot selection</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -9648,10 +9630,6 @@ Example: JBSWY3DPEHPK3PXP</source>
<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>
<message>
<source>Detecting hardware keys…</source>
<translation type="unfinished"></translation>
Expand All @@ -9660,11 +9638,8 @@ Example: JBSWY3DPEHPK3PXP</source>
<source>No hardware keys detected</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>YubiKeyInterface</name>
<message>
<source>%1 Invalid slot specified - %2</source>
<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://docs.yubico.com/yesdk/users-manual/application-otp/challenge-response.html&quot;&gt;HMAC-SHA1 Challenge-Response&lt;/a&gt;.&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand All @@ -9678,10 +9653,6 @@ Example: JBSWY3DPEHPK3PXP</source>
<source>The YubiKey PCSC interface has not been initialized.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key is currently in use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Could not find or access hardware key with serial number %1. Please present it to continue. </source>
<translation type="unfinished"></translation>
Expand All @@ -9705,14 +9676,6 @@ Example: JBSWY3DPEHPK3PXP</source>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(USB) %1 [%2] Configured Slot - %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(USB) %1 [%2] Challenge-Response - Slot %3 - %4</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Press</source>
<comment>USB Challenge-Response Key interaction request</comment>
Expand All @@ -9727,10 +9690,6 @@ Example: JBSWY3DPEHPK3PXP</source>
<source>The YubiKey USB interface has not been initialized.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hardware key is currently in use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Could not find hardware key with serial number %1. Please plug it in to continue.</source>
<translation type="unfinished"></translation>
Expand All @@ -9747,5 +9706,15 @@ Example: JBSWY3DPEHPK3PXP</source>
<source>Failed to complete a challenge-response, the specific error was: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 [%2] - Slot %3</source>
<comment>YubiKey NEO display fields</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 [%2] - Slot %3, %4</source>
<comment>YubiKey display fields</comment>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
13 changes: 12 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ if(WIN32)
endif()
endif()

if(WITH_XC_YUBIKEY)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/osutils/DeviceListener.cpp)
if(APPLE)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/osutils/macutils/DeviceListenerMac.cpp)
elseif(UNIX)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/osutils/nixutils/DeviceListenerLibUsb.cpp)
elseif(WIN32)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/osutils/winutils/DeviceListenerWin.cpp)
endif()
endif()

set(keepassx_SOURCES ${keepassx_SOURCES}
../share/icons/icons.qrc
../share/wizard/wizard.qrc)
Expand Down Expand Up @@ -401,7 +412,7 @@ if(HAIKU)
target_link_libraries(keepassx_core network)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus)
target_link_libraries(keepassx_core Qt5::DBus ${LIBUSB_LIBRARIES})
if(WITH_XC_X11)
target_link_libraries(keepassx_core Qt5::X11Extras X11)
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/core/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Bootstrap
* Perform early application bootstrapping that does not rely on a QApplication
* being present.
*/
void bootstrap()
void bootstrap(const QString& overrideUiLang)
{
#ifdef QT_NO_DEBUG
disableCoreDumps();
Expand All @@ -72,7 +72,7 @@ namespace Bootstrap
setupSearchPaths();
applyEarlyQNetworkAccessManagerWorkaround();

Translator::installTranslators();
Translator::installTranslators(overrideUiLang);
}

// LCOV_EXCL_START
Expand Down
4 changes: 3 additions & 1 deletion src/core/Bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#ifndef KEEPASSXC_BOOTSTRAP_H
#define KEEPASSXC_BOOTSTRAP_H

#include <QString>

namespace Bootstrap
{
void bootstrap();
void bootstrap(const QString& overrideUiLang = {});
void disableCoreDumps();
bool createWindowsDACL();
void setupSearchPaths();
Expand Down
28 changes: 16 additions & 12 deletions src/core/Translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@
/**
* Install all KeePassXC and Qt translators.
*/
void Translator::installTranslators()
void Translator::installTranslators(const QString& overrideLang)
{
QStringList languages;
QString languageSetting = config()->get(Config::GUI_Language).toString();
if (languageSetting.isEmpty() || languageSetting == "system") {
// NOTE: this is a workaround for the terrible way Qt loads languages
// using the QLocale::uiLanguages() approach. Instead, we search each
// language and all country variants in order before moving to the next.
QLocale locale;
languages = locale.uiLanguages();
if (overrideLang.isEmpty()) {
QString languageSetting = config()->get(Config::GUI_Language).toString();
if (languageSetting.isEmpty() || languageSetting == "system") {
// NOTE: this is a workaround for the terrible way Qt loads languages
// using the QLocale::uiLanguages() approach. Instead, we search each
// language and all country variants in order before moving to the next.
QLocale locale;
languages = locale.uiLanguages();
} else {
languages << languageSetting;
}
// Always try to load english last
languages << "en_US";

} else {
languages << languageSetting;
languages << overrideLang;
}

// Always try to load english last
languages << "en_US";

const auto path = resources()->dataPath("translations");
installQtTranslator(languages, path);
if (!installTranslator(languages, path)) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/Translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#define KEEPASSX_TRANSLATOR_H

#include <QMetaType>
#include <QString>

class Translator
{
public:
static void installTranslators();
static void installTranslators(const QString& overrideLang = {});
static QList<QPair<QString, QString>> availableLanguages();

private:
Expand Down
Loading

0 comments on commit 844fafb

Please sign in to comment.