From 38cbb42b58f6ecb9cbd2b06d4d2c5c39bdc6d124 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Sat, 7 Oct 2017 23:13:34 +0100 Subject: [PATCH 001/118] Use the renamed QT ppa (with packages named the same) --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7da65821..60ba4ff5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,10 +23,11 @@ RUN set -x \ RUN set -x \ && add-apt-repository ppa:george-edison55/cmake-3.x +ENV QT_PPA=qt591 ENV QT_VERSION=qt59 RUN set -x \ - && add-apt-repository --yes ppa:beineri/opt-${QT_VERSION}-trusty + && add-apt-repository --yes ppa:beineri/opt-${QT_PPA}-trusty RUN set -x \ From 84508e91da2303967dc28d76433300c48f29cd41 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Sat, 7 Oct 2017 23:30:33 +0100 Subject: [PATCH 002/118] Disable apparmor to use fuse Necessary for an Ubuntu 16.04, Docker 17.09.0-ce host See https://github.com/moby/moby/issues/9448#issuecomment-289950103 --- release-tool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-tool b/release-tool index 680cdca2..24d64f90 100755 --- a/release-tool +++ b/release-tool @@ -615,7 +615,7 @@ build() { logInfo "Launching Docker container to compile sources..." docker run --name "$DOCKER_CONTAINER_NAME" --rm \ - --cap-add SYS_ADMIN --device /dev/fuse \ + --cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \ -e "CC=${CC}" -e "CXX=${CXX}" \ -v "$(realpath "$SRC_DIR"):/keepassxc/src:ro" \ -v "$(realpath "$OUTPUT_DIR"):/keepassxc/out:rw" \ From 1374c68274b8e93b74027f40c56db3eb5c48ab3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 01:46:09 -0600 Subject: [PATCH 003/118] Add .DS_Store (mac os) to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2d9bb4af..b91b15ac 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ release*/ \.vscode/ *.swp + +.DS_Store From c6f83b9ca6a6368c33b3fb315ded32c3423a0f2d Mon Sep 17 00:00:00 2001 From: rockihack Date: Fri, 13 Oct 2017 12:31:57 +0200 Subject: [PATCH 004/118] Fix: Regenerate transform seed and transform master key on save. --- src/core/Database.cpp | 19 +++++++++++++++++++ src/core/Database.h | 1 + src/format/KeePass2Writer.cpp | 8 +++++++- src/format/KeePass2Writer.h | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/core/Database.cpp b/src/core/Database.cpp index d3f87a7b..864dd758 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -257,6 +257,25 @@ bool Database::hasKey() const return m_data.hasKey; } +bool Database::transformKeyWithSeed(const QByteArray& transformSeed) +{ + Q_ASSERT(hasKey()); + + bool ok; + QString errorString; + + QByteArray transformedMasterKey = + m_data.key.transform(transformSeed, transformRounds(), &ok, &errorString); + if (!ok) { + return false; + } + + m_data.transformSeed = transformSeed; + m_data.transformedMasterKey = transformedMasterKey; + + return true; +} + bool Database::verifyKey(const CompositeKey& key) const { Q_ASSERT(hasKey()); diff --git a/src/core/Database.h b/src/core/Database.h index a799e0b3..b08233e5 100644 --- a/src/core/Database.h +++ b/src/core/Database.h @@ -106,6 +106,7 @@ public: */ bool setKey(const CompositeKey& key); bool hasKey() const; + bool transformKeyWithSeed(const QByteArray& transformSeed); bool verifyKey(const CompositeKey& key) const; void recycleEntry(Entry* entry); void recycleGroup(Group* group); diff --git a/src/format/KeePass2Writer.cpp b/src/format/KeePass2Writer.cpp index d63151c8..f8f60f11 100644 --- a/src/format/KeePass2Writer.cpp +++ b/src/format/KeePass2Writer.cpp @@ -45,6 +45,7 @@ void KeePass2Writer::writeDatabase(QIODevice* device, Database* db) m_error = false; m_errorStr.clear(); + QByteArray transformSeed = randomGen()->randomArray(32); QByteArray masterSeed = randomGen()->randomArray(32); QByteArray encryptionIV = randomGen()->randomArray(16); QByteArray protectedStreamKey = randomGen()->randomArray(32); @@ -52,7 +53,12 @@ void KeePass2Writer::writeDatabase(QIODevice* device, Database* db) QByteArray endOfHeader = "\r\n\r\n"; if (db->challengeMasterSeed(masterSeed) == false) { - raiseError("Unable to issue challenge-response."); + raiseError(tr("Unable to issue challenge-response.")); + return; + } + + if (!db->transformKeyWithSeed(transformSeed)) { + raiseError(tr("Unable to calculate master key")); return; } diff --git a/src/format/KeePass2Writer.h b/src/format/KeePass2Writer.h index 1b3436dc..184aa1a7 100644 --- a/src/format/KeePass2Writer.h +++ b/src/format/KeePass2Writer.h @@ -18,6 +18,8 @@ #ifndef KEEPASSX_KEEPASS2WRITER_H #define KEEPASSX_KEEPASS2WRITER_H +#include + #include "format/KeePass2.h" #include "keys/CompositeKey.h" @@ -26,6 +28,8 @@ class QIODevice; class KeePass2Writer { + Q_DECLARE_TR_FUNCTIONS(KeePass2Writer) + public: KeePass2Writer(); void writeDatabase(QIODevice* device, Database* db); From c0182df05ea74e5f59445018b84477ec9b12c5e4 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 16 Oct 2017 16:52:32 +0200 Subject: [PATCH 005/118] Add CLion build directories --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0521a42e..479c589e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ CMakeLists.txt.* build*/ +cmake-build-*/ release*/ .idea/ *.iml From 1cbbcc0d87b8c3d453388b986d6535e5aa5f8967 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 16 Oct 2017 17:01:37 +0200 Subject: [PATCH 006/118] Allow starting AppImage with custom extended QT_PLUGIN_PATH, resolves #1077 --- AppImage-Recipe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppImage-Recipe.sh b/AppImage-Recipe.sh index 2707fe96..2a40458f 100755 --- a/AppImage-Recipe.sh +++ b/AppImage-Recipe.sh @@ -73,7 +73,7 @@ cat << EOF > ./usr/bin/keepassxc_env #!/usr/bin/env bash #export QT_QPA_PLATFORMTHEME=gtk2 export LD_LIBRARY_PATH="..$(dirname ${QT_PLUGIN_PATH})/lib:\${LD_LIBRARY_PATH}" -export QT_PLUGIN_PATH="..${QT_PLUGIN_PATH}" +export QT_PLUGIN_PATH="..${QT_PLUGIN_PATH}:\${KPXC_QT_PLUGIN_PATH}" # unset XDG_DATA_DIRS to make tray icon work in Ubuntu Unity # see https://github.com/probonopd/AppImageKit/issues/351 From bae9dbc4078c6467da631a11eb2d0bf5e34b6915 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 16 Oct 2017 17:47:19 +0200 Subject: [PATCH 007/118] Add distribution information to debug info screen --- CMakeLists.txt | 8 ++++++-- src/config-keepassx.h.cmake | 3 ++- src/gui/AboutDialog.cpp | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6d28a35..ea32e100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,12 @@ set(KEEPASSXC_VERSION_MINOR "2") set(KEEPASSXC_VERSION_PATCH "1") set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION_MAJOR}.${KEEPASSXC_VERSION_MINOR}.${KEEPASSXC_VERSION_PATCH}") -# Special flag for snap builds -set(KEEPASSXC_SNAP_BUILD OFF CACHE BOOL "Set whether this is a build for snap or not") +# Distribution info +set(KEEPASSXC_DIST_TYPE "Other" CACHE STRING "KeePassXC Distribution type") +set_property(CACHE KEEPASSXC_DIST_TYPE PROPERTY STRINGS Snap AppImage Other) +if(NOT KEEPASSXC_DIST_TYPE STREQUAL "Other") + set(KEEPASSXC_DIST True) +endif() if("${CMAKE_C_COMPILER}" MATCHES "clang$" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_COMPILER_IS_CLANG 1) diff --git a/src/config-keepassx.h.cmake b/src/config-keepassx.h.cmake index f89d447c..e0d96e0c 100644 --- a/src/config-keepassx.h.cmake +++ b/src/config-keepassx.h.cmake @@ -16,7 +16,8 @@ #cmakedefine WITH_XC_AUTOTYPE #cmakedefine WITH_XC_YUBIKEY -#cmakedefine KEEPASSXC_SNAP_BUILD +#cmakedefine KEEPASSXC_DIST +#cmakedefine KEEPASSXC_DIST_TYPE "@KEEPASSXC_DIST_TYPE@" #cmakedefine HAVE_PR_SET_DUMPABLE 1 #cmakedefine HAVE_RLIMIT_CORE 1 diff --git a/src/gui/AboutDialog.cpp b/src/gui/AboutDialog.cpp index 0e0f2960..5978cd95 100644 --- a/src/gui/AboutDialog.cpp +++ b/src/gui/AboutDialog.cpp @@ -55,10 +55,14 @@ AboutDialog::AboutDialog(QWidget* parent) QString debugInfo = "KeePassXC - "; debugInfo.append(tr("Version %1\n").arg(KEEPASSX_VERSION)); if (!commitHash.isEmpty()) { - debugInfo.append(tr("Revision: %1").arg(commitHash).append("\n\n")); + debugInfo.append(tr("Revision: %1").arg(commitHash.left(7)).append("\n")); } - debugInfo.append(QString("%1\n- Qt %2\n- %3\n\n") +#ifdef KEEPASSXC_DIST + debugInfo.append(tr("Distribution: %1").arg(KEEPASSXC_DIST_TYPE).append("\n")); +#endif + + debugInfo.append("\n").append(QString("%1\n- Qt %2\n- %3\n\n") .arg(tr("Libraries:")) .arg(QString::fromLocal8Bit(qVersion())) .arg(Crypto::backendVersion())); From 6d433fecef375ca869eea0cba64e4ed7c895619a Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 16 Oct 2017 17:51:16 +0200 Subject: [PATCH 008/118] Set KEEPASSXC_DIST_TYPE when building AppImages and Snaps --- release-tool | 3 ++- snapcraft.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/release-tool b/release-tool index 24d64f90..35163069 100755 --- a/release-tool +++ b/release-tool @@ -598,7 +598,8 @@ build() { # Building on Linux without Docker container logInfo "Configuring build..." cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=Off $CMAKE_OPTIONS \ - -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" "$SRC_DIR" + -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \ + -DKEEPASSXC_DIST_TYPE=AppImage "$SRC_DIR" logInfo "Compiling sources..." make $MAKE_OPTIONS diff --git a/snapcraft.yaml b/snapcraft.yaml index c73b5328..7062802d 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -24,7 +24,7 @@ parts: configflags: - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=/usr - - -DKEEPASSXC_SNAP_BUILD=ON + - -DKEEPASSXC_DIST_TYPE=Snap - -DWITH_TESTS=OFF - -DWITH_XC_AUTOTYPE=ON - -DWITH_XC_HTTP=ON From ec8c99c3b24d9c09858210ccb4f2afa4e8586374 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 17 Oct 2017 12:56:42 +0200 Subject: [PATCH 009/118] Fix remaining uses of KEEPASSXC_SNAP_BUILD --- CMakeLists.txt | 9 +++++++-- src/config-keepassx.h.cmake | 2 ++ src/core/FilePath.cpp | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea32e100..3fddb457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,10 +53,15 @@ set(KEEPASSXC_VERSION_PATCH "1") set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION_MAJOR}.${KEEPASSXC_VERSION_MINOR}.${KEEPASSXC_VERSION_PATCH}") # Distribution info +set(KEEPASSXC_DIST True) set(KEEPASSXC_DIST_TYPE "Other" CACHE STRING "KeePassXC Distribution type") set_property(CACHE KEEPASSXC_DIST_TYPE PROPERTY STRINGS Snap AppImage Other) -if(NOT KEEPASSXC_DIST_TYPE STREQUAL "Other") - set(KEEPASSXC_DIST True) +if(KEEPASSXC_DIST_TYPE STREQUAL "Snap") + set(KEEPASSXC_DIST_SNAP True) +elseif(KEEPASSXC_DIST_TYPE STREQUAL "AppImage") + set(KEEPASSXC_DIST_APPIMAGE True) +elseif(KEEPASSXC_DIST_TYPE STREQUAL "Other") + unset(KEEPASSXC_DIST) endif() if("${CMAKE_C_COMPILER}" MATCHES "clang$" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") diff --git a/src/config-keepassx.h.cmake b/src/config-keepassx.h.cmake index e0d96e0c..e06c6938 100644 --- a/src/config-keepassx.h.cmake +++ b/src/config-keepassx.h.cmake @@ -18,6 +18,8 @@ #cmakedefine KEEPASSXC_DIST #cmakedefine KEEPASSXC_DIST_TYPE "@KEEPASSXC_DIST_TYPE@" +#cmakedefine KEEPASSXC_DIST_SNAP +#cmakedefine KEEPASSXC_DIST_APPIMAGE #cmakedefine HAVE_PR_SET_DUMPABLE 1 #cmakedefine HAVE_RLIMIT_CORE 1 diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index 90311b40..b5c9d102 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -91,7 +91,7 @@ QString FilePath::pluginPath(const QString& name) QIcon FilePath::applicationIcon() { -#ifdef KEEPASSXC_SNAP_BUILD +#ifdef KEEPASSXC_DIST_SNAP return icon("apps", "keepassxc", false); #else return icon("apps", "keepassxc"); @@ -100,7 +100,7 @@ QIcon FilePath::applicationIcon() QIcon FilePath::trayIconLocked() { -#ifdef KEEPASSXC_SNAP_BUILD +#ifdef KEEPASSXC_DIST_SNAP return icon("apps", "keepassxc-locked", false); #else return icon("apps", "keepassxc-locked"); @@ -109,7 +109,7 @@ QIcon FilePath::trayIconLocked() QIcon FilePath::trayIconUnlocked() { -#ifdef KEEPASSXC_SNAP_BUILD +#ifdef KEEPASSXC_DIST_SNAP return icon("apps", "keepassxc-unlocked", false); #else return icon("apps", "keepassxc-unlocked"); From 75cfe1c5dd1c23523135d38e751f4cedba5cd0dd Mon Sep 17 00:00:00 2001 From: frostasm Date: Wed, 11 Oct 2017 13:10:40 +0300 Subject: [PATCH 010/118] Add the auto hide functionality to the MessageWidget --- src/gui/MessageWidget.cpp | 36 +++++++++++++++++++++++++++++++++--- src/gui/MessageWidget.h | 9 +++++++++ src/http/OptionDialog.cpp | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/gui/MessageWidget.cpp b/src/gui/MessageWidget.cpp index de981b92..b3d014c3 100644 --- a/src/gui/MessageWidget.cpp +++ b/src/gui/MessageWidget.cpp @@ -18,20 +18,50 @@ #include "MessageWidget.h" -MessageWidget::MessageWidget(QWidget* parent) - :KMessageWidget(parent) -{ +#include "QTimer" +MessageWidget::MessageWidget(QWidget* parent) + : KMessageWidget(parent) + , m_autoHideTimer(new QTimer(this)) + , m_autoHideTimeout(6000) +{ + m_autoHideTimer->setSingleShot(true); + connect(m_autoHideTimer, SIGNAL(timeout()), this, SLOT(animatedHide())); + connect(this, SIGNAL(hideAnimationFinished()), m_autoHideTimer, SLOT(stop())); +} + +int MessageWidget::autoHideTimeout() const +{ + return m_autoHideTimeout; } void MessageWidget::showMessage(const QString& text, MessageWidget::MessageType type) +{ + showMessage(text, type, m_autoHideTimeout); +} + +void MessageWidget::showMessage(const QString &text, KMessageWidget::MessageType type, int autoHideTimeout) { setMessageType(type); setText(text); animatedShow(); + if (autoHideTimeout > 0) { + m_autoHideTimer->start(autoHideTimeout); + } else { + m_autoHideTimer->stop(); + } } void MessageWidget::hideMessage() { animatedHide(); + m_autoHideTimer->stop(); +} + +void MessageWidget::setAutoHideTimeout(int autoHideTimeout) +{ + m_autoHideTimeout = autoHideTimeout; + if (autoHideTimeout <= 0) { + m_autoHideTimer->stop(); + } } diff --git a/src/gui/MessageWidget.h b/src/gui/MessageWidget.h index 03ebee3e..4a25737b 100644 --- a/src/gui/MessageWidget.h +++ b/src/gui/MessageWidget.h @@ -21,6 +21,8 @@ #include "gui/KMessageWidget.h" +class QTimer; + class MessageWidget : public KMessageWidget { Q_OBJECT @@ -28,10 +30,17 @@ class MessageWidget : public KMessageWidget public: explicit MessageWidget(QWidget* parent = 0); + int autoHideTimeout() const; + public slots: void showMessage(const QString& text, MessageWidget::MessageType type); + void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout); void hideMessage(); + void setAutoHideTimeout(int autoHideTimeout); +private: + QTimer* m_autoHideTimer; + int m_autoHideTimeout; }; #endif // MESSAGEWIDGET_H diff --git a/src/http/OptionDialog.cpp b/src/http/OptionDialog.cpp index 9fb66bd6..b0823c7b 100644 --- a/src/http/OptionDialog.cpp +++ b/src/http/OptionDialog.cpp @@ -35,6 +35,7 @@ OptionDialog::OptionDialog(QWidget *parent) : m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning")); m_ui->warningWidget->setCloseButtonVisible(false); + m_ui->warningWidget->setAutoHideTimeout(-1); m_ui->tabWidget->setEnabled(m_ui->enableHttpServer->isChecked()); connect(m_ui->enableHttpServer, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool))); From f38fe5a9dda5f17393373c67c0c4735ad578c95d Mon Sep 17 00:00:00 2001 From: frostasm Date: Thu, 19 Oct 2017 21:46:09 +0300 Subject: [PATCH 011/118] Disable automatic hiding of an information message for YubiKey --- src/gui/DatabaseWidget.cpp | 5 +++-- src/gui/DatabaseWidget.h | 3 ++- src/gui/MainWindow.cpp | 14 ++++++++------ src/gui/MainWindow.h | 6 ++++-- src/gui/MessageWidget.cpp | 5 ++++- src/gui/MessageWidget.h | 3 +++ src/http/OptionDialog.cpp | 2 +- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3a39bddc..7fbcbe35 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1325,9 +1325,10 @@ void DatabaseWidget::closeUnlockDialog() m_unlockDatabaseDialog->close(); } -void DatabaseWidget::showMessage(const QString& text, MessageWidget::MessageType type) +void DatabaseWidget::showMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, int autoHideTimeout) { - m_messageWidget->showMessage(text, type); + m_messageWidget->setCloseButtonVisible(showClosebutton); + m_messageWidget->showMessage(text, type, autoHideTimeout); } void DatabaseWidget::hideMessage() diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 734e979e..93482000 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -166,7 +166,8 @@ public slots: void setSearchLimitGroup(bool state); void endSearch(); - void showMessage(const QString& text, MessageWidget::MessageType type); + void showMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); void hideMessage(); private slots: diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 14531a4f..cfa18597 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -952,16 +952,17 @@ bool MainWindow::isTrayIconEnabled() const && QSystemTrayIcon::isSystemTrayAvailable(); } -void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton) +void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, + int autoHideTimeout) { m_ui->globalMessageWidget->setCloseButtonVisible(showClosebutton); - m_ui->globalMessageWidget->showMessage(text, type); + m_ui->globalMessageWidget->showMessage(text, type, autoHideTimeout); } -void MainWindow::displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton) +void MainWindow::displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, + int autoHideTimeout) { - m_ui->globalMessageWidget->setCloseButtonVisible(showClosebutton); - m_ui->tabWidget->currentDatabaseWidget()->showMessage(text, type); + m_ui->tabWidget->currentDatabaseWidget()->showMessage(text, type, showClosebutton, autoHideTimeout); } void MainWindow::hideGlobalMessage() @@ -978,7 +979,8 @@ void MainWindow::hideTabMessage() void MainWindow::showYubiKeyPopup() { - displayGlobalMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information, false); + displayGlobalMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information, + false, MessageWidget::DisableAutoHide); setEnabled(false); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index caf3f585..ea17107a 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -54,8 +54,10 @@ public slots: void openDatabase(const QString& fileName, const QString& pw = QString(), const QString& keyFile = QString()); void appExit(); - void displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true); - void displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true); + void displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); + void displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); void hideGlobalMessage(); void showYubiKeyPopup(); void hideYubiKeyPopup(); diff --git a/src/gui/MessageWidget.cpp b/src/gui/MessageWidget.cpp index b3d014c3..2be29805 100644 --- a/src/gui/MessageWidget.cpp +++ b/src/gui/MessageWidget.cpp @@ -20,10 +20,13 @@ #include "QTimer" +const int MessageWidget::DefaultAutoHideTimeout = 6000; +const int MessageWidget::DisableAutoHide = -1; + MessageWidget::MessageWidget(QWidget* parent) : KMessageWidget(parent) , m_autoHideTimer(new QTimer(this)) - , m_autoHideTimeout(6000) + , m_autoHideTimeout(DefaultAutoHideTimeout) { m_autoHideTimer->setSingleShot(true); connect(m_autoHideTimer, SIGNAL(timeout()), this, SLOT(animatedHide())); diff --git a/src/gui/MessageWidget.h b/src/gui/MessageWidget.h index 4a25737b..c29c320b 100644 --- a/src/gui/MessageWidget.h +++ b/src/gui/MessageWidget.h @@ -32,6 +32,9 @@ public: int autoHideTimeout() const; + static const int DefaultAutoHideTimeout; + static const int DisableAutoHide; + public slots: void showMessage(const QString& text, MessageWidget::MessageType type); void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout); diff --git a/src/http/OptionDialog.cpp b/src/http/OptionDialog.cpp index b0823c7b..03ae6e9c 100644 --- a/src/http/OptionDialog.cpp +++ b/src/http/OptionDialog.cpp @@ -35,7 +35,7 @@ OptionDialog::OptionDialog(QWidget *parent) : m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning")); m_ui->warningWidget->setCloseButtonVisible(false); - m_ui->warningWidget->setAutoHideTimeout(-1); + m_ui->warningWidget->setAutoHideTimeout(MessageWidget::DisableAutoHide); m_ui->tabWidget->setEnabled(m_ui->enableHttpServer->isChecked()); connect(m_ui->enableHttpServer, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool))); From 72a6c3445027ec312864e5f6928e4794fc39fe31 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 17 Oct 2017 13:42:12 +0200 Subject: [PATCH 012/118] Add AppStream AppData file, resolves #1066 --- share/CMakeLists.txt | 3 +- share/linux/org.keepassxc.appdata.xml | 200 ++++++++++++++++++ ...eepassxc.desktop => org.keepassxc.desktop} | 0 snapcraft.yaml | 8 +- 4 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 share/linux/org.keepassxc.appdata.xml rename share/linux/{keepassxc.desktop => org.keepassxc.desktop} (100%) diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index a609add7..6323ece8 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -30,7 +30,8 @@ if(UNIX AND NOT APPLE) install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor FILES_MATCHING PATTERN "application-x-keepassxc.png" PATTERN "application-x-keepassxc.svgz" PATTERN "status" EXCLUDE PATTERN "actions" EXCLUDE PATTERN "categories" EXCLUDE) - install(FILES linux/keepassxc.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) + install(FILES linux/org.keepassxc.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) + install(FILES linux/org.keepassxc.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) install(FILES linux/keepassxc.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages) endif(UNIX AND NOT APPLE) diff --git a/share/linux/org.keepassxc.appdata.xml b/share/linux/org.keepassxc.appdata.xml new file mode 100644 index 00000000..3a5eb2c5 --- /dev/null +++ b/share/linux/org.keepassxc.appdata.xml @@ -0,0 +1,200 @@ + + + + org.keepassxc + KeePassXC + CC-BY-3.0 + GPL-3.0+ + keepassxc + https://keepassxc.org + + application/x-keepass2 + + Community-driven port of the Windows application “KeePass Password Safe” + +

+ KeePassXC is an application for people with extremely high demands on secure + personal data management. It has a light interface, is cross-platform and + published under the terms of the GNU General Public License. +

+
+ + org.keepassxc.desktop + + + + https://keepassxc.org/images/screenshots/linux/screen_001.png + + + https://keepassxc.org/images/screenshots/linux/screen_002.png + + + https://keepassxc.org/images/screenshots/linux/screen_003.png + + + https://keepassxc.org/images/screenshots/linux/screen_004.png + + + https://keepassxc.org/images/screenshots/linux/screen_005.png + + + https://keepassxc.org/images/screenshots/linux/screen_006.png + + + https://keepassxc.org/images/screenshots/linux/screen_007.png + + + https://keepassxc.org/images/screenshots/linux/screen_008.png + + + https://keepassxc.org/images/screenshots/linux/screen_009.png + + + https://keepassxc.org/images/screenshots/linux/screen_010.png + + + https://keepassxc.org/images/screenshots/linux/screen_011.png + + + https://keepassxc.org/images/screenshots/linux/screen_012.png + + + https://keepassxc.org/images/screenshots/linux/screen_013.png + + + https://keepassxc.org/images/screenshots/linux/screen_014.png + + + + + + +
    +
  • Corrected multiple snap issues [#934, #1011]
  • +
  • Corrected multiple custom icon issues [#708, #719, #994]
  • +
  • Corrected multiple Yubikey issues [#880]
  • +
  • Fixed single instance preventing load on occasion [#997]
  • +
  • Keep entry history when merging databases [#970]
  • +
  • Prevent data loss if passwords were mismatched [#1007]
  • +
  • Fixed crash after merge [#941]
  • +
  • Added configurable auto-type default delay [#703]
  • +
  • Unlock database dialog window comes to front [#663]
  • +
  • Translation and compiling fixes
  • +
+
+
+ + +
    +
  • Added YubiKey 2FA integration for unlocking databases [#127]
  • +
  • Added TOTP support [#519]
  • +
  • Added CSV import tool [#146, #490]
  • +
  • Added KeePassXC CLI tool [#254]
  • +
  • Added diceware password generator [#373]
  • +
  • Added support for entry references [#370, #378]
  • +
  • Added support for Twofish encryption [#167]
  • +
  • Enabled DEP and ASLR for in-memory protection [#371]
  • +
  • Enabled single instance mode [#510]
  • +
  • Enabled portable mode [#645]
  • +
  • Enabled database lock on screensaver and session lock [#545]
  • +
  • Redesigned welcome screen with common features and recent databases [#292]
  • +
  • Multiple updates to search behavior [#168, #213, #374, #471, #603, #654]
  • +
  • Added auto-type fields {CLEARFIELD}, {SPACE}, {{}, {}} [#267, #427, #480]
  • +
  • Fixed auto-type errors on Linux [#550]
  • +
  • Prompt user prior to executing a cmd:// URL [#235]
  • +
  • Entry attributes can be protected (hidden) [#220]
  • +
  • Added extended ascii to password generator [#538]
  • +
  • Added new database icon to toolbar [#289]
  • +
  • Added context menu entry to empty recycle bin in databases [#520]
  • +
  • Added "apply" button to entry and group edit windows [#624]
  • +
  • Added macOS tray icon and enabled minimize on close [#583]
  • +
  • Fixed issues with unclean shutdowns [#170, #580]
  • +
  • Changed keyboard shortcut to create new database to CTRL+SHIFT+N [#515]
  • +
  • Compare window title to entry URLs [#556]
  • +
  • Implemented inline error messages [#162]
  • +
  • Ignore group expansion and other minor changes when making database "dirty" [#464]
  • +
  • Updated license and copyright information on souce files [#632]
  • +
  • Added contributors list to about dialog [#629]
  • +
+
+
+ + +
    +
  • Bumped KeePassHTTP version to 1.8.4.2
  • +
  • KeePassHTTP confirmation window comes to foreground [#466]
  • +
+
+
+ + +
    +
  • Fix possible overflow in zxcvbn library [#363]
  • +
  • Revert HiDPI setting to avoid problems on laptop screens [#332]
  • +
  • Set file meta properties in Windows executable [#330]
  • +
  • Suppress error message when auto-reloading a locked database [#345]
  • +
  • Improve usability of question dialog when database is already locked by a different instance [#346]
  • +
  • Fix compiler warnings in QHttp library [#351]
  • +
  • Use unified toolbar on Mac OS X [#361]
  • +
  • Fix an issue on X11 where the main window would be raised instead of closed on Alt+F4 [#362]
  • +
+
+
+ + +
    +
  • Ask for save location when creating a new database [#302]
  • +
  • Remove Libmicrohttpd dependency to clean up the code and ensure better OS X compatibility [#317, #265]
  • +
  • Prevent Qt from degrading Wifi network performance on certain platforms [#318]
  • +
  • Visually refine user interface on OS X and other platforms [#299]
  • +
  • Remove unusable tray icon setting on OS X [#293]
  • +
  • Fix compositing glitches on Ubuntu and prevent flashing when minimizing to the tray at startup [#307]
  • +
  • Fix AppImage tray icon on Ubuntu [#277, #273]
  • +
  • Fix global menu disappearing after restoring KeePassXC from the tray on Ubuntu [#276]
  • +
  • Fix result order in entry search [#320]
  • +
  • Enable HiDPI scaling on supported platforms [#315]
  • +
  • Remove empty directories from installation target [#282]
  • +
+
+
+ + +
    +
  • Enabled HTTP plugin build; plugin is disabled by default and limited to localhost [#147]
  • +
  • Escape HTML in dialog boxes [#247]
  • +
  • Corrected crashes in favicon download and password generator [#233, #226]
  • +
  • Increase font size of password meter [#228]
  • +
  • Fixed compatibility with Qt 5.8 [#211]
  • +
  • Use consistent button heights in password generator [#229]
  • +
+
+
+ + +
    +
  • Show unlock dialog when using autotype on a closed database [#10, #89]
  • +
  • Show different tray icon when database is locked [#37, #46]
  • +
  • Support autotype on Windows and OS X [#42, #60, #63]
  • +
  • Add delay feature to autotype [#76, #77]
  • +
  • Add password strength meter [#84, #92]
  • +
  • Add option for automatically locking the database when minimizing the window [#57]
  • +
  • Add feature to download favicons and use them as entry icons [#30]
  • +
  • Automatically reload and merge database when the file changed on disk [#22, #33, #93]
  • +
  • Add tool for merging two databases [#22, #47, #143]
  • +
  • Add --pw-stdin commandline option to unlock the database by providing a password on STDIN [#54]
  • +
  • Add utility script for reading the database password from KWallet [#55]
  • +
  • Fix some KeePassHTTP settings not being remembered [#34, #65]
  • +
  • Make search box persistent [#15, #67, #157]
  • +
  • Enhance search feature by scoping the search to selected group [#16, #118]
  • +
  • Improve interaction between search field and entry list [#131, #141]
  • +
  • Add stand-alone password-generator [#18, #92]
  • +
  • Don't require password repetition when password is visible [#27, #92]
  • +
  • Add support for entry attributes in autotype sequences [#107]
  • +
  • Always focus password field when opening the database unlock widget [#116, #117]
  • +
  • Fix compilation errors on various platforms [#53, #126, #130]
  • +
  • Restructure and improve kdbx-extract utility [#160]
  • +
+
+
+
+
diff --git a/share/linux/keepassxc.desktop b/share/linux/org.keepassxc.desktop similarity index 100% rename from share/linux/keepassxc.desktop rename to share/linux/org.keepassxc.desktop diff --git a/snapcraft.yaml b/snapcraft.yaml index 7062802d..2b58df28 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,18 +1,18 @@ name: keepassxc version: 2.2.1 grade: stable -summary: community driven port of the windows application “Keepass Password Safe” +summary: Community-driven port of the Windows application “KeePass Password Safe” description: | KeePassXC is an application for people with extremely high demands on secure - personal data management. It has a light interface, is cross platform and - is published under the terms of the GNU General Public License. + personal data management. It has a light interface, is cross-platform and + published under the terms of the GNU General Public License. confinement: strict apps: keepassxc: command: desktop-launch keepassxc plugs: [unity7, x11, opengl, gsettings, home, network, network-bind, removable-media, raw-usb] - desktop: usr/share/applications/keepassxc.desktop + desktop: usr/share/applications/org.keepassxc.desktop cli: command: keepassxc-cli plugs: [gsettings, home, removable-media, raw-usb] From b30eb597911a97d968ebd366f286e21b10b91f30 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 17 Oct 2017 14:12:02 +0200 Subject: [PATCH 013/118] Extend desktop file and name it according to the freedesktop specification --- share/linux/keepassxc.xml | 2 +- share/linux/org.keepassxc.desktop | 7 +++++-- snapcraft.yaml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/share/linux/keepassxc.xml b/share/linux/keepassxc.xml index 757047d2..b26b4db2 100644 --- a/share/linux/keepassxc.xml +++ b/share/linux/keepassxc.xml @@ -1,7 +1,7 @@ - KeePass 2 database + KeePass 2 Database diff --git a/share/linux/org.keepassxc.desktop b/share/linux/org.keepassxc.desktop index 1e72c4f8..fd94fdcd 100644 --- a/share/linux/org.keepassxc.desktop +++ b/share/linux/org.keepassxc.desktop @@ -1,13 +1,16 @@ [Desktop Entry] Name=KeePassXC -GenericName=Community Password Manager +GenericName=Password Manager GenericName[de]=Passwortverwaltung GenericName[es]=Gestor de contraseñas GenericName[fr]=Gestionnaire de mot de passe GenericName[ru]=менеджер паролей +Comment=Community-driven port of the Windows application “KeePass Password Safe” Exec=keepassxc %f +TryExec=keepassxc Icon=keepassxc Terminal=false Type=Application -Categories=Qt;Utility; +Version=1.0 +Categories=Utility;Security;Qt MimeType=application/x-keepass2; diff --git a/snapcraft.yaml b/snapcraft.yaml index 2b58df28..a3e4004c 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -42,7 +42,7 @@ parts: - libyubikey-dev - libykpers-1-dev install: | - sed -i 's|Icon=keepassxc|Icon=${SNAP}/usr/share/icons/hicolor/256x256/apps/keepassxc.png|g' $SNAPCRAFT_PART_INSTALL/usr/share/applications/keepassxc.desktop + sed -i 's|Icon=keepassxc|Icon=${SNAP}/usr/share/icons/hicolor/256x256/apps/keepassxc.png|g' $SNAPCRAFT_PART_INSTALL/usr/share/applications/org.keepassxc.desktop after: [desktop-qt5] # Redefine desktop-qt5 stage packages to work with Ubuntu 17.04 From eb977b8021a997abdb973483ec68ca46ff195e13 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 17 Oct 2017 14:36:18 +0200 Subject: [PATCH 014/118] Check AppStream info file before merging releases --- release-tool | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/release-tool b/release-tool index 35163069..c3fa84d3 100755 --- a/release-tool +++ b/release-tool @@ -257,7 +257,30 @@ checkChangeLog() { grep -qPzo "${RELEASE_NAME} \(\d{4}-\d{2}-\d{2}\)\n=+\n" CHANGELOG if [ $? -ne 0 ]; then - exitError "CHANGELOG does not contain any information about the '${RELEASE_NAME}' release!" + exitError "'CHANGELOG' has not been updated to the '${RELEASE_NAME}' release!" + fi +} + +checkAppStreamInfo() { + if [ ! -f share/linux/org.keepassxc.appdata.xml ]; then + exitError "No AppStream info file found!" + fi + + grep -qPzo "" share/linux/org.keepassxc.appdata.xml + if [ $? -ne 0 ]; then + exitError "'share/linux/org.keepassxc.appdata.xml' has not been updated to the '${RELEASE_NAME}' release!" + fi +} + +checkSnapcraft() { + if [ ! -f snapcraft.yaml ]; then + echo "No snapcraft file found!" + return + fi + + grep -qPzo "version: ${RELEASE_NAME}" snapcraft.yaml + if [ $? -ne 0 ]; then + exitError "'snapcraft.yaml' has not been updated to the '${RELEASE_NAME}' release!" fi } @@ -273,18 +296,6 @@ checkTransifexCommandExists() { fi } -checkSnapcraft() { - if [ ! -f snapcraft.yaml ]; then - echo "No snapcraft file found!" - return - fi - - grep -qPzo "version: ${RELEASE_NAME}" snapcraft.yaml - if [ $? -ne 0 ]; then - exitError "snapcraft.yaml has not been updated to the '${RELEASE_NAME}' release!" - fi -} - performChecks() { logInfo "Performing basic checks..." @@ -309,6 +320,7 @@ performChecks() { checkVersionInCMake checkChangeLog + checkAppStreamInfo checkSnapcraft logInfo "\e[1m\e[32mAll checks passed!\e[0m" From d3208bddb0a01e0ab145e2c8d51f0429023877bd Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 17 Oct 2017 14:54:11 +0200 Subject: [PATCH 015/118] Enhance lupdate-qt5 check --- release-tool | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/release-tool b/release-tool index c3fa84d3..a1d23b40 100755 --- a/release-tool +++ b/release-tool @@ -289,10 +289,15 @@ checkTransifexCommandExists() { if [ 0 -ne $? ]; then exitError "Transifex tool 'tx' not installed! Please install it using 'pip install transifex-client'" fi +} - command -v lupdate-qt5 > /dev/null - if [ 0 -ne $? ]; then - exitError "Qt Linguist tool (lupdate-qt5) is not installed! Please install using 'apt install qttools5-dev-tools'" +checkQt5LUpdateExists() { + command -v lupdate > /dev/null + if [ 0 -eq $? ] && ! $(lupdate -version | grep -q "lupdate version 5\."); then + command -v lupdate-qt5 > /dev/null + if [ 0 -ne $? ]; then + exitError "Qt Linguist tool (lupdate-qt5) is not installed! Please install using 'apt install qttools5-dev-tools'" + fi fi } @@ -307,6 +312,7 @@ performChecks() { logInfo "Validating toolset and repository..." checkTransifexCommandExists + checkQt5LUpdateExists checkGitRepository checkReleaseDoesNotExist checkWorkingTreeClean From 5e0df62d7adc951aa05bdb064eddd23f50ab87be Mon Sep 17 00:00:00 2001 From: frostasm Date: Sat, 14 Oct 2017 15:41:45 +0300 Subject: [PATCH 016/118] Add processing of the url placeholders --- src/core/Entry.cpp | 92 ++++++++++++++++++++++++++++++++++++++------- src/core/Entry.h | 17 +++++++++ tests/TestEntry.cpp | 32 ++++++++++++++++ tests/TestEntry.h | 1 + 4 files changed, 128 insertions(+), 14 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 464628dc..867e68ea 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -755,23 +755,28 @@ QString Entry::resolvePlaceholder(const QString& str) const { QString result = str; - const QList keyList = attributes()->keys(); - for (const QString& key : keyList) { - Qt::CaseSensitivity cs = Qt::CaseInsensitive; - QString k = key; + const UrlPlaceholderType placeholderType = urlPlaceholderType(str); + if (placeholderType != UrlPlaceholderType::NotUrl) { + return resolveUrlPlaceholder(url(), placeholderType); + } else { + const QList keyList = attributes()->keys(); + for (const QString& key : keyList) { + Qt::CaseSensitivity cs = Qt::CaseInsensitive; + QString k = key; - if (!EntryAttributes::isDefaultAttribute(key)) { - cs = Qt::CaseSensitive; - k.prepend("{S:"); - } else { - k.prepend("{"); - } + if (!EntryAttributes::isDefaultAttribute(key)) { + cs = Qt::CaseSensitive; + k.prepend("{S:"); + } else { + k.prepend("{"); + } - k.append("}"); - if (result.compare(k,cs)==0) { - result.replace(result,attributes()->value(key)); - break; + k.append("}"); + if (result.compare(k,cs)==0) { + result.replace(result,attributes()->value(key)); + break; + } } } @@ -829,3 +834,62 @@ QString Entry::resolveUrl(const QString& url) const // No valid http URL's found return QString(""); } + +QString Entry::resolveUrlPlaceholder(const QString &strUrl, Entry::UrlPlaceholderType placeholderType) const +{ + QUrl qurl(strUrl); + if (!qurl.isValid()) + return QString(); + + switch (placeholderType) { + case UrlPlaceholderType::FullUrl: + return strUrl; + case UrlPlaceholderType::WithoutScheme: + return qurl.toString(QUrl::RemoveScheme | QUrl::FullyDecoded); + case UrlPlaceholderType::Scheme: + return qurl.scheme(); + case UrlPlaceholderType::Host: + return qurl.host(); + case UrlPlaceholderType::Port: + return QString::number(qurl.port()); + case UrlPlaceholderType::Path: + return qurl.path(); + case UrlPlaceholderType::Query: + return qurl.query(); + case UrlPlaceholderType::Fragment: + return qurl.fragment(); + case UrlPlaceholderType::UserInfo: + return qurl.userInfo(); + case UrlPlaceholderType::UserName: + return qurl.userName(); + case UrlPlaceholderType::Password: + return qurl.password(); + default: + Q_ASSERT(false); + break; + } + + return QString(); +} + +Entry::UrlPlaceholderType Entry::urlPlaceholderType(const QString &placeholder) const +{ + static const QMap urlPlaceholders { + { QStringLiteral("{URL}"), UrlPlaceholderType::FullUrl }, + { QStringLiteral("{URL:RMVSCM}"), UrlPlaceholderType::WithoutScheme }, + { QStringLiteral("{URL:WITHOUTSCHEME}"), UrlPlaceholderType::WithoutScheme }, + { QStringLiteral("{URL:SCM}"), UrlPlaceholderType::Scheme }, + { QStringLiteral("{URL:SCHEME}"), UrlPlaceholderType::Scheme }, + { QStringLiteral("{URL:HOST}"), UrlPlaceholderType::Host }, + { QStringLiteral("{URL:PORT}"), UrlPlaceholderType::Port }, + { QStringLiteral("{URL:PATH}"), UrlPlaceholderType::Path }, + { QStringLiteral("{URL:QUERY}"), UrlPlaceholderType::Query }, + { QStringLiteral("{URL:FRAGMENT}"), UrlPlaceholderType::Fragment }, + { QStringLiteral("{URL:USERINFO}"), UrlPlaceholderType::UserInfo }, + { QStringLiteral("{URL:USERNAME}"), UrlPlaceholderType::UserName }, + { QStringLiteral("{URL:PASSWORD}"), UrlPlaceholderType::Password } + }; + + UrlPlaceholderType result = urlPlaceholders.value(placeholder.toUpper(), UrlPlaceholderType::NotUrl); + return result; +} diff --git a/src/core/Entry.h b/src/core/Entry.h index a37637c2..51208c9e 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -134,6 +134,21 @@ public: }; Q_DECLARE_FLAGS(CloneFlags, CloneFlag) + enum class UrlPlaceholderType { + NotUrl, + FullUrl, + WithoutScheme, + Scheme, + Host, + Port, + Path, + Query, + Fragment, + UserInfo, + UserName, + Password, + }; + /** * Creates a duplicate of this entry except that the returned entry isn't * part of any group. @@ -145,6 +160,8 @@ public: QString maskPasswordPlaceholders(const QString& str) const; QString resolveMultiplePlaceholders(const QString& str) const; QString resolvePlaceholder(const QString& str) const; + QString resolveUrlPlaceholder(const QString& url, UrlPlaceholderType placeholderType) const; + UrlPlaceholderType urlPlaceholderType(const QString& placeholder) const; QString resolveUrl(const QString& url) const; /** diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 84ad0318..056dbc93 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -158,3 +158,35 @@ void TestEntry::testResolveUrl() delete entry; } + +void TestEntry::testResolveUrlPlaceholders() +{ + Entry* entry = new Entry(); + entry->setUrl("https://user:pw@keepassxc.org:80/path/example.php?q=e&s=t+2#fragment"); + + QString rmvscm("//user:pw@keepassxc.org:80/path/example.php?q=e&s=t+2#fragment"); // Entry URL without scheme name. + QString scm("https"); // Scheme name of the entry URL. + QString host("keepassxc.org"); // Host component of the entry URL. + QString port("80"); // Port number of the entry URL. + QString path("/path/example.php"); // Path component of the entry URL. + QString query("q=e&s=t+2"); // Query information of the entry URL. + QString userinfo("user:pw"); // User information of the entry URL. + QString username("user"); // User name of the entry URL. + QString password("pw"); // Password of the entry URL. + QString fragment("fragment"); // Password of the entry URL. + + QCOMPARE(entry->resolvePlaceholder("{URL:RMVSCM}"), rmvscm); + QCOMPARE(entry->resolvePlaceholder("{URL:WITHOUTSCHEME}"), rmvscm); + QCOMPARE(entry->resolvePlaceholder("{URL:SCM}"), scm); + QCOMPARE(entry->resolvePlaceholder("{URL:SCHEME}"), scm); + QCOMPARE(entry->resolvePlaceholder("{URL:HOST}"), host); + QCOMPARE(entry->resolvePlaceholder("{URL:PORT}"), port); + QCOMPARE(entry->resolvePlaceholder("{URL:PATH}"), path); + QCOMPARE(entry->resolvePlaceholder("{URL:QUERY}"), query); + QCOMPARE(entry->resolvePlaceholder("{URL:USERINFO}"), userinfo); + QCOMPARE(entry->resolvePlaceholder("{URL:USERNAME}"), username); + QCOMPARE(entry->resolvePlaceholder("{URL:PASSWORD}"), password); + QCOMPARE(entry->resolvePlaceholder("{URL:FRAGMENT}"), fragment); + + delete entry; +} diff --git a/tests/TestEntry.h b/tests/TestEntry.h index 3f6d20ee..febdf085 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -32,6 +32,7 @@ private slots: void testCopyDataFrom(); void testClone(); void testResolveUrl(); + void testResolveUrlPlaceholders(); }; #endif // KEEPASSX_TESTENTRY_H From e81d8beb191eab920f165fa4086779915490e77a Mon Sep 17 00:00:00 2001 From: frostasm Date: Sat, 14 Oct 2017 19:23:22 +0300 Subject: [PATCH 017/118] Refactor Entry::resolvePlaceholder function --- src/core/Entry.cpp | 229 +++++++++++++++++++++++++-------------------- src/core/Entry.h | 34 ++++--- 2 files changed, 149 insertions(+), 114 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 867e68ea..1a1dff02 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -751,56 +751,142 @@ QString Entry::resolveMultiplePlaceholders(const QString& str) const return result; } -QString Entry::resolvePlaceholder(const QString& str) const +QString Entry::resolvePlaceholder(const QString& placeholder) const { - QString result = str; + const PlaceholderType placeholderType = this->placeholderType(placeholder); + switch (placeholderType) { + case PlaceholderType::NotPlaceholder: + return placeholder; + case PlaceholderType::Unknown: + qWarning("Can't resolve placeholder '%s' for entry with uuid %s", qPrintable(placeholder), + qPrintable(uuid().toHex())); + return placeholder; + case PlaceholderType::Title: + return title(); + case PlaceholderType::UserName: + return username(); + case PlaceholderType::Password: + return password(); + case PlaceholderType::Notes: + return notes(); + case PlaceholderType::Totp: + return totp(); + case PlaceholderType::Url: + case PlaceholderType::UrlWithoutScheme: + case PlaceholderType::UrlScheme: + case PlaceholderType::UrlHost: + case PlaceholderType::UrlPort: + case PlaceholderType::UrlPath: + case PlaceholderType::UrlQuery: + case PlaceholderType::UrlFragment: + case PlaceholderType::UrlUserInfo: + case PlaceholderType::UrlUserName: + case PlaceholderType::UrlPassword: + return resolveUrlPlaceholder(placeholderType); + case PlaceholderType::CustomAttribute: { + const QString key = placeholder.mid(3, placeholder.length() - 4); // {S:attribute} => mid(3, len - 4) + return attributes()->hasKey(key) ? attributes()->value(key) : placeholder; + } + case PlaceholderType::Reference: { + // resolving references in format: {REF:@I:} + // using format from http://keepass.info/help/base/fieldrefs.html at the time of writing, + // but supporting lookups of standard fields and references by UUID only - const UrlPlaceholderType placeholderType = urlPlaceholderType(str); - if (placeholderType != UrlPlaceholderType::NotUrl) { - return resolveUrlPlaceholder(url(), placeholderType); - } else { - const QList keyList = attributes()->keys(); - for (const QString& key : keyList) { - Qt::CaseSensitivity cs = Qt::CaseInsensitive; - QString k = key; + QRegExp* tmpRegExp = m_attributes->referenceRegExp(); + if (tmpRegExp->indexIn(placeholder) != -1) { + constexpr int wantedFieldIndex = 1; + constexpr int referencedUuidIndex = 2; + const Uuid referencedUuid(QByteArray::fromHex(tmpRegExp->cap(referencedUuidIndex).toLatin1())); + const Entry* refEntry = m_group->database()->resolveEntry(referencedUuid); + if (refEntry) { + QString result; + const QString wantedField = tmpRegExp->cap(wantedFieldIndex).toLower(); + if (wantedField == "t") result = refEntry->title(); + else if (wantedField == "u") result = refEntry->username(); + else if (wantedField == "p") result = refEntry->password(); + else if (wantedField == "a") result = refEntry->url(); + else if (wantedField == "n") result = refEntry->notes(); - if (!EntryAttributes::isDefaultAttribute(key)) { - cs = Qt::CaseSensitive; - k.prepend("{S:"); - } else { - k.prepend("{"); - } - - - k.append("}"); - if (result.compare(k,cs)==0) { - result.replace(result,attributes()->value(key)); - break; + result = refEntry->resolveMultiplePlaceholders(result); + return result; } } } - - // resolving references in format: {REF:@I:} - // using format from http://keepass.info/help/base/fieldrefs.html at the time of writing, - // but supporting lookups of standard fields and references by UUID only - - QRegExp* tmpRegExp = m_attributes->referenceRegExp(); - if (tmpRegExp->indexIn(result) != -1) { - // cap(0) contains the whole reference - // cap(1) contains which field is wanted - // cap(2) contains the uuid of the referenced entry - Entry* tmpRefEntry = m_group->database()->resolveEntry(Uuid(QByteArray::fromHex(tmpRegExp->cap(2).toLatin1()))); - if (tmpRefEntry) { - // entry found, get the relevant field - QString tmpRefField = tmpRegExp->cap(1).toLower(); - if (tmpRefField == "t") result.replace(tmpRegExp->cap(0), tmpRefEntry->title(), Qt::CaseInsensitive); - else if (tmpRefField == "u") result.replace(tmpRegExp->cap(0), tmpRefEntry->username(), Qt::CaseInsensitive); - else if (tmpRefField == "p") result.replace(tmpRegExp->cap(0), tmpRefEntry->password(), Qt::CaseInsensitive); - else if (tmpRefField == "a") result.replace(tmpRegExp->cap(0), tmpRefEntry->url(), Qt::CaseInsensitive); - else if (tmpRefField == "n") result.replace(tmpRegExp->cap(0), tmpRefEntry->notes(), Qt::CaseInsensitive); - } } + return placeholder; +} + +QString Entry::resolveUrlPlaceholder(Entry::PlaceholderType placeholderType) const +{ + const QString urlStr = url(); + if (urlStr.isEmpty()) + return QString(); + + const QUrl qurl(urlStr); + switch (placeholderType) { + case PlaceholderType::Url: + return urlStr; + case PlaceholderType::UrlWithoutScheme: + return qurl.toString(QUrl::RemoveScheme | QUrl::FullyDecoded); + case PlaceholderType::UrlScheme: + return qurl.scheme(); + case PlaceholderType::UrlHost: + return qurl.host(); + case PlaceholderType::UrlPort: + return QString::number(qurl.port()); + case PlaceholderType::UrlPath: + return qurl.path(); + case PlaceholderType::UrlQuery: + return qurl.query(); + case PlaceholderType::UrlFragment: + return qurl.fragment(); + case PlaceholderType::UrlUserInfo: + return qurl.userInfo(); + case PlaceholderType::UrlUserName: + return qurl.userName(); + case PlaceholderType::UrlPassword: + return qurl.password(); + default: + Q_ASSERT(false); + break; + } + + return urlStr; +} + +Entry::PlaceholderType Entry::placeholderType(const QString &placeholder) const +{ + if (!placeholder.startsWith(QLatin1Char('{')) || !placeholder.endsWith(QLatin1Char('}'))) { + return PlaceholderType::NotPlaceholder; + } else if (placeholder.startsWith(QLatin1Literal("{S:"))) { + return PlaceholderType::CustomAttribute; + } else if (placeholder.startsWith(QLatin1Literal("{REF:"))) { + return PlaceholderType::Reference; + } + + static const QMap placeholders { + { QStringLiteral("{TITLE}"), PlaceholderType::Title }, + { QStringLiteral("{USERNAME}"), PlaceholderType::UserName }, + { QStringLiteral("{PASSWORD}"), PlaceholderType::Password }, + { QStringLiteral("{NOTES}"), PlaceholderType::Notes }, + { QStringLiteral("{TOTP}"), PlaceholderType::Totp }, + { QStringLiteral("{URL}"), PlaceholderType::Url }, + { QStringLiteral("{URL:RMVSCM}"), PlaceholderType::UrlWithoutScheme }, + { QStringLiteral("{URL:WITHOUTSCHEME}"), PlaceholderType::UrlWithoutScheme }, + { QStringLiteral("{URL:SCM}"), PlaceholderType::UrlScheme }, + { QStringLiteral("{URL:SCHEME}"), PlaceholderType::UrlScheme }, + { QStringLiteral("{URL:HOST}"), PlaceholderType::UrlHost }, + { QStringLiteral("{URL:PORT}"), PlaceholderType::UrlPort }, + { QStringLiteral("{URL:PATH}"), PlaceholderType::UrlPath }, + { QStringLiteral("{URL:QUERY}"), PlaceholderType::UrlQuery }, + { QStringLiteral("{URL:FRAGMENT}"), PlaceholderType::UrlFragment }, + { QStringLiteral("{URL:USERINFO}"), PlaceholderType::UrlUserInfo }, + { QStringLiteral("{URL:USERNAME}"), PlaceholderType::UrlUserName }, + { QStringLiteral("{URL:PASSWORD}"), PlaceholderType::UrlPassword } + }; + + PlaceholderType result = placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown); return result; } @@ -834,62 +920,3 @@ QString Entry::resolveUrl(const QString& url) const // No valid http URL's found return QString(""); } - -QString Entry::resolveUrlPlaceholder(const QString &strUrl, Entry::UrlPlaceholderType placeholderType) const -{ - QUrl qurl(strUrl); - if (!qurl.isValid()) - return QString(); - - switch (placeholderType) { - case UrlPlaceholderType::FullUrl: - return strUrl; - case UrlPlaceholderType::WithoutScheme: - return qurl.toString(QUrl::RemoveScheme | QUrl::FullyDecoded); - case UrlPlaceholderType::Scheme: - return qurl.scheme(); - case UrlPlaceholderType::Host: - return qurl.host(); - case UrlPlaceholderType::Port: - return QString::number(qurl.port()); - case UrlPlaceholderType::Path: - return qurl.path(); - case UrlPlaceholderType::Query: - return qurl.query(); - case UrlPlaceholderType::Fragment: - return qurl.fragment(); - case UrlPlaceholderType::UserInfo: - return qurl.userInfo(); - case UrlPlaceholderType::UserName: - return qurl.userName(); - case UrlPlaceholderType::Password: - return qurl.password(); - default: - Q_ASSERT(false); - break; - } - - return QString(); -} - -Entry::UrlPlaceholderType Entry::urlPlaceholderType(const QString &placeholder) const -{ - static const QMap urlPlaceholders { - { QStringLiteral("{URL}"), UrlPlaceholderType::FullUrl }, - { QStringLiteral("{URL:RMVSCM}"), UrlPlaceholderType::WithoutScheme }, - { QStringLiteral("{URL:WITHOUTSCHEME}"), UrlPlaceholderType::WithoutScheme }, - { QStringLiteral("{URL:SCM}"), UrlPlaceholderType::Scheme }, - { QStringLiteral("{URL:SCHEME}"), UrlPlaceholderType::Scheme }, - { QStringLiteral("{URL:HOST}"), UrlPlaceholderType::Host }, - { QStringLiteral("{URL:PORT}"), UrlPlaceholderType::Port }, - { QStringLiteral("{URL:PATH}"), UrlPlaceholderType::Path }, - { QStringLiteral("{URL:QUERY}"), UrlPlaceholderType::Query }, - { QStringLiteral("{URL:FRAGMENT}"), UrlPlaceholderType::Fragment }, - { QStringLiteral("{URL:USERINFO}"), UrlPlaceholderType::UserInfo }, - { QStringLiteral("{URL:USERNAME}"), UrlPlaceholderType::UserName }, - { QStringLiteral("{URL:PASSWORD}"), UrlPlaceholderType::Password } - }; - - UrlPlaceholderType result = urlPlaceholders.value(placeholder.toUpper(), UrlPlaceholderType::NotUrl); - return result; -} diff --git a/src/core/Entry.h b/src/core/Entry.h index 51208c9e..7b7a2508 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -134,19 +134,27 @@ public: }; Q_DECLARE_FLAGS(CloneFlags, CloneFlag) - enum class UrlPlaceholderType { - NotUrl, - FullUrl, - WithoutScheme, - Scheme, - Host, - Port, - Path, - Query, - Fragment, - UserInfo, + enum class PlaceholderType { + NotPlaceholder, + Unknown, + Title, UserName, Password, + Notes, + Totp, + Url, + UrlWithoutScheme, + UrlScheme, + UrlHost, + UrlPort, + UrlPath, + UrlQuery, + UrlFragment, + UrlUserInfo, + UrlUserName, + UrlPassword, + Reference, + CustomAttribute }; /** @@ -160,8 +168,8 @@ public: QString maskPasswordPlaceholders(const QString& str) const; QString resolveMultiplePlaceholders(const QString& str) const; QString resolvePlaceholder(const QString& str) const; - QString resolveUrlPlaceholder(const QString& url, UrlPlaceholderType placeholderType) const; - UrlPlaceholderType urlPlaceholderType(const QString& placeholder) const; + QString resolveUrlPlaceholder(PlaceholderType placeholderType) const; + PlaceholderType placeholderType(const QString& placeholder) const; QString resolveUrl(const QString& url) const; /** From f0fcc199156b842e7fc972d4896d451dc1a99fc7 Mon Sep 17 00:00:00 2001 From: frostasm Date: Mon, 16 Oct 2017 10:35:40 +0300 Subject: [PATCH 018/118] Implement recursive resolving for placeholders --- src/core/Entry.cpp | 200 +++++++++++++++++++++++++------------------- src/core/Entry.h | 6 +- tests/TestEntry.cpp | 106 +++++++++++++++++++---- tests/TestEntry.h | 1 + 4 files changed, 209 insertions(+), 104 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 1a1dff02..d5afec04 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -26,6 +26,8 @@ #include "totp/totp.h" const int Entry::DefaultIconNumber = 0; +const int Entry::ResolveMaximumDepth = 10; + Entry::Entry() : m_attributes(new EntryAttributes(this)) @@ -670,6 +672,108 @@ void Entry::updateModifiedSinceBegin() m_modifiedSinceBegin = true; } +QString Entry::resolveMultiplePlaceholdersRecursive(const QString &str, int maxDepth) const +{ + if (maxDepth <= 0) { + qWarning("Maximum depth of replacement has been reached. Entry uuid: %s", qPrintable(uuid().toHex())); + return str; + } + + QString result = str; + QRegExp placeholderRegEx("(\\{[^\\}]+\\})", Qt::CaseInsensitive, QRegExp::RegExp2); + placeholderRegEx.setMinimal(true); + int pos = 0; + while ((pos = placeholderRegEx.indexIn(str, pos)) != -1) { + const QString found = placeholderRegEx.cap(1); + result.replace(found, resolvePlaceholderRecursive(found, maxDepth - 1)); + pos += placeholderRegEx.matchedLength(); + } + + if (result != str) { + result = resolveMultiplePlaceholdersRecursive(result, maxDepth - 1); + } + + return result; +} + +QString Entry::resolvePlaceholderRecursive(const QString &placeholder, int maxDepth) const +{ + const PlaceholderType typeOfPlaceholder = placeholderType(placeholder); + switch (typeOfPlaceholder) { + case PlaceholderType::NotPlaceholder: + return placeholder; + case PlaceholderType::Unknown: + qWarning("Can't resolve placeholder %s for entry with uuid %s", qPrintable(placeholder), + qPrintable(uuid().toHex())); + return placeholder; + case PlaceholderType::Title: + return title(); + case PlaceholderType::UserName: + return username(); + case PlaceholderType::Password: + return password(); + case PlaceholderType::Notes: + return notes(); + case PlaceholderType::Totp: + return totp(); + case PlaceholderType::Url: + return url(); + case PlaceholderType::UrlWithoutScheme: + case PlaceholderType::UrlScheme: + case PlaceholderType::UrlHost: + case PlaceholderType::UrlPort: + case PlaceholderType::UrlPath: + case PlaceholderType::UrlQuery: + case PlaceholderType::UrlFragment: + case PlaceholderType::UrlUserInfo: + case PlaceholderType::UrlUserName: + case PlaceholderType::UrlPassword: { + const QString strUrl = resolveMultiplePlaceholdersRecursive(url(), maxDepth - 1); + return resolveUrlPlaceholder(strUrl, typeOfPlaceholder); + } + case PlaceholderType::CustomAttribute: { + const QString key = placeholder.mid(3, placeholder.length() - 4); // {S:attr} => mid(3, len - 4) + return attributes()->hasKey(key) ? attributes()->value(key) : QString(); + } + case PlaceholderType::Reference: { + // resolving references in format: {REF:@I:} + // using format from http://keepass.info/help/base/fieldrefs.html at the time of writing, + // but supporting lookups of standard fields and references by UUID only + + QString result; + QRegExp* referenceRegExp = m_attributes->referenceRegExp(); + if (referenceRegExp->indexIn(placeholder) != -1) { + constexpr int wantedFieldIndex = 1; + constexpr int referencedUuidIndex = 2; + const Uuid referencedUuid(QByteArray::fromHex(referenceRegExp->cap(referencedUuidIndex).toLatin1())); + const Entry* refEntry = m_group->database()->resolveEntry(referencedUuid); + if (refEntry) { + const QString wantedField = referenceRegExp->cap(wantedFieldIndex).toLower(); + if (wantedField == "t") { + result = refEntry->title(); + } else if (wantedField == "u") { + result = refEntry->username(); + } else if (wantedField == "p") { + result = refEntry->password(); + } else if (wantedField == "a") { + result = refEntry->url(); + } else if (wantedField == "n") { + result = refEntry->notes(); + } + + // Referencing fields of other entries only works with standard fields, not with custom user strings. + // If you want to reference a custom user string, you need to place a redirection in a standard field + // of the entry with the custom string, using {S:}, and reference the standard field. + result = refEntry->resolveMultiplePlaceholdersRecursive(result, maxDepth - 1); + } + } + return result; + } + } + + return placeholder; +} + Group* Entry::group() { return m_group; @@ -736,97 +840,21 @@ QString Entry::maskPasswordPlaceholders(const QString &str) const QString Entry::resolveMultiplePlaceholders(const QString& str) const { - QString result = str; - QRegExp tmplRegEx("(\\{.*\\})", Qt::CaseInsensitive, QRegExp::RegExp2); - tmplRegEx.setMinimal(true); - QStringList tmplList; - int pos = 0; - - while ((pos = tmplRegEx.indexIn(str, pos)) != -1) { - QString found = tmplRegEx.cap(1); - result.replace(found,resolvePlaceholder(found)); - pos += tmplRegEx.matchedLength(); - } - - return result; + return resolveMultiplePlaceholdersRecursive(str, ResolveMaximumDepth); } QString Entry::resolvePlaceholder(const QString& placeholder) const { - const PlaceholderType placeholderType = this->placeholderType(placeholder); - switch (placeholderType) { - case PlaceholderType::NotPlaceholder: - return placeholder; - case PlaceholderType::Unknown: - qWarning("Can't resolve placeholder '%s' for entry with uuid %s", qPrintable(placeholder), - qPrintable(uuid().toHex())); - return placeholder; - case PlaceholderType::Title: - return title(); - case PlaceholderType::UserName: - return username(); - case PlaceholderType::Password: - return password(); - case PlaceholderType::Notes: - return notes(); - case PlaceholderType::Totp: - return totp(); - case PlaceholderType::Url: - case PlaceholderType::UrlWithoutScheme: - case PlaceholderType::UrlScheme: - case PlaceholderType::UrlHost: - case PlaceholderType::UrlPort: - case PlaceholderType::UrlPath: - case PlaceholderType::UrlQuery: - case PlaceholderType::UrlFragment: - case PlaceholderType::UrlUserInfo: - case PlaceholderType::UrlUserName: - case PlaceholderType::UrlPassword: - return resolveUrlPlaceholder(placeholderType); - case PlaceholderType::CustomAttribute: { - const QString key = placeholder.mid(3, placeholder.length() - 4); // {S:attribute} => mid(3, len - 4) - return attributes()->hasKey(key) ? attributes()->value(key) : placeholder; - } - case PlaceholderType::Reference: { - // resolving references in format: {REF:@I:} - // using format from http://keepass.info/help/base/fieldrefs.html at the time of writing, - // but supporting lookups of standard fields and references by UUID only - - QRegExp* tmpRegExp = m_attributes->referenceRegExp(); - if (tmpRegExp->indexIn(placeholder) != -1) { - constexpr int wantedFieldIndex = 1; - constexpr int referencedUuidIndex = 2; - const Uuid referencedUuid(QByteArray::fromHex(tmpRegExp->cap(referencedUuidIndex).toLatin1())); - const Entry* refEntry = m_group->database()->resolveEntry(referencedUuid); - if (refEntry) { - QString result; - const QString wantedField = tmpRegExp->cap(wantedFieldIndex).toLower(); - if (wantedField == "t") result = refEntry->title(); - else if (wantedField == "u") result = refEntry->username(); - else if (wantedField == "p") result = refEntry->password(); - else if (wantedField == "a") result = refEntry->url(); - else if (wantedField == "n") result = refEntry->notes(); - - result = refEntry->resolveMultiplePlaceholders(result); - return result; - } - } - } - } - - return placeholder; + return resolvePlaceholderRecursive(placeholder, ResolveMaximumDepth); } -QString Entry::resolveUrlPlaceholder(Entry::PlaceholderType placeholderType) const +QString Entry::resolveUrlPlaceholder(const QString &str, Entry::PlaceholderType placeholderType) const { - const QString urlStr = url(); - if (urlStr.isEmpty()) + if (str.isEmpty()) return QString(); - const QUrl qurl(urlStr); + const QUrl qurl(str); switch (placeholderType) { - case PlaceholderType::Url: - return urlStr; case PlaceholderType::UrlWithoutScheme: return qurl.toString(QUrl::RemoveScheme | QUrl::FullyDecoded); case PlaceholderType::UrlScheme: @@ -847,12 +875,13 @@ QString Entry::resolveUrlPlaceholder(Entry::PlaceholderType placeholderType) con return qurl.userName(); case PlaceholderType::UrlPassword: return qurl.password(); - default: - Q_ASSERT(false); + default: { + Q_ASSERT_X(false, "Entry::resolveUrlPlaceholder", "Bad url placeholder type"); break; } + } - return urlStr; + return QString(); } Entry::PlaceholderType Entry::placeholderType(const QString &placeholder) const @@ -886,8 +915,7 @@ Entry::PlaceholderType Entry::placeholderType(const QString &placeholder) const { QStringLiteral("{URL:PASSWORD}"), PlaceholderType::UrlPassword } }; - PlaceholderType result = placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown); - return result; + return placeholders.value(placeholder.toUpper(), PlaceholderType::Unknown); } QString Entry::resolveUrl(const QString& url) const diff --git a/src/core/Entry.h b/src/core/Entry.h index 7b7a2508..212c8668 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -96,6 +96,7 @@ public: const EntryAttachments* attachments() const; static const int DefaultIconNumber; + static const int ResolveMaximumDepth; void setUuid(const Uuid& uuid); void setIcon(int iconNumber); @@ -168,7 +169,7 @@ public: QString maskPasswordPlaceholders(const QString& str) const; QString resolveMultiplePlaceholders(const QString& str) const; QString resolvePlaceholder(const QString& str) const; - QString resolveUrlPlaceholder(PlaceholderType placeholderType) const; + QString resolveUrlPlaceholder(const QString &str, PlaceholderType placeholderType) const; PlaceholderType placeholderType(const QString& placeholder) const; QString resolveUrl(const QString& url) const; @@ -199,6 +200,9 @@ private slots: void updateModifiedSinceBegin(); private: + QString resolveMultiplePlaceholdersRecursive(const QString& str, int maxDepth) const; + QString resolvePlaceholderRecursive(const QString& placeholder, int maxDepth) const; + const Database* database() const; template bool set(T& property, const T& value); diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 056dbc93..1e863dbe 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -20,7 +20,9 @@ #include +#include "core/Database.h" #include "core/Entry.h" +#include "core/Group.h" #include "crypto/Crypto.h" QTEST_GUILESS_MAIN(TestEntry) @@ -161,8 +163,8 @@ void TestEntry::testResolveUrl() void TestEntry::testResolveUrlPlaceholders() { - Entry* entry = new Entry(); - entry->setUrl("https://user:pw@keepassxc.org:80/path/example.php?q=e&s=t+2#fragment"); + Entry entry; + entry.setUrl("https://user:pw@keepassxc.org:80/path/example.php?q=e&s=t+2#fragment"); QString rmvscm("//user:pw@keepassxc.org:80/path/example.php?q=e&s=t+2#fragment"); // Entry URL without scheme name. QString scm("https"); // Scheme name of the entry URL. @@ -173,20 +175,90 @@ void TestEntry::testResolveUrlPlaceholders() QString userinfo("user:pw"); // User information of the entry URL. QString username("user"); // User name of the entry URL. QString password("pw"); // Password of the entry URL. - QString fragment("fragment"); // Password of the entry URL. + QString fragment("fragment"); // Fragment of the entry URL. - QCOMPARE(entry->resolvePlaceholder("{URL:RMVSCM}"), rmvscm); - QCOMPARE(entry->resolvePlaceholder("{URL:WITHOUTSCHEME}"), rmvscm); - QCOMPARE(entry->resolvePlaceholder("{URL:SCM}"), scm); - QCOMPARE(entry->resolvePlaceholder("{URL:SCHEME}"), scm); - QCOMPARE(entry->resolvePlaceholder("{URL:HOST}"), host); - QCOMPARE(entry->resolvePlaceholder("{URL:PORT}"), port); - QCOMPARE(entry->resolvePlaceholder("{URL:PATH}"), path); - QCOMPARE(entry->resolvePlaceholder("{URL:QUERY}"), query); - QCOMPARE(entry->resolvePlaceholder("{URL:USERINFO}"), userinfo); - QCOMPARE(entry->resolvePlaceholder("{URL:USERNAME}"), username); - QCOMPARE(entry->resolvePlaceholder("{URL:PASSWORD}"), password); - QCOMPARE(entry->resolvePlaceholder("{URL:FRAGMENT}"), fragment); - - delete entry; + QCOMPARE(entry.resolvePlaceholder("{URL:RMVSCM}"), rmvscm); + QCOMPARE(entry.resolvePlaceholder("{URL:WITHOUTSCHEME}"), rmvscm); + QCOMPARE(entry.resolvePlaceholder("{URL:SCM}"), scm); + QCOMPARE(entry.resolvePlaceholder("{URL:SCHEME}"), scm); + QCOMPARE(entry.resolvePlaceholder("{URL:HOST}"), host); + QCOMPARE(entry.resolvePlaceholder("{URL:PORT}"), port); + QCOMPARE(entry.resolvePlaceholder("{URL:PATH}"), path); + QCOMPARE(entry.resolvePlaceholder("{URL:QUERY}"), query); + QCOMPARE(entry.resolvePlaceholder("{URL:USERINFO}"), userinfo); + QCOMPARE(entry.resolvePlaceholder("{URL:USERNAME}"), username); + QCOMPARE(entry.resolvePlaceholder("{URL:PASSWORD}"), password); + QCOMPARE(entry.resolvePlaceholder("{URL:FRAGMENT}"), fragment); +} + +void TestEntry::testResolveRecursivePlaceholders() +{ + Database db; + Group* root = db.rootGroup(); + + Entry* entry1 = new Entry(); + entry1->setGroup(root); + entry1->setUuid(Uuid::random()); + entry1->setTitle("{USERNAME}"); + entry1->setUsername("{PASSWORD}"); + entry1->setPassword("{URL}"); + entry1->setUrl("{S:CustomTitle}"); + entry1->attributes()->set("CustomTitle", "RecursiveValue"); + QCOMPARE(entry1->resolveMultiplePlaceholders(entry1->title()), QString("RecursiveValue")); + + Entry* entry2 = new Entry(); + entry2->setGroup(root); + entry2->setUuid(Uuid::random()); + entry2->setTitle("Entry2Title"); + entry2->setUsername("{S:CustomUserNameAttribute}"); + entry2->setPassword(QString("{REF:P@I:%1}").arg(entry1->uuid().toHex())); + entry2->setUrl("http://{S:IpAddress}:{S:Port}/{S:Uri}"); + entry2->attributes()->set("CustomUserNameAttribute", "CustomUserNameValue"); + entry2->attributes()->set("IpAddress", "127.0.0.1"); + entry2->attributes()->set("Port", "1234"); + entry2->attributes()->set("Uri", "uri/path"); + + Entry* entry3 = new Entry(); + entry3->setGroup(root); + entry3->setUuid(Uuid::random()); + entry3->setTitle(QString("{REF:T@I:%1}").arg(entry2->uuid().toHex())); + entry3->setUsername(QString("{REF:U@I:%1}").arg(entry2->uuid().toHex())); + entry3->setPassword(QString("{REF:P@I:%1}").arg(entry2->uuid().toHex())); + entry3->setUrl(QString("{REF:A@I:%1}").arg(entry2->uuid().toHex())); + + QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->title()), QString("Entry2Title")); + QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->username()), QString("CustomUserNameValue")); + QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->password()), QString("RecursiveValue")); + QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->url()), QString("http://127.0.0.1:1234/uri/path")); + + Entry* entry4 = new Entry(); + entry4->setGroup(root); + entry4->setUuid(Uuid::random()); + entry4->setTitle(QString("{REF:T@I:%1}").arg(entry3->uuid().toHex())); + entry4->setUsername(QString("{REF:U@I:%1}").arg(entry3->uuid().toHex())); + entry4->setPassword(QString("{REF:P@I:%1}").arg(entry3->uuid().toHex())); + entry4->setUrl(QString("{REF:A@I:%1}").arg(entry3->uuid().toHex())); + + QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->title()), QString("Entry2Title")); + QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->username()), QString("CustomUserNameValue")); + QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->password()), QString("RecursiveValue")); + QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->url()), QString("http://127.0.0.1:1234/uri/path")); + + Entry* entry5 = new Entry(); + entry5->setGroup(root); + entry5->setUuid(Uuid::random()); + entry5->attributes()->set("Scheme", "http"); + entry5->attributes()->set("Host", "host.org"); + entry5->attributes()->set("Port", "2017"); + entry5->attributes()->set("Path", "/some/path"); + entry5->attributes()->set("UserName", "username"); + entry5->attributes()->set("Password", "password"); + entry5->attributes()->set("Query", "q=e&t=s"); + entry5->attributes()->set("Fragment", "fragment"); + entry5->setUrl("{S:Scheme}://{S:UserName}:{S:Password}@{S:Host}:{S:Port}{S:Path}?{S:Query}#{S:Fragment}"); + entry5->setTitle("title+{URL:Path}+{URL:Fragment}+title"); + + const QString url("http://username:password@host.org:2017/some/path?q=e&t=s#fragment"); + QCOMPARE(entry5->resolveMultiplePlaceholders(entry5->url()), url); + QCOMPARE(entry5->resolveMultiplePlaceholders(entry5->title()), QString("title+/some/path+fragment+title")); } diff --git a/tests/TestEntry.h b/tests/TestEntry.h index febdf085..50fec57a 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -33,6 +33,7 @@ private slots: void testClone(); void testResolveUrl(); void testResolveUrlPlaceholders(); + void testResolveRecursivePlaceholders(); }; #endif // KEEPASSX_TESTENTRY_H From 37aa4f0257ee1fb39300f262437b1cd858fc464d Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Wed, 18 Oct 2017 22:08:30 -0400 Subject: [PATCH 019/118] Unlock previously opened databases with --pw-stdin --- src/gui/DatabaseTabWidget.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index df0e1a1d..4c9445cc 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -129,7 +129,12 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw, while (i.hasNext()) { i.next(); if (i.value().canonicalFilePath == canonicalFilePath) { - setCurrentIndex(databaseIndex(i.key())); + if (!i.value().dbWidget->dbHasKey() && !(pw.isNull() && keyFile.isEmpty())) { + // If the database is locked and a pw or keyfile is provided, unlock it + i.value().dbWidget->switchToOpenDatabase(i.value().filePath, pw, keyFile); + } else { + setCurrentIndex(databaseIndex(i.key())); + } return; } } @@ -204,7 +209,7 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw, updateLastDatabases(dbStruct.filePath); - if (!pw.isNull() || !keyFile.isEmpty()) { + if (!(pw.isNull() && keyFile.isEmpty())) { dbStruct.dbWidget->switchToOpenDatabase(dbStruct.filePath, pw, keyFile); } else { From feb6baad05a3de71387bdf11f7e6282cd31aef0c Mon Sep 17 00:00:00 2001 From: thez3ro Date: Fri, 20 Oct 2017 21:13:59 +0200 Subject: [PATCH 020/118] add KeePassHTTP-Connector --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf214d3c..5588e322 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ KeePass Cross-platform Community Edition - Using website favicons as entry icons - Merging of databases - Automatic reload when the database changed on disk -- KeePassHTTP support for use with [PassIFox](https://addons.mozilla.org/en-us/firefox/addon/passifox/) in Mozilla Firefox and [chromeIPass](https://chrome.google.com/webstore/detail/chromeipass/ompiailgknfdndiefoaoiligalphfdae) in Google Chrome or Chromium, and [passafari](https://github.com/mmichaa/passafari.safariextension/) in Safari. +- KeePassHTTP support for use with KeePassHTTP-Connector for [Mozilla Firefox](https://addons.mozilla.org/en-US/firefox/addon/keepasshttp-connector/) and [Google Chrome or Chromium](https://chrome.google.com/webstore/detail/keepasshttp-connector/dafgdjggglmmknipkhngniifhplpcldb), and [passafari](https://github.com/mmichaa/passafari.safariextension/) in Safari. - Many bug fixes For a full list of features and changes, read the [CHANGELOG](CHANGELOG) document. From 85f652290b48a2178fef65678889313d838c0f22 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Thu, 5 Oct 2017 18:04:41 -0400 Subject: [PATCH 021/118] Add signtool function (Windows Only) to release-tool script --- release-tool | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/release-tool b/release-tool index a1d23b40..10c6a14c 100755 --- a/release-tool +++ b/release-tool @@ -119,9 +119,11 @@ EOF Sign previously compiled release packages Options: - -f, --files Files to sign (required) - -g, --gpg-key GPG key used to sign the files (default: '${GPG_KEY}') - -h, --help Show this help + -f, --files Files to sign (required) + -g, --gpg-key GPG key used to sign the files (default: '${GPG_KEY}') + --signtool Specify the signtool executable (default: 'signtool') + --signtool-key Provide a key to be used with signtool (for Windows EXE) + -h, --help Show this help EOF fi } @@ -546,10 +548,10 @@ build() { checkWorkingTreeClean OUTPUT_DIR="$(realpath "$OUTPUT_DIR")" - + logInfo "Checking out release tag '${TAG_NAME}'..." git checkout "$TAG_NAME" - + logInfo "Creating output directory..." mkdir -p "$OUTPUT_DIR" @@ -663,6 +665,8 @@ build() { # ----------------------------------------------------------------------- sign() { SIGN_FILES=() + SIGNTOOL="signtool" + SIGNTOOL_KEY="" while [ $# -ge 1 ]; do local arg="$1" @@ -676,6 +680,14 @@ sign() { -g|--gpg-key) GPG_KEY="$2" shift ;; + + --signtool) + SIGNTOOL="$2" + shift ;; + + --signtool-key) + SIGNTOOL_KEY="$2" + shift ;; -h|--help) printUsage "sign" @@ -694,13 +706,30 @@ sign() { printUsage "sign" exit 1 fi + + if [[ -n "$SIGNTOOL_KEY" && ! -f "$SIGNTOOL_KEY" ]]; then + exitError "Signtool Key was not found!" + elif [[ -f "$SIGNTOOL_KEY" && ! -x $(command -v "${SIGNTOOL}") ]]; then + exitError "signtool program not found on PATH!" + fi for f in "${SIGN_FILES[@]}"; do if [ ! -f "$f" ]; then exitError "File '${f}' does not exist!" fi + + if [[ -n "$SIGNTOOL_KEY" && ${f: -4} == '.exe' ]]; then + logInfo "Signing file '${f}' using signtool...\n" + read -s -p "Signtool Key Password: " password + echo + "${SIGNTOOL}" sign -f "${SIGNTOOL_KEY}" -p ${password} -v -t http://timestamp.comodoca.com/authenticode ${f} + + if [ 0 -ne $? ]; then + exitError "Signing failed!" + fi + fi - logInfo "Signing file '${f}'..." + logInfo "Signing file '${f}' using release key..." gpg --output "${f}.sig" --armor --local-user "$GPG_KEY" --detach-sig "$f" if [ 0 -ne $? ]; then From 19eb6a8a60afed2da5733a2eef47de80009f824f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sat, 14 Oct 2017 22:54:20 -0600 Subject: [PATCH 022/118] Add new Base32 implementation --- COPYING | 9 -- LICENSE.APACHE-2.0 | 201 ------------------------------ src/CMakeLists.txt | 5 +- src/core/Base32.cpp | 285 +++++++++++++++++++++++++++++++++++++++++++ src/core/Base32.h | 42 +++++++ src/core/Optional.h | 86 +++++++++++++ src/totp/base32.cpp | 68 ----------- src/totp/base32.h | 34 ------ src/totp/totp.cpp | 57 ++++++--- src/totp/totp.h | 11 +- tests/CMakeLists.txt | 3 + tests/TestBase32.cpp | 278 +++++++++++++++++++++++++++++++++++++++++ tests/TestBase32.h | 37 ++++++ tests/TestTotp.cpp | 31 +---- tests/TestTotp.h | 1 - 15 files changed, 789 insertions(+), 359 deletions(-) delete mode 100644 LICENSE.APACHE-2.0 create mode 100644 src/core/Base32.cpp create mode 100644 src/core/Base32.h create mode 100644 src/core/Optional.h delete mode 100644 src/totp/base32.cpp delete mode 100644 src/totp/base32.h create mode 100644 tests/TestBase32.cpp create mode 100644 tests/TestBase32.h diff --git a/COPYING b/COPYING index 481aaf72..403e4564 100644 --- a/COPYING +++ b/COPYING @@ -214,10 +214,6 @@ Files: share/icons/database/C65_W.png Copyright: none License: public-domain -Files: src/crypto/salsa20/* -Copyright: none -License: public-domain - Files: src/streams/qtiocompressor.* src/streams/QtIOCompressor tests/modeltest.* @@ -241,8 +237,3 @@ Files: src/gui/KMessageWidget.h Copyright: 2011 Aurélien Gâteau 2014 Dominik Haumann License: LGPL-2.1 - -Files: src/totp/base32.cpp - src/totp/base32.h -Copyright: 2010 Google Inc. -License: Apache 2.0 \ No newline at end of file diff --git a/LICENSE.APACHE-2.0 b/LICENSE.APACHE-2.0 deleted file mode 100644 index 9c8f3ea0..00000000 --- a/LICENSE.APACHE-2.0 +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79168557..28170b16 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,6 +59,9 @@ set(keepassx_SOURCES core/Tools.cpp core/Translator.cpp core/Uuid.cpp + core/Base32.h + core/Base32.cpp + core/Optional.h cli/PasswordInput.cpp cli/PasswordInput.h crypto/Crypto.cpp @@ -138,8 +141,6 @@ set(keepassx_SOURCES streams/qtiocompressor.cpp streams/StoreDataStream.cpp streams/SymmetricCipherStream.cpp - totp/base32.h - totp/base32.cpp totp/totp.h totp/totp.cpp ) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp new file mode 100644 index 00000000..8b2faf62 --- /dev/null +++ b/src/core/Base32.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Conforms to RFC 4648. For details, see: https://tools.ietf.org/html/rfc4648 + * Use the functions Base32::addPadding/1, Base32::removePadding/1 or + * Base32::sanitizeInput/1 to fix input or output for a particular + * applications (e.g. to use with Google Authenticator). + */ + +#include "Base32.h" + +constexpr quint64 MASK_40BIT = quint64(0xF8) << 32; +constexpr quint64 MASK_35BIT = quint64(0x7C0000000); +constexpr quint64 MASK_25BIT = quint64(0x1F00000); +constexpr quint64 MASK_20BIT = quint64(0xF8000); +constexpr quint64 MASK_10BIT = quint64(0x3E0); + +constexpr char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; +constexpr quint8 ALPH_POS_2 = 26; + +constexpr quint8 ASCII_2 = static_cast('2'); +constexpr quint8 ASCII_7 = static_cast('7'); +constexpr quint8 ASCII_A = static_cast('A'); +constexpr quint8 ASCII_Z = static_cast('Z'); +constexpr quint8 ASCII_a = static_cast('a'); +constexpr quint8 ASCII_z = static_cast('z'); +constexpr quint8 ASCII_EQ = static_cast('='); + +Optional Base32::decode(const QByteArray& encodedData) +{ + if (encodedData.size() <= 0) { + return Optional(""); + } + + if (encodedData.size() % 8 != 0) { + return Optional(); + } + + int nPads = 0; + for (int i = -1; i > -7; --i) { + if ('=' == encodedData[encodedData.size() + i]) + ++nPads; + } + + int specialOffset; + int nSpecialBytes; + + switch (nPads) { // in {0, 1, 3, 4, 6} + case 1: + nSpecialBytes = 4; + specialOffset = 3; + break; + case 3: + nSpecialBytes = 3; + specialOffset = 1; + break; + case 4: + nSpecialBytes = 2; + specialOffset = 4; + break; + case 6: + nSpecialBytes = 1; + specialOffset = 2; + break; + default: + nSpecialBytes = 0; + specialOffset = 0; + } + + Q_ASSERT(encodedData.size() > 0); + const int nQuanta = encodedData.size() / 8; + const int nBytes = (nQuanta - 1) * 5 + nSpecialBytes; + + QByteArray data(nBytes, Qt::Uninitialized); + + int i = 0; + int o = 0; + + while (i < encodedData.size()) { + quint64 quantum = 0; + int nQuantumBytes = 5; + + for (int n = 0; n < 8; n++) { + quint8 ch = static_cast(encodedData[i++]); + if ((ASCII_A <= ch && ch <= ASCII_Z) || (ASCII_a <= ch && ch <= ASCII_z)) { + ch -= ASCII_A; + if (ch >= ALPH_POS_2) + ch -= ASCII_a - ASCII_A; + } else { + if (ASCII_2 <= ch && ch <= ASCII_7) { + ch -= ASCII_2; + ch += ALPH_POS_2; + } else { + if (ASCII_EQ == ch) { + if (i == encodedData.size()) { + // finished with special quantum + quantum >>= specialOffset; + nQuantumBytes = nSpecialBytes; + } + continue; + } else { + // illegal character + return Optional(); + } + } + } + + quantum <<= 5; + quantum |= ch; + } + + const int offset = (nQuantumBytes - 1) * 8; + quint64 mask = quint64(0xFF) << offset; + for (int n = offset; n >= 0; n -= 8) { + char c = static_cast((quantum & mask) >> n); + data[o++] = c; + mask >>= 8; + } + } + + return Optional(data); +} + +QByteArray Base32::encode(const QByteArray& data) +{ + if (data.size() < 1) { + return QByteArray(); + } + + const int nBits = data.size() * 8; + const int rBits = nBits % 40; // in {0, 8, 16, 24, 32} + const int nQuanta = nBits / 40 + (rBits > 0 ? 1 : 0); + QByteArray encodedData(nQuanta * 8, Qt::Uninitialized); + + int i = 0; + int o = 0; + int n; + quint64 mask; + quint64 quantum; + + // 40-bits of input per input group + while (i + 5 <= data.size()) { + quantum = 0; + for (n = 32; n >= 0; n -= 8) { + quantum |= (static_cast(data[i++]) << n); + } + + mask = MASK_40BIT; + int index; + for (n = 35; n >= 0; n -= 5) { + index = (quantum & mask) >> n; + encodedData[o++] = alphabet[index]; + mask >>= 5; + } + } + + // < 40-bits of input at final input group + if (i < data.size()) { + Q_ASSERT(rBits > 0); + quantum = 0; + for (n = rBits - 8; n >= 0; n -= 8) + quantum |= static_cast(data[i++]) << n; + + switch (rBits) { + case 8: // expand to 10 bits + quantum <<= 2; + mask = MASK_10BIT; + n = 5; + break; + case 16: // expand to 20 bits + quantum <<= 4; + mask = MASK_20BIT; + n = 15; + break; + case 24: // expand to 25 bits + quantum <<= 1; + mask = MASK_25BIT; + n = 20; + break; + default: // expand to 35 bits + Q_ASSERT(rBits == 32); + quantum <<= 3; + mask = MASK_35BIT; + n = 30; + } + + while (n >= 0) { + int index = (quantum & mask) >> n; + encodedData[o++] = alphabet[index]; + mask >>= 5; + n -= 5; + } + + // add pad characters + while (o < encodedData.size()) + encodedData[o++] = '='; + } + + Q_ASSERT(encodedData.size() == o); + return encodedData; +} + +QByteArray Base32::addPadding(const QByteArray& encodedData) +{ + if (encodedData.size() <= 0 || encodedData.size() % 8 == 0) { + return encodedData; + } + + const int rBytes = encodedData.size() % 8; + // rBytes must be a member of {2, 4, 5, 7} + if (1 == rBytes || 3 == rBytes || 6 == rBytes) { + return encodedData; + } + + QByteArray newEncodedData(encodedData); + for (int nPads = 8 - rBytes; nPads > 0; --nPads) { + newEncodedData.append('='); + } + + return newEncodedData; +} + +QByteArray Base32::removePadding(const QByteArray& encodedData) +{ + if (encodedData.size() <= 0 || encodedData.size() % 8 != 0) { + return encodedData; // return same bad input + } + + int nPads = 0; + for (int i = -1; i > -7; --i) { + if ('=' == encodedData[encodedData.size() + i]) { + ++nPads; + } + } + + QByteArray newEncodedData(encodedData); + newEncodedData.remove(encodedData.size() - nPads, nPads); + newEncodedData.resize(encodedData.size() - nPads); + + return newEncodedData; +} + +QByteArray Base32::sanitizeInput(const QByteArray& encodedData) +{ + if (encodedData.size() <= 0) { + return encodedData; + } + + QByteArray newEncodedData(encodedData.size(), Qt::Uninitialized); + int i = 0; + for (auto ch : encodedData) { + switch (ch) { + case '0': + newEncodedData[i++] = 'O'; + break; + case '1': + newEncodedData[i++] = 'L'; + break; + case '8': + newEncodedData[i++] = 'B'; + break; + default: + if (('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ('2' <= ch && ch <= '7')) { + newEncodedData[i++] = ch; + } + } + } + newEncodedData.resize(i); + + return addPadding(newEncodedData); +} diff --git a/src/core/Base32.h b/src/core/Base32.h new file mode 100644 index 00000000..04882897 --- /dev/null +++ b/src/core/Base32.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Conforms to RFC 4648. For details, see: https://tools.ietf.org/html/rfc4648 + * Use the functions Base32::addPadding/1, Base32::removePadding/1 or + * Base32::sanitizeInput/1 to fix input or output for a particular + * applications (e.g. to use with Google Authenticator). + */ + +#ifndef BASE32_H +#define BASE32_H + +#include "Optional.h" +#include +#include + +class Base32 +{ +public: + Base32() = default; + Q_REQUIRED_RESULT static Optional decode(const QByteArray&); + Q_REQUIRED_RESULT static QByteArray encode(const QByteArray&); + Q_REQUIRED_RESULT static QByteArray addPadding(const QByteArray&); + Q_REQUIRED_RESULT static QByteArray removePadding(const QByteArray&); + Q_REQUIRED_RESULT static QByteArray sanitizeInput(const QByteArray&); +}; + +#endif // BASE32_H diff --git a/src/core/Optional.h b/src/core/Optional.h new file mode 100644 index 00000000..0721daa3 --- /dev/null +++ b/src/core/Optional.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef OPTIONAL_H +#define OPTIONAL_H + +/* + * This utility class is for providing basic support for an option type. + * It can be replaced by std::optional (C++17) or + * std::experimental::optional (C++11) when they become fully supported + * by all the main compiler toolchains. + */ + +template class Optional +{ +public: + // None + Optional() + : m_hasValue(false) + , m_value(){}; + + // Some T + Optional(const T& value) + : m_hasValue(true) + , m_value(value){}; + + // Copy + Optional(const Optional& other) + : m_hasValue(other.m_hasValue) + , m_value(other.m_value){}; + + const Optional& operator=(const Optional& other) + { + m_hasValue = other.m_hasValue; + m_value = other.m_value; + return *this; + } + + bool operator==(const Optional& other) const + { + if (m_hasValue) + return other.m_hasValue && m_value == other.m_value; + else + return !other.m_hasValue; + } + + bool operator!=(const Optional& other) const + { + return !(*this == other); + } + + bool hasValue() const + { + return m_hasValue; + } + + T valueOr(const T& other) const + { + return m_hasValue ? m_value : other; + } + + Optional static makeOptional(const T& value) + { + return Optional(value); + } + +private: + bool m_hasValue; + T m_value; +}; + +#endif // OPTIONAL_H diff --git a/src/totp/base32.cpp b/src/totp/base32.cpp deleted file mode 100644 index 4c81cb49..00000000 --- a/src/totp/base32.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Base32 implementation -// Source: https://github.com/google/google-authenticator-libpam/blob/master/src/base32.c -// -// Copyright 2010 Google Inc. -// Author: Markus Gutschke -// Modifications Copyright 2017 KeePassXC team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "base32.h" - -Base32::Base32() -{ -} - -QByteArray Base32::base32_decode(const QByteArray encoded) -{ - QByteArray result; - - int buffer = 0; - int bitsLeft = 0; - - for (char ch : encoded) { - if (ch == 0 || ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-' || ch == '=') { - continue; - } - - buffer <<= 5; - - // Deal with commonly mistyped characters - if (ch == '0') { - ch = 'O'; - } else if (ch == '1') { - ch = 'L'; - } else if (ch == '8') { - ch = 'B'; - } - - // Look up one base32 digit - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { - ch = (ch & 0x1F) - 1; - } else if (ch >= '2' && ch <= '7') { - ch -= '2' - 26; - } else { - return QByteArray(); - } - - buffer |= ch; - bitsLeft += 5; - - if (bitsLeft >= 8) { - result.append(static_cast (buffer >> (bitsLeft - 8))); - bitsLeft -= 8; - } - } - - return result; -} \ No newline at end of file diff --git a/src/totp/base32.h b/src/totp/base32.h deleted file mode 100644 index 75343fa4..00000000 --- a/src/totp/base32.h +++ /dev/null @@ -1,34 +0,0 @@ -// Base32 implementation -// Source: https://github.com/google/google-authenticator-libpam/blob/master/src/base32.h -// -// Copyright 2010 Google Inc. -// Author: Markus Gutschke -// Modifications Copyright 2017 KeePassXC team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef BASE32_H -#define BASE32_H - -#include -#include - -class Base32 -{ -public: - Base32(); - static QByteArray base32_decode(const QByteArray encoded); -}; - - -#endif //BASE32_H diff --git a/src/totp/totp.cpp b/src/totp/totp.cpp index 51af0e08..170ac2da 100644 --- a/src/totp/totp.cpp +++ b/src/totp/totp.cpp @@ -17,16 +17,15 @@ */ #include "totp.h" -#include "base32.h" -#include -#include -#include -#include +#include "core/Base32.h" #include +#include #include +#include #include #include - +#include +#include const quint8 QTotp::defaultStep = 30; const quint8 QTotp::defaultDigits = 6; @@ -35,7 +34,7 @@ QTotp::QTotp() { } -QString QTotp::parseOtpString(QString key, quint8 &digits, quint8 &step) +QString QTotp::parseOtpString(QString key, quint8& digits, quint8& step) { QUrl url(key); @@ -58,7 +57,6 @@ QString QTotp::parseOtpString(QString key, quint8 &digits, quint8 &step) step = q_step; } - } else { // Compatibility with "KeeOtp" plugin string format QRegExp rx("key=(.+)", Qt::CaseInsensitive, QRegExp::RegExp); @@ -93,30 +91,53 @@ QString QTotp::parseOtpString(QString key, quint8 &digits, quint8 &step) return seed; } -QString QTotp::generateTotp(const QByteArray key, quint64 time, - const quint8 numDigits = defaultDigits, const quint8 step = defaultStep) +QString QTotp::generateTotp(const QByteArray key, + quint64 time, + const quint8 numDigits = defaultDigits, + const quint8 step = defaultStep) { quint64 current = qToBigEndian(time / step); - QByteArray secret = Base32::base32_decode(key); - if (secret.isEmpty()) { + Optional secret = Base32::decode(Base32::sanitizeInput(key)); + if (!secret.hasValue()) { return "Invalid TOTP secret key"; } QMessageAuthenticationCode code(QCryptographicHash::Sha1); - code.setKey(secret); + code.setKey(secret.valueOr("")); code.addData(QByteArray(reinterpret_cast(¤t), sizeof(current))); QByteArray hmac = code.result(); int offset = (hmac[hmac.length() - 1] & 0xf); - int binary = - ((hmac[offset] & 0x7f) << 24) - | ((hmac[offset + 1] & 0xff) << 16) - | ((hmac[offset + 2] & 0xff) << 8) - | (hmac[offset + 3] & 0xff); + int binary = ((hmac[offset] & 0x7f) << 24) | ((hmac[offset + 1] & 0xff) << 16) | ((hmac[offset + 2] & 0xff) << 8) | + (hmac[offset + 3] & 0xff); quint32 digitsPower = pow(10, numDigits); quint64 password = binary % digitsPower; return QString("%1").arg(password, numDigits, 10, QChar('0')); } + +// See: https://github.com/google/google-authenticator/wiki/Key-Uri-Format +QUrl QTotp::generateOtpString(const QString& secret, + const QString& type, + const QString& issuer, + const QString& username, + const QString& algorithm, + const quint8& digits, + const quint8& step) +{ + QUrl keyUri; + keyUri.setScheme("otpauth"); + keyUri.setHost(type); + keyUri.setPath(QString("/%1:%2").arg(issuer).arg(username)); + QUrlQuery parameters; + parameters.addQueryItem("secret", secret); + parameters.addQueryItem("issuer", issuer); + parameters.addQueryItem("algorithm", algorithm); + parameters.addQueryItem("digits", QString::number(digits)); + parameters.addQueryItem("period", QString::number(step)); + keyUri.setQuery(parameters); + + return keyUri; +} diff --git a/src/totp/totp.h b/src/totp/totp.h index 642b4f9a..d5d8aa67 100644 --- a/src/totp/totp.h +++ b/src/totp/totp.h @@ -21,12 +21,21 @@ #include +class QUrl; + class QTotp { public: QTotp(); - static QString parseOtpString(QString rawSecret, quint8 &digits, quint8 &step); + static QString parseOtpString(QString rawSecret, quint8& digits, quint8& step); static QString generateTotp(const QByteArray key, quint64 time, const quint8 numDigits, const quint8 step); + static QUrl generateOtpString(const QString& secret, + const QString& type, + const QString& issuer, + const QString& username, + const QString& algorithm, + const quint8& digits, + const quint8& step); static const quint8 defaultStep; static const quint8 defaultDigits; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a420270..3f003f01 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -161,6 +161,9 @@ add_unit_test(NAME testentry SOURCES TestEntry.cpp add_unit_test(NAME testtotp SOURCES TestTotp.cpp LIBS ${TEST_LIBRARIES}) +add_unit_test(NAME testbase32 SOURCES TestBase32.cpp + LIBS ${TEST_LIBRARIES}) + add_unit_test(NAME testcsvparser SOURCES TestCsvParser.cpp LIBS ${TEST_LIBRARIES}) diff --git a/tests/TestBase32.cpp b/tests/TestBase32.cpp new file mode 100644 index 00000000..3d829d96 --- /dev/null +++ b/tests/TestBase32.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "TestBase32.h" +#include "core/Base32.h" +#include + +QTEST_GUILESS_MAIN(TestBase32) + +void TestBase32::testDecode() +{ + // 3 quanta, all upper case + padding + QByteArray encodedData = "JBSWY3DPEB3W64TMMQXC4LQ="; + auto data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("Hello world...")); + + // 4 quanta, all upper case + encodedData = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + + // 4 quanta, all lower case + encodedData = "gezdgnbvgy3tqojqgezdgnbvgy3tqojq"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + + // 4 quanta, mixed upper and lower case + encodedData = "Gezdgnbvgy3tQojqgezdGnbvgy3tQojQ"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + + // 1 pad characters + encodedData = "ORSXG5A="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("test")); + + // 3 pad characters + encodedData = "L5PV6==="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("___")); + + // 4 pad characters + encodedData = "MZXW6IDCMFZA===="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foo bar")); + + // six pad characters + encodedData = "MZXW6YTBOI======"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foobar")); + + encodedData = "IA======"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("@")); + + // error: illegal character + encodedData = "1MZXW6YTBOI====="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("ERROR")); + + // error: missing pad character + encodedData = "MZXW6YTBOI====="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("ERROR")); + + // RFC 4648 test vectors + encodedData = ""; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("")); + + encodedData = "MY======"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("f")); + + encodedData = "MZXQ===="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("fo")); + + encodedData = "MZXW6==="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foo")); + + encodedData = "MZXW6YQ="; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foob")); + + encodedData = "MZXW6YTB"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("fooba")); + + encodedData = "MZXW6YTBOI======"; + data = Base32::decode(encodedData); + QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foobar")); +} + +void TestBase32::testEncode() +{ + QByteArray data = "Hello world..."; + QByteArray encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("JBSWY3DPEB3W64TMMQXC4LQ=")); + + data = "12345678901234567890"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ")); + + data = "012345678901234567890"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("GAYTEMZUGU3DOOBZGAYTEMZUGU3DOOBZGA======")); + + data = "test"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("ORSXG5A=")); + + data = "___"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("L5PV6===")); + + data = "foo bar"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXW6IDCMFZA====")); + + data = "@"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("IA======")); + + // RFC 4648 test vectors + data = ""; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("")); + + data = "f"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MY======")); + + data = "fo"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXQ====")); + + data = "foo"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXW6===")); + + data = "foob"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXW6YQ=")); + + data = "fooba"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXW6YTB")); + + data = "foobar"; + encodedData = Base32::encode(data); + QCOMPARE(encodedData, QByteArray("MZXW6YTBOI======")); +} + +void TestBase32::testAddPadding() +{ + // Empty. Invalid, returns input. + QByteArray data = ""; + QByteArray paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, data); + + // One byte of encoded data. Invalid, returns input. + data = "B"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, data); + + // Two bytes of encoded data. + data = "BB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, QByteArray("BB======")); + + // Three bytes of encoded data. Invalid, returns input. + data = "BBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, data); + + // Four bytes of encoded data. + data = "BBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, QByteArray("BBBB====")); + + // Five bytes of encoded data. + data = "BBBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, QByteArray("BBBBB===")); + + // Six bytes of encoded data. Invalid, returns input. + data = "BBBBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, data); + + // Seven bytes of encoded data. + data = "BBBBBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, QByteArray("BBBBBBB=")); + + // Eight bytes of encoded data. Valid, but returns same as input. + data = "BBBBBBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, data); + + // More than eight bytes (8+5). + data = "AAAAAAAABBBBB"; + paddedData = Base32::addPadding(data); + QCOMPARE(paddedData, QByteArray("AAAAAAAABBBBB===")); +} + +void TestBase32::testRemovePadding() +{ + QByteArray data = ""; + QByteArray unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, data); + + data = "AAAAAAAABB======"; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, QByteArray("AAAAAAAABB")); + + data = "BBBB===="; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, QByteArray("BBBB")); + + data = "AAAAAAAABBBBB==="; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, QByteArray("AAAAAAAABBBBB")); + + data = "BBBBBBB="; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, QByteArray("BBBBBBB")); + + // Invalid: 7 bytes of data. Returns same as input. + data = "IIIIIII"; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, data); + + // Invalid: more padding than necessary. Returns same as input. + data = "AAAAAAAABBBB====="; + unpaddedData = Base32::removePadding(data); + QCOMPARE(unpaddedData, data); +} + +void TestBase32::testSanitizeInput() +{ + // sanitize input (white space + missing padding) + QByteArray encodedData = "JBSW Y3DP EB3W 64TM MQXC 4LQA"; + auto data = Base32::decode(Base32::sanitizeInput(encodedData)); + QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + + // sanitize input (typo + missing padding) + encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; + data = Base32::decode(Base32::sanitizeInput(encodedData)); + QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + + // sanitize input (other illegal characters) + encodedData = "J8SWY3D[PE83W64TMMQ]XC!4LQA"; + data = Base32::decode(Base32::sanitizeInput(encodedData)); + QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + + // sanitize input (NUL character) + encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; + encodedData.insert(3, '\0'); + data = Base32::decode(Base32::sanitizeInput(encodedData)); + QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); +} diff --git a/tests/TestBase32.h b/tests/TestBase32.h new file mode 100644 index 00000000..cf7cf092 --- /dev/null +++ b/tests/TestBase32.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSX_TESTBASE32_H +#define KEEPASSX_TESTBASE32_H + +#include + +class Base32; + +class TestBase32 : public QObject +{ + Q_OBJECT + +private slots: + void testEncode(); + void testDecode(); + void testAddPadding(); + void testRemovePadding(); + void testSanitizeInput(); +}; + +#endif // KEEPASSX_TESTBASE32_H diff --git a/tests/TestTotp.cpp b/tests/TestTotp.cpp index e22c2567..48ff8814 100644 --- a/tests/TestTotp.cpp +++ b/tests/TestTotp.cpp @@ -18,15 +18,14 @@ #include "TestTotp.h" -#include -#include #include -#include +#include #include +#include +#include #include "crypto/Crypto.h" #include "totp/totp.h" -#include "totp/base32.h" QTEST_GUILESS_MAIN(TestTotp) @@ -35,12 +34,13 @@ void TestTotp::initTestCase() QVERIFY(Crypto::init()); } - void TestTotp::testParseSecret() { quint8 digits = 0; quint8 step = 0; - QString secret = "otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30"; + QString secret = "otpauth://totp/" + "ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=" + "SHA1&digits=6&period=30"; QCOMPARE(QTotp::parseOtpString(secret, digits, step), QString("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ")); QCOMPARE(digits, quint8(6)); QCOMPARE(step, quint8(30)); @@ -60,25 +60,6 @@ void TestTotp::testParseSecret() QCOMPARE(step, quint8(30)); } -void TestTotp::testBase32() -{ - QByteArray key = QString("JBSW Y3DP EB3W 64TM MQXC 4LQA").toLatin1(); - QByteArray secret = Base32::base32_decode(key); - QCOMPARE(QString::fromLatin1(secret), QString("Hello world...")); - - key = QString("gezdgnbvgy3tqojqgezdgnbvgy3tqojq").toLatin1(); - secret = Base32::base32_decode(key); - QCOMPARE(QString::fromLatin1(secret), QString("12345678901234567890")); - - key = QString("ORSXG5A=").toLatin1(); - secret = Base32::base32_decode(key); - QCOMPARE(QString::fromLatin1(secret), QString("test")); - - key = QString("MZXW6YTBOI======").toLatin1(); - secret = Base32::base32_decode(key); - QCOMPARE(QString::fromLatin1(secret), QString("foobar")); -} - void TestTotp::testTotpCode() { // Test vectors from RFC 6238 diff --git a/tests/TestTotp.h b/tests/TestTotp.h index d197294d..785a9f52 100644 --- a/tests/TestTotp.h +++ b/tests/TestTotp.h @@ -30,7 +30,6 @@ class TestTotp : public QObject private slots: void initTestCase(); void testParseSecret(); - void testBase32(); void testTotpCode(); }; From 95b0ad15ef5f1f33d9b27f8eec47fa2fee81f1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Thu, 19 Oct 2017 13:52:23 -0600 Subject: [PATCH 023/118] Fix code style --- src/core/Base32.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index 8b2faf62..84dca5ec 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -206,8 +206,9 @@ QByteArray Base32::encode(const QByteArray& data) } // add pad characters - while (o < encodedData.size()) + while (o < encodedData.size()) { encodedData[o++] = '='; + } } Q_ASSERT(encodedData.size() == o); From d21ae0f94ab5af5900ade0776d52a6e83ae614e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 14:54:31 -0600 Subject: [PATCH 024/118] Fix for loop's variable increment style --- src/core/Base32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index 84dca5ec..5bd20901 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -94,7 +94,7 @@ Optional Base32::decode(const QByteArray& encodedData) quint64 quantum = 0; int nQuantumBytes = 5; - for (int n = 0; n < 8; n++) { + for (int n = 0; n < 8; ++n) { quint8 ch = static_cast(encodedData[i++]); if ((ASCII_A <= ch && ch <= ASCII_Z) || (ASCII_a <= ch && ch <= ASCII_z)) { ch -= ASCII_A; From 905e104ba24c8322832c660764c779b915dd65bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 15:23:21 -0600 Subject: [PATCH 025/118] Revert formatting change --- src/totp/totp.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/totp/totp.cpp b/src/totp/totp.cpp index 170ac2da..28d808e3 100644 --- a/src/totp/totp.cpp +++ b/src/totp/totp.cpp @@ -109,8 +109,14 @@ QString QTotp::generateTotp(const QByteArray key, QByteArray hmac = code.result(); int offset = (hmac[hmac.length() - 1] & 0xf); - int binary = ((hmac[offset] & 0x7f) << 24) | ((hmac[offset + 1] & 0xff) << 16) | ((hmac[offset + 2] & 0xff) << 8) | - (hmac[offset + 3] & 0xff); + + // clang-format off + int binary = + ((hmac[offset] & 0x7f) << 24) + | ((hmac[offset + 1] & 0xff) << 16) + | ((hmac[offset + 2] & 0xff) << 8) + | (hmac[offset + 3] & 0xff); + // clang-format on quint32 digitsPower = pow(10, numDigits); From 24f560aaa2c0a4574697bdc9b7ec41de9815c6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 16:55:02 -0600 Subject: [PATCH 026/118] Replace Optional with QVariant --- src/CMakeLists.txt | 1 - src/core/Base32.cpp | 10 +++--- src/core/Base32.h | 4 +-- src/core/Optional.h | 86 -------------------------------------------- src/totp/totp.cpp | 7 ++-- tests/TestBase32.cpp | 66 ++++++++++++++++++++++------------ 6 files changed, 54 insertions(+), 120 deletions(-) delete mode 100644 src/core/Optional.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 28170b16..5255186e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,7 +61,6 @@ set(keepassx_SOURCES core/Uuid.cpp core/Base32.h core/Base32.cpp - core/Optional.h cli/PasswordInput.cpp cli/PasswordInput.h crypto/Crypto.cpp diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index 5bd20901..6fdecccd 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -40,14 +40,14 @@ constexpr quint8 ASCII_a = static_cast('a'); constexpr quint8 ASCII_z = static_cast('z'); constexpr quint8 ASCII_EQ = static_cast('='); -Optional Base32::decode(const QByteArray& encodedData) +QVariant Base32::decode(const QByteArray& encodedData) { if (encodedData.size() <= 0) { - return Optional(""); + return QVariant::fromValue(QByteArray("")); } if (encodedData.size() % 8 != 0) { - return Optional(); + return QVariant(); } int nPads = 0; @@ -114,7 +114,7 @@ Optional Base32::decode(const QByteArray& encodedData) continue; } else { // illegal character - return Optional(); + return QVariant(); } } } @@ -132,7 +132,7 @@ Optional Base32::decode(const QByteArray& encodedData) } } - return Optional(data); + return QVariant::fromValue(data); } QByteArray Base32::encode(const QByteArray& data) diff --git a/src/core/Base32.h b/src/core/Base32.h index 04882897..204368c5 100644 --- a/src/core/Base32.h +++ b/src/core/Base32.h @@ -24,15 +24,15 @@ #ifndef BASE32_H #define BASE32_H -#include "Optional.h" #include +#include #include class Base32 { public: Base32() = default; - Q_REQUIRED_RESULT static Optional decode(const QByteArray&); + Q_REQUIRED_RESULT static QVariant decode(const QByteArray&); Q_REQUIRED_RESULT static QByteArray encode(const QByteArray&); Q_REQUIRED_RESULT static QByteArray addPadding(const QByteArray&); Q_REQUIRED_RESULT static QByteArray removePadding(const QByteArray&); diff --git a/src/core/Optional.h b/src/core/Optional.h deleted file mode 100644 index 0721daa3..00000000 --- a/src/core/Optional.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2017 KeePassXC Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 or (at your option) - * version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef OPTIONAL_H -#define OPTIONAL_H - -/* - * This utility class is for providing basic support for an option type. - * It can be replaced by std::optional (C++17) or - * std::experimental::optional (C++11) when they become fully supported - * by all the main compiler toolchains. - */ - -template class Optional -{ -public: - // None - Optional() - : m_hasValue(false) - , m_value(){}; - - // Some T - Optional(const T& value) - : m_hasValue(true) - , m_value(value){}; - - // Copy - Optional(const Optional& other) - : m_hasValue(other.m_hasValue) - , m_value(other.m_value){}; - - const Optional& operator=(const Optional& other) - { - m_hasValue = other.m_hasValue; - m_value = other.m_value; - return *this; - } - - bool operator==(const Optional& other) const - { - if (m_hasValue) - return other.m_hasValue && m_value == other.m_value; - else - return !other.m_hasValue; - } - - bool operator!=(const Optional& other) const - { - return !(*this == other); - } - - bool hasValue() const - { - return m_hasValue; - } - - T valueOr(const T& other) const - { - return m_hasValue ? m_value : other; - } - - Optional static makeOptional(const T& value) - { - return Optional(value); - } - -private: - bool m_hasValue; - T m_value; -}; - -#endif // OPTIONAL_H diff --git a/src/totp/totp.cpp b/src/totp/totp.cpp index 28d808e3..7a584def 100644 --- a/src/totp/totp.cpp +++ b/src/totp/totp.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -98,13 +99,13 @@ QString QTotp::generateTotp(const QByteArray key, { quint64 current = qToBigEndian(time / step); - Optional secret = Base32::decode(Base32::sanitizeInput(key)); - if (!secret.hasValue()) { + QVariant secret = Base32::decode(Base32::sanitizeInput(key)); + if (secret.isNull()) { return "Invalid TOTP secret key"; } QMessageAuthenticationCode code(QCryptographicHash::Sha1); - code.setKey(secret.valueOr("")); + code.setKey(secret.toByteArray()); code.addData(QByteArray(reinterpret_cast(¤t), sizeof(current))); QByteArray hmac = code.result(); diff --git a/tests/TestBase32.cpp b/tests/TestBase32.cpp index 3d829d96..615b356f 100644 --- a/tests/TestBase32.cpp +++ b/tests/TestBase32.cpp @@ -25,86 +25,102 @@ void TestBase32::testDecode() { // 3 quanta, all upper case + padding QByteArray encodedData = "JBSWY3DPEB3W64TMMQXC4LQ="; - auto data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("Hello world...")); + QVariant data = Base32::decode(encodedData); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("Hello world...")); // 4 quanta, all upper case encodedData = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("12345678901234567890")); // 4 quanta, all lower case encodedData = "gezdgnbvgy3tqojqgezdgnbvgy3tqojq"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("12345678901234567890")); // 4 quanta, mixed upper and lower case encodedData = "Gezdgnbvgy3tQojqgezdGnbvgy3tQojQ"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("12345678901234567890")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("12345678901234567890")); // 1 pad characters encodedData = "ORSXG5A="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("test")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("test")); // 3 pad characters encodedData = "L5PV6==="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("___")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("___")); // 4 pad characters encodedData = "MZXW6IDCMFZA===="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foo bar")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("foo bar")); // six pad characters encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foobar")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("foobar")); encodedData = "IA======"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("@")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("@")); // error: illegal character encodedData = "1MZXW6YTBOI====="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("ERROR")); + QVERIFY(data.isNull()); // error: missing pad character encodedData = "MZXW6YTBOI====="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("ERROR")); + QVERIFY(data.isNull()); // RFC 4648 test vectors encodedData = ""; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("")); encodedData = "MY======"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("f")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("f")); encodedData = "MZXQ===="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("fo")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("fo")); encodedData = "MZXW6==="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foo")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("foo")); encodedData = "MZXW6YQ="; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foob")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("foob")); encodedData = "MZXW6YTB"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("fooba")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("fooba")); encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); - QCOMPARE(QString::fromLatin1(data.valueOr("ERROR")), QString("foobar")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("foobar")); } void TestBase32::testEncode() @@ -258,21 +274,25 @@ void TestBase32::testSanitizeInput() // sanitize input (white space + missing padding) QByteArray encodedData = "JBSW Y3DP EB3W 64TM MQXC 4LQA"; auto data = Base32::decode(Base32::sanitizeInput(encodedData)); - QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("Hello world...")); // sanitize input (typo + missing padding) encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; data = Base32::decode(Base32::sanitizeInput(encodedData)); - QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("Hello world...")); // sanitize input (other illegal characters) encodedData = "J8SWY3D[PE83W64TMMQ]XC!4LQA"; data = Base32::decode(Base32::sanitizeInput(encodedData)); - QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("Hello world...")); // sanitize input (NUL character) encodedData = "J8SWY3DPE83W64TMMQXC4LQA"; encodedData.insert(3, '\0'); data = Base32::decode(Base32::sanitizeInput(encodedData)); - QCOMPARE(QString::fromLatin1(data.valueOr("ERRROR")), QString("Hello world...")); + QVERIFY(!data.isNull()); + QCOMPARE(data.toString(), QString("Hello world...")); } From c731f8e5c05b8546a5aa35e3b0b8f027dc1f4009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 18:05:33 -0600 Subject: [PATCH 027/118] Fix bug in Base32::decode and add bounds check The bug that was fixed, was affecting how the number of bytes of decoded data was calculated and thus, even though it didn't truncate the result, it was causing the array to be resized unnecessarily. --- src/core/Base32.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index 6fdecccd..b76fd029 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -83,7 +83,7 @@ QVariant Base32::decode(const QByteArray& encodedData) Q_ASSERT(encodedData.size() > 0); const int nQuanta = encodedData.size() / 8; - const int nBytes = (nQuanta - 1) * 5 + nSpecialBytes; + const int nBytes = nSpecialBytes > 0 ? (nQuanta - 1) * 5 + nSpecialBytes : nQuanta * 5; QByteArray data(nBytes, Qt::Uninitialized); @@ -126,12 +126,17 @@ QVariant Base32::decode(const QByteArray& encodedData) const int offset = (nQuantumBytes - 1) * 8; quint64 mask = quint64(0xFF) << offset; for (int n = offset; n >= 0; n -= 8) { - char c = static_cast((quantum & mask) >> n); - data[o++] = c; - mask >>= 8; + if (o < nBytes) { + data[o++] = static_cast((quantum & mask) >> n); + mask >>= 8; + } else { + break; + } } } + Q_ASSERT(nBytes == o); + return QVariant::fromValue(data); } @@ -144,6 +149,7 @@ QByteArray Base32::encode(const QByteArray& data) const int nBits = data.size() * 8; const int rBits = nBits % 40; // in {0, 8, 16, 24, 32} const int nQuanta = nBits / 40 + (rBits > 0 ? 1 : 0); + const int nBytes = nQuanta * 8; QByteArray encodedData(nQuanta * 8, Qt::Uninitialized); int i = 0; @@ -211,7 +217,8 @@ QByteArray Base32::encode(const QByteArray& data) } } - Q_ASSERT(encodedData.size() == o); + Q_ASSERT(data.size() == i); + Q_ASSERT(nBytes == o); return encodedData; } From f1d99dd0ede60bfe16438caaf7323219a36fa015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 18:31:17 -0600 Subject: [PATCH 028/118] Improve testing of Base32 --- src/core/Base32.cpp | 1 + tests/TestBase32.cpp | 64 +++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index b76fd029..cfd7f04c 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -135,6 +135,7 @@ QVariant Base32::decode(const QByteArray& encodedData) } } + Q_ASSERT(encodedData.size() == i); Q_ASSERT(nBytes == o); return QVariant::fromValue(data); diff --git a/tests/TestBase32.cpp b/tests/TestBase32.cpp index 615b356f..1d30e781 100644 --- a/tests/TestBase32.cpp +++ b/tests/TestBase32.cpp @@ -26,55 +26,73 @@ void TestBase32::testDecode() // 3 quanta, all upper case + padding QByteArray encodedData = "JBSWY3DPEB3W64TMMQXC4LQ="; QVariant data = Base32::decode(encodedData); + QString expectedData = "Hello world..."; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("Hello world...")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 4 quanta, all upper case encodedData = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"; data = Base32::decode(encodedData); + expectedData = "12345678901234567890"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("12345678901234567890")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 4 quanta, all lower case encodedData = "gezdgnbvgy3tqojqgezdgnbvgy3tqojq"; data = Base32::decode(encodedData); + expectedData = "12345678901234567890"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("12345678901234567890")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 4 quanta, mixed upper and lower case encodedData = "Gezdgnbvgy3tQojqgezdGnbvgy3tQojQ"; data = Base32::decode(encodedData); + expectedData = "12345678901234567890"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("12345678901234567890")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 1 pad characters encodedData = "ORSXG5A="; data = Base32::decode(encodedData); + expectedData = "test"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("test")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 3 pad characters encodedData = "L5PV6==="; data = Base32::decode(encodedData); + expectedData = "___"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("___")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // 4 pad characters encodedData = "MZXW6IDCMFZA===="; data = Base32::decode(encodedData); + expectedData = "foo bar"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("foo bar")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // six pad characters encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); + expectedData = "foobar"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("foobar")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "IA======"; data = Base32::decode(encodedData); + expectedData = "@"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("@")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); // error: illegal character encodedData = "1MZXW6YTBOI====="; @@ -89,38 +107,52 @@ void TestBase32::testDecode() // RFC 4648 test vectors encodedData = ""; data = Base32::decode(encodedData); + expectedData = ""; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MY======"; data = Base32::decode(encodedData); + expectedData = "f"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("f")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MZXQ===="; data = Base32::decode(encodedData); + expectedData = "fo"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("fo")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MZXW6==="; data = Base32::decode(encodedData); QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("foo")); + expectedData = "foo"; + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MZXW6YQ="; data = Base32::decode(encodedData); + expectedData = "foob"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("foob")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MZXW6YTB"; + expectedData = "fooba"; data = Base32::decode(encodedData); QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("fooba")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); encodedData = "MZXW6YTBOI======"; data = Base32::decode(encodedData); + expectedData = "foobar"; QVERIFY(!data.isNull()); - QCOMPARE(data.toString(), QString("foobar")); + QCOMPARE(data.toString(), expectedData); + QVERIFY(data.value().size() == expectedData.size()); } void TestBase32::testEncode() From 86cd2c09a416fbb86eba4713a8ad66b27127795c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Fri, 20 Oct 2017 23:50:34 -0600 Subject: [PATCH 029/118] Improve readability of code --- src/core/Base32.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/core/Base32.cpp b/src/core/Base32.cpp index cfd7f04c..13228a37 100644 --- a/src/core/Base32.cpp +++ b/src/core/Base32.cpp @@ -125,13 +125,9 @@ QVariant Base32::decode(const QByteArray& encodedData) const int offset = (nQuantumBytes - 1) * 8; quint64 mask = quint64(0xFF) << offset; - for (int n = offset; n >= 0; n -= 8) { - if (o < nBytes) { + for (int n = offset; n >= 0 && o < nBytes; n -= 8) { data[o++] = static_cast((quantum & mask) >> n); mask >>= 8; - } else { - break; - } } } From 09e94397aa7b2508591ff10683ea69d39485c720 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 13:27:25 +0200 Subject: [PATCH 030/118] Remove emoji in commit messages from style guide --- .github/CONTRIBUTING.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index df542958..4f937513 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -103,18 +103,8 @@ The Branch Strategy is based on [git-flow-lite](http://nvie.com/posts/a-successf * Use the imperative mood ("Move cursor to…" not "Moves cursor to…") * Limit the first line to 72 characters or less * Reference issues and pull requests liberally +* If your pull request fixes an existing issue, add "…, resolves #ISSUENUMBER" to your main commit * When only changing documentation, include `[ci skip]` in the commit description -* Consider starting the commit message with an applicable emoji: - * :memo: `:memo:` when writing docs - * :penguin: `:penguin:` when fixing something on Linux - * :apple: `:apple:` when fixing something on macOS - * :checkered_flag: `:checkered_flag:` when fixing something on Windows - * :bug: `:bug:` when fixing a bug - * :fire: `:fire:` when removing code or files - * :green_heart: `:green_heart:` when fixing the CI build - * :white_check_mark: `:white_check_mark:` when adding tests - * :lock: `:lock:` when dealing with security - ### Coding styleguide From 0fe06b3fbb0c4758d8a09335e1d7d635b079587a Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Thu, 5 Oct 2017 14:44:05 -0400 Subject: [PATCH 031/118] Fix double warning display for database open --- src/gui/DatabaseOpenWidget.cpp | 37 +++++++++++++++++++--------------- src/gui/DatabaseOpenWidget.h | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index b8f8feb1..fee0c26e 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -162,7 +162,10 @@ void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile) void DatabaseOpenWidget::openDatabase() { KeePass2Reader reader; - CompositeKey masterKey = databaseKey(); + CompositeKey* masterKey = databaseKey(); + if (masterKey == nullptr) { + return; + } QFile file(m_filename); if (!file.open(QIODevice::ReadOnly)) { @@ -174,7 +177,7 @@ void DatabaseOpenWidget::openDatabase() delete m_db; } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - m_db = reader.readDatabase(&file, masterKey); + m_db = reader.readDatabase(&file, *masterKey); QApplication::restoreOverrideCursor(); if (m_db) { @@ -182,20 +185,21 @@ void DatabaseOpenWidget::openDatabase() m_ui->messageWidget->animatedHide(); } emit editFinished(true); - } - else { - m_ui->messageWidget->showMessage(tr("Unable to open the database.") - .append("\n").append(reader.errorString()), MessageWidget::Error); + } else { + m_ui->messageWidget->showMessage(tr("Unable to open the database.").append("\n").append(reader.errorString()), + MessageWidget::Error); m_ui->editPassword->clear(); } + + delete masterKey; } -CompositeKey DatabaseOpenWidget::databaseKey() +CompositeKey* DatabaseOpenWidget::databaseKey() { - CompositeKey masterKey; + CompositeKey* masterKey = new CompositeKey(); if (m_ui->checkPassword->isChecked()) { - masterKey.addKey(PasswordKey(m_ui->editPassword->text())); + masterKey->addKey(PasswordKey(m_ui->editPassword->text())); } QHash lastKeyFiles = config()->get("LastKeyFiles").toHash(); @@ -206,11 +210,12 @@ CompositeKey DatabaseOpenWidget::databaseKey() QString keyFilename = m_ui->comboKeyFile->currentText(); QString errorMsg; if (!key.load(keyFilename, &errorMsg)) { - m_ui->messageWidget->showMessage(tr("Can't open key file").append(":\n") - .append(errorMsg), MessageWidget::Error); - return CompositeKey(); + m_ui->messageWidget->showMessage(tr("Can't open key file").append(":\n").append(errorMsg), + MessageWidget::Error); + delete masterKey; + return nullptr; } - masterKey.addKey(key); + masterKey->addKey(key); lastKeyFiles[m_filename] = keyFilename; } else { lastKeyFiles.remove(m_filename); @@ -237,9 +242,9 @@ CompositeKey DatabaseOpenWidget::databaseKey() // read blocking mode from LSB and slot index number from second LSB bool blocking = comboPayload & 1; - int slot = comboPayload >> 1; - auto key = QSharedPointer(new YkChallengeResponseKey(slot, blocking)); - masterKey.addChallengeResponseKey(key); + int slot = comboPayload >> 1; + auto key = QSharedPointer(new YkChallengeResponseKey(slot, blocking)); + masterKey->addChallengeResponseKey(key); } #endif diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h index d4b47364..d2a7e1fa 100644 --- a/src/gui/DatabaseOpenWidget.h +++ b/src/gui/DatabaseOpenWidget.h @@ -52,7 +52,7 @@ signals: protected: void showEvent(QShowEvent* event) override; void hideEvent(QHideEvent* event) override; - CompositeKey databaseKey(); + CompositeKey* databaseKey(); protected slots: virtual void openDatabase(); From a1aad5d165ab5b16937ff2a15d307fc9565a1ffb Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Sat, 14 Oct 2017 22:12:45 -0400 Subject: [PATCH 032/118] Using QScopedPointer --- src/gui/DatabaseOpenWidget.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index fee0c26e..19e9a3f4 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -162,8 +162,8 @@ void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile) void DatabaseOpenWidget::openDatabase() { KeePass2Reader reader; - CompositeKey* masterKey = databaseKey(); - if (masterKey == nullptr) { + QScopedPointer masterKey(databaseKey()); + if (masterKey.isNull()) { return; } @@ -190,8 +190,6 @@ void DatabaseOpenWidget::openDatabase() MessageWidget::Error); m_ui->editPassword->clear(); } - - delete masterKey; } CompositeKey* DatabaseOpenWidget::databaseKey() From aba2acb0620f0a34c29aaf4bac4eb790bec39782 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 14:00:25 +0200 Subject: [PATCH 033/118] Use QSharedPointer --- src/gui/DatabaseOpenWidget.cpp | 9 ++++----- src/gui/DatabaseOpenWidget.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 19e9a3f4..ee0e9de2 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -162,7 +162,7 @@ void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile) void DatabaseOpenWidget::openDatabase() { KeePass2Reader reader; - QScopedPointer masterKey(databaseKey()); + QSharedPointer masterKey = databaseKey(); if (masterKey.isNull()) { return; } @@ -192,9 +192,9 @@ void DatabaseOpenWidget::openDatabase() } } -CompositeKey* DatabaseOpenWidget::databaseKey() +QSharedPointer DatabaseOpenWidget::databaseKey() { - CompositeKey* masterKey = new CompositeKey(); + auto masterKey = QSharedPointer::create(); if (m_ui->checkPassword->isChecked()) { masterKey->addKey(PasswordKey(m_ui->editPassword->text())); @@ -210,8 +210,7 @@ CompositeKey* DatabaseOpenWidget::databaseKey() if (!key.load(keyFilename, &errorMsg)) { m_ui->messageWidget->showMessage(tr("Can't open key file").append(":\n").append(errorMsg), MessageWidget::Error); - delete masterKey; - return nullptr; + return QSharedPointer(); } masterKey->addKey(key); lastKeyFiles[m_filename] = keyFilename; diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h index d2a7e1fa..a7691a91 100644 --- a/src/gui/DatabaseOpenWidget.h +++ b/src/gui/DatabaseOpenWidget.h @@ -52,7 +52,7 @@ signals: protected: void showEvent(QShowEvent* event) override; void hideEvent(QHideEvent* event) override; - CompositeKey* databaseKey(); + QSharedPointer databaseKey(); protected slots: virtual void openDatabase(); From 2fa3f5072d2010c402d44c394b208cd32f108aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 06:02:34 -0600 Subject: [PATCH 034/118] Simplify the ZLIB version check --- CMakeLists.txt | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ec37473..bfefcadd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,17 +240,8 @@ find_package(ZLIB REQUIRED) set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR}) -check_cxx_source_compiles(" - #include - - #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1200) - #error zlib 1.2.x or higher is required to use the gzip format - #endif - - int main() { return 0; }" ZLIB_SUPPORTS_GZIP) - -if(NOT ZLIB_SUPPORTS_GZIP) - message(FATAL_ERROR "zlib 1.2.x or higher is required to use the gzip format") +if(ZLIB_VERSION_STRING VERSION_LESS "1.2.0") + message(FATAL_ERROR "zlib 1.2.0 or higher is required to use the gzip format") endif() # Optional From de065c728fb7600ec368e895ba4faab656c0dc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 06:54:27 -0600 Subject: [PATCH 035/118] Enable option WITH_ASAN for macOS builds --- CMakeLists.txt | 16 ++++++++++------ README.md | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfefcadd..f9aec839 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,9 @@ include(CheckCXXSourceCompiles) option(WITH_TESTS "Enable building of unit tests" ON) option(WITH_GUI_TESTS "Enable building of GUI tests" OFF) option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF) -option(WITH_ASAN "Enable address sanitizer checks (Linux only)" OFF) +option(WITH_ASAN "Enable address sanitizer checks (Linux and macOS only)" OFF) option(WITH_COVERAGE "Use to build with coverage tests (GCC only)." OFF) -option(WITH_APP_BUNDLE "Enable Application Bundle for OS X" ON) +option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON) option(WITH_XC_AUTOTYPE "Include Auto-Type." ON) option(WITH_XC_HTTP "Include KeePassHTTP and Custom Icon Downloads." OFF) @@ -110,16 +110,20 @@ endif() add_gcc_compiler_cxxflags("-fno-exceptions -fno-rtti") add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual") add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings") + if(WITH_ASAN) - if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") - message(FATAL_ERROR "WITH_ASAN is only supported on Linux at the moment.") + if(NOT (LINUX OR APPLE)) + message(FATAL_ERROR "WITH_ASAN is only supported on Linux and macOS at the moment.") endif() add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") - if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) - add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") + if(LINUX) + if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) + add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") + endif() endif() + endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) diff --git a/README.md b/README.md index 669b0b66..e379123c 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,12 @@ cmake accepts the following options: -DWITH_TESTS=[ON|OFF] Enable/Disable building of unit tests (default: ON) -DWITH_GUI_TESTS=[ON|OFF] Enable/Disable building of GUI tests (default: OFF) -DWITH_DEV_BUILD=[ON|OFF] Enable/Disable deprecated method warnings (default: OFF) - -DWITH_ASAN=[ON|OFF] Enable/Disable address sanitizer checks (Linux only) (default: OFF) + -DWITH_ASAN=[ON|OFF] Enable/Disable address sanitizer checks (Linux / macOS only) (default: OFF) -DWITH_COVERAGE=[ON|OFF] Enable/Disable coverage tests (GCC only) (default: OFF) ``` +:exclamation: When building with ASan support on macOS, you need to use `export ASAN_OPTIONS=detect_leaks=0` before running the tests (no LSan support in macOS). + ### Contributing We are always looking for suggestions how to improve our application. If you find any bugs or have an idea for a new feature, please let us know by opening a report in our [issue tracker](https://github.com/keepassxreboot/keepassxc/issues) on GitHub or join us on IRC on freenode channels #keepassxc or #keepassxc-dev. From 7198f20d6931bd39a17f41bd01d0c9d93ba56f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 16:27:07 -0600 Subject: [PATCH 036/118] Improve building of macOS target --- CMakeLists.txt | 42 +++++++++++++++++++++++---------- src/CMakeLists.txt | 18 +++++++------- src/autotype/mac/CMakeLists.txt | 6 ++--- utils/fix_mac.sh | 20 ---------------- 4 files changed, 39 insertions(+), 47 deletions(-) delete mode 100755 utils/fix_mac.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index f9aec839..7b465d22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ include(CheckCXXSourceCompiles) option(WITH_TESTS "Enable building of unit tests" ON) option(WITH_GUI_TESTS "Enable building of GUI tests" OFF) option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF) -option(WITH_ASAN "Enable address sanitizer checks (Linux and macOS only)" OFF) +option(WITH_ASAN "Enable address sanitizer checks (Linux / macOS only)" OFF) option(WITH_COVERAGE "Use to build with coverage tests (GCC only)." OFF) option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON) @@ -112,13 +112,13 @@ add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virt add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings") if(WITH_ASAN) - if(NOT (LINUX OR APPLE)) - message(FATAL_ERROR "WITH_ASAN is only supported on Linux and macOS at the moment.") + if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE)) + message(FATAL_ERROR "WITH_ASAN is only supported on Linux / macOS at the moment.") endif() add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") - if(LINUX) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") endif() @@ -220,17 +220,33 @@ if(WITH_TESTS) enable_testing() endif(WITH_TESTS) -find_package(Qt5Core 5.2 REQUIRED) -find_package(Qt5Network 5.2 REQUIRED) -find_package(Qt5Concurrent 5.2 REQUIRED) -find_package(Qt5Widgets 5.2 REQUIRED) -find_package(Qt5Test 5.2 REQUIRED) -find_package(Qt5LinguistTools 5.2 REQUIRED) -find_package(Qt5Network 5.2 REQUIRED) -if (UNIX AND NOT APPLE) - find_package(Qt5DBus 5.2 REQUIRED) +if(UNIX AND NOT APPLE) + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools DBus REQUIRED) +elseif(APPLE) + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools MacExtras REQUIRED + HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH + ) +else() + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools REQUIRED) endif() + +if(Qt5Core_VERSION VERSION_LESS "5.2.0") + message(FATAL_ERROR "Qt version 5.2.0 or higher is required") +endif() + set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +if(APPLE) + set(CMAKE_MACOSX_RPATH TRUE) + find_program(MACDEPLOYQT_EXE macdeployqt HINTS /usr/local/opt/qt5/bin ENV PATH) + if(NOT MACDEPLOYQT_EXE) + message(FATAL_ERROR "macdeployqt is required to use build in macOS") + else() + message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}") + endif() +endif() # Debian sets the the build type to None for package builds. # Make sure we don't enable asserts there. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd8a1fd3..3d5e7bf4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -234,6 +234,9 @@ target_link_libraries(keepassx_core if(APPLE) target_link_libraries(keepassx_core "-framework Foundation") + if(Qt5MacExtras_FOUND) + target_link_libraries(keepassx_core Qt5::MacExtras) + endif() endif() if (UNIX AND NOT APPLE) target_link_libraries(keepassx_core Qt5::DBus) @@ -264,13 +267,7 @@ if(APPLE AND WITH_APP_BUNDLE) set_target_properties(${PROGNAME} PROPERTIES MACOSX_BUNDLE ON MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) -endif() -install(TARGETS ${PROGNAME} - BUNDLE DESTINATION . COMPONENT Runtime - RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime) - -if(APPLE AND WITH_APP_BUNDLE) if(QT_MAC_USE_COCOA AND EXISTS "${QT_LIBRARY_DIR}/Resources/qt_menu.nib") install(DIRECTORY "${QT_LIBRARY_DIR}/Resources/qt_menu.nib" DESTINATION "${DATA_INSTALL_DIR}") @@ -284,16 +281,17 @@ if(APPLE AND WITH_APP_BUNDLE) set(CPACK_PACKAGE_FILE_NAME "${PROGNAME}-${KEEPASSXC_VERSION}") include(CPack) - if(NOT DEFINED QT_BINARY_DIR) - set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder") - endif() add_custom_command(TARGET ${PROGNAME} POST_BUILD - COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app + COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src COMMENT "Deploying app bundle") endif() +install(TARGETS ${PROGNAME} + BUNDLE DESTINATION . COMPONENT Runtime + RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime) + if(MINGW) if(${CMAKE_SIZEOF_VOID_P} EQUAL "8") set(OUTPUT_FILE_POSTFIX "Win64") diff --git a/src/autotype/mac/CMakeLists.txt b/src/autotype/mac/CMakeLists.txt index ac93de0e..08c53278 100644 --- a/src/autotype/mac/CMakeLists.txt +++ b/src/autotype/mac/CMakeLists.txt @@ -9,14 +9,12 @@ set(autotype_mac_mm_SOURCES add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES} ${autotype_mac_mm_SOURCES}) set_target_properties(keepassx-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon") target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets) -if(NOT DEFINED QT_BINARY_DIR) - set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder") -endif() + if(WITH_APP_BUNDLE) add_custom_command(TARGET keepassx-autotype-cocoa POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libkeepassx-autotype-cocoa.so ${PLUGIN_INSTALL_DIR} - COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app -executable=${PLUGIN_INSTALL_DIR}/libkeepassx-autotype-cocoa.so -no-plugins + COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app -executable=${PLUGIN_INSTALL_DIR}/libkeepassx-autotype-cocoa.so -no-plugins WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src COMMENT "Deploying autotype plugin") else() diff --git a/utils/fix_mac.sh b/utils/fix_mac.sh deleted file mode 100755 index 2e4e84e5..00000000 --- a/utils/fix_mac.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Canonical path to qt5 directory -QT="/usr/local/Cellar/qt" -if [ ! -d "$QT" ]; then - # Alternative (old) path to qt5 directory - QT+="5" - if [ ! -d "$QT" ]; then - echo "Qt/Qt5 not found!" - exit - fi -fi -QT5_DIR="$QT/$(ls $QT | sort -r | head -n1)" -echo $QT5_DIR - -# Change qt5 framework ids -for framework in $(find "$QT5_DIR/lib" -regex ".*/\(Qt[a-zA-Z]*\)\.framework/Versions/5/\1"); do - echo "$framework" - install_name_tool -id "$framework" "$framework" -done From fdc7471a7b42731c849028ad17dbbee323007545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20E=2E=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 17:28:26 -0600 Subject: [PATCH 037/118] Make QtMacExtras optional --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b465d22..5fa90173 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,10 @@ endif(WITH_TESTS) if(UNIX AND NOT APPLE) find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools DBus REQUIRED) elseif(APPLE) - find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools MacExtras REQUIRED + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools REQUIRED + HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH + ) + find_package(Qt5 COMPONENTS MacExtras HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH ) else() @@ -242,7 +245,7 @@ if(APPLE) set(CMAKE_MACOSX_RPATH TRUE) find_program(MACDEPLOYQT_EXE macdeployqt HINTS /usr/local/opt/qt5/bin ENV PATH) if(NOT MACDEPLOYQT_EXE) - message(FATAL_ERROR "macdeployqt is required to use build in macOS") + message(FATAL_ERROR "macdeployqt is required to build in macOS") else() message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}") endif() From a895729b9e75ea5b5353d80188c541f64bbcf5d9 Mon Sep 17 00:00:00 2001 From: Peter Nirschl Date: Sat, 21 Oct 2017 19:18:19 +0200 Subject: [PATCH 038/118] :bug: Fix result propagation in SymmetricCipherGcrypt::process The boolean 'ok' has always been set to true, regardless of possible errors. --- src/crypto/SymmetricCipherGcrypt.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crypto/SymmetricCipherGcrypt.cpp b/src/crypto/SymmetricCipherGcrypt.cpp index cd432406..e600a7ed 100644 --- a/src/crypto/SymmetricCipherGcrypt.cpp +++ b/src/crypto/SymmetricCipherGcrypt.cpp @@ -148,9 +148,10 @@ QByteArray SymmetricCipherGcrypt::process(const QByteArray& data, bool* ok) if (error != 0) { setErrorString(error); *ok = false; + } else { + *ok = true; } - *ok = true; return result; } From 76ac8dda547eadcc4091a7955a990f745af761ef Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 17:22:47 +0200 Subject: [PATCH 039/118] Fix missing semicolon --- share/linux/org.keepassxc.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/linux/org.keepassxc.desktop b/share/linux/org.keepassxc.desktop index fd94fdcd..d3b007bd 100644 --- a/share/linux/org.keepassxc.desktop +++ b/share/linux/org.keepassxc.desktop @@ -12,5 +12,5 @@ Icon=keepassxc Terminal=false Type=Application Version=1.0 -Categories=Utility;Security;Qt +Categories=Utility;Security;Qt; MimeType=application/x-keepass2; From 94ea91ec6321f0fc4fb6f1fa28149eff5b1cb08b Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 17:02:46 +0200 Subject: [PATCH 040/118] Switch from Ubuntu 14.04 to CentOS 7 --- AppImage-Recipe.sh | 5 ++- Dockerfile | 84 ++++++++++++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/AppImage-Recipe.sh b/AppImage-Recipe.sh index 2a40458f..a05a118e 100755 --- a/AppImage-Recipe.sh +++ b/AppImage-Recipe.sh @@ -34,6 +34,7 @@ fi APP="$1" LOWERAPP="$(echo "$APP" | tr '[:upper:]' '[:lower:]')" VERSION="$2" +export ARCH=x86_64 mkdir -p $APP.AppDir wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh @@ -42,6 +43,8 @@ wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./func LIB_DIR=./usr/lib if [ -d ./usr/lib/x86_64-linux-gnu ]; then LIB_DIR=./usr/lib/x86_64-linux-gnu +elif [ -d ./usr/lib64 ]; then + LIB_DIR=./usr/lib64 fi cd $APP.AppDir @@ -51,7 +54,7 @@ rm -R ./usr/local rmdir ./opt 2> /dev/null # bundle Qt platform plugins and themes -QXCB_PLUGIN="$(find /usr/lib -name 'libqxcb.so' 2> /dev/null)" +QXCB_PLUGIN="$(find /usr/lib* -name 'libqxcb.so' 2> /dev/null)" if [ "$QXCB_PLUGIN" == "" ]; then QXCB_PLUGIN="$(find /opt/qt*/plugins -name 'libqxcb.so' 2> /dev/null)" fi diff --git a/Dockerfile b/Dockerfile index 60ba4ff5..6f7ace34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,50 +14,68 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -FROM ubuntu:14.04 +FROM centos:7 RUN set -x \ - && apt-get update \ - && apt-get install --yes software-properties-common + && curl "https://copr.fedorainfracloud.org/coprs/bugzy/keepassxc/repo/epel-7/bugzy-keepassxc-epel-7.repo" \ + > /etc/yum.repos.d/bugzy-keepassxc-epel-7.repo RUN set -x \ - && add-apt-repository ppa:george-edison55/cmake-3.x - -ENV QT_PPA=qt591 -ENV QT_VERSION=qt59 + && curl "https://copr.fedorainfracloud.org/coprs/sic/backports/repo/epel-7/sic-backports-epel-7.repo" \ + > /etc/yum.repos.d/sic-backports-epel-7.repo RUN set -x \ - && add-apt-repository --yes ppa:beineri/opt-${QT_PPA}-trusty - + && yum clean -y all \ + && yum upgrade -y +# build and runtime dependencies RUN set -x \ - && apt-get update \ - && apt-get install --yes \ - g++ \ + && yum install -y \ + make \ + automake \ + gcc-c++ \ cmake \ - libgcrypt20-dev \ - ${QT_VERSION}base \ - ${QT_VERSION}tools \ - ${QT_VERSION}x11extras \ - libxi-dev \ - libxtst-dev \ - zlib1g-dev \ - libyubikey-dev \ - libykpers-1-dev \ - xvfb \ - wget \ - file \ - fuse \ - python + libgcrypt16-devel \ + qt5-qtbase-devel \ + qt5-linguist \ + qt5-qttools \ + zlib-devel \ + qt5-qtx11extras \ + qt5-qtx11extras-devel \ + libXi-devel \ + libXtst-devel +# AppImage dependencies RUN set -x \ - && apt-get install --yes mesa-common-dev - + && yum install -y \ + wget \ + fuse-libs + +# build libyubikey +ENV YUBIKEY_VERSION=1.13 +RUN set -x && yum install -y libusb-devel +RUN set -x \ + && wget "https://developers.yubico.com/yubico-c/Releases/libyubikey-${YUBIKEY_VERSION}.tar.gz" \ + && tar xf libyubikey-${YUBIKEY_VERSION}.tar.gz \ + && cd libyubikey-${YUBIKEY_VERSION} \ + && ./configure --prefix=/usr --libdir=/usr/lib64 \ + && make \ + && make install \ + && cd .. \ + && rm -Rf libyubikey-${YUBIKEY_VERSION}* + +# build libykpers-1 +ENV YKPERS_VERSION=1.18.0 +RUN set -x \ + && wget "https://developers.yubico.com/yubikey-personalization/Releases/ykpers-${YKPERS_VERSION}.tar.gz" \ + && tar xf ykpers-${YKPERS_VERSION}.tar.gz \ + && cd ykpers-${YKPERS_VERSION} \ + && ./configure --prefix=/usr --libdir=/usr/lib64 \ + && make \ + && make install \ + && cd .. \ + && rm -Rf ykpers-${YKPERS_VERSION}* + VOLUME /keepassxc/src VOLUME /keepassxc/out WORKDIR /keepassxc - -ENV CMAKE_PREFIX_PATH=/opt/${QT_VERSION}/lib/cmake -ENV LD_LIBRARY_PATH=/opt/${QT_VERSION}/lib -RUN set -x \ - && echo /opt/${QT_VERSION}/lib > /etc/ld.so.conf.d/${QT_VERSION}.conf From 51ed7a59da5f1331277ef6d799d534d5ab3029d4 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 20:24:39 +0200 Subject: [PATCH 041/118] Fix Exec replacement --- AppImage-Recipe.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AppImage-Recipe.sh b/AppImage-Recipe.sh index a05a118e..0e7d16af 100755 --- a/AppImage-Recipe.sh +++ b/AppImage-Recipe.sh @@ -74,7 +74,6 @@ get_desktop get_icon cat << EOF > ./usr/bin/keepassxc_env #!/usr/bin/env bash -#export QT_QPA_PLATFORMTHEME=gtk2 export LD_LIBRARY_PATH="..$(dirname ${QT_PLUGIN_PATH})/lib:\${LD_LIBRARY_PATH}" export QT_PLUGIN_PATH="..${QT_PLUGIN_PATH}:\${KPXC_QT_PLUGIN_PATH}" @@ -85,7 +84,7 @@ unset XDG_DATA_DIRS exec keepassxc "\$@" EOF chmod +x ./usr/bin/keepassxc_env -sed -i 's/Exec=keepassxc/Exec=keepassxc_env/' keepassxc.desktop +sed -i 's/Exec=keepassxc/Exec=keepassxc_env/' org.keepassxc.desktop get_desktopintegration $LOWERAPP GLIBC_NEEDED=$(glibc_needed) @@ -94,5 +93,5 @@ cd .. generate_type2_appimage -mv ../out/*.AppImage .. +mv ../out/*.AppImage ../KeePassXC-${VERSION}-${ARCH}.AppImage rmdir ../out > /dev/null 2>&1 From e2c6f5010830855ff1a4b49bfe60f455951218fd Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 20:32:41 +0200 Subject: [PATCH 042/118] Support starting keepassxc-cli via 'cli' argument --- AppImage-Recipe.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/AppImage-Recipe.sh b/AppImage-Recipe.sh index 0e7d16af..c421aa79 100755 --- a/AppImage-Recipe.sh +++ b/AppImage-Recipe.sh @@ -78,10 +78,15 @@ export LD_LIBRARY_PATH="..$(dirname ${QT_PLUGIN_PATH})/lib:\${LD_LIBRARY_PATH}" export QT_PLUGIN_PATH="..${QT_PLUGIN_PATH}:\${KPXC_QT_PLUGIN_PATH}" # unset XDG_DATA_DIRS to make tray icon work in Ubuntu Unity -# see https://github.com/probonopd/AppImageKit/issues/351 +# see https://github.com/AppImage/AppImageKit/issues/351 unset XDG_DATA_DIRS -exec keepassxc "\$@" +if [ "\${1}" == "cli" ]; then + shift + exec keepassxc-cli "\$@" +else + exec keepassxc "\$@" +fi EOF chmod +x ./usr/bin/keepassxc_env sed -i 's/Exec=keepassxc/Exec=keepassxc_env/' org.keepassxc.desktop From 067da8223dfcc700654eae22c1ddf9f902187e5d Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 21 Oct 2017 22:38:24 +0200 Subject: [PATCH 043/118] Fix build after merge --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd256511..3f0ba782 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,8 +68,8 @@ set(keepassx_SOURCES core/Uuid.cpp core/Base32.h core/Base32.cpp - cli/PasswordInput.cpp - cli/PasswordInput.h + cli/Utils.cpp + cli/Utils.h crypto/Crypto.cpp crypto/CryptoHash.cpp crypto/Random.cpp From 880a8da68a7a44ccc2730321a7a691afa8a55ee2 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sun, 22 Oct 2017 00:27:26 +0200 Subject: [PATCH 044/118] Bump version to 2.2.2 and update changelog --- CHANGELOG | 17 +++++++++++++++++ CMakeLists.txt | 2 +- share/linux/org.keepassxc.appdata.xml | 20 +++++++++++++++++++- snapcraft.yaml | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cc976c13..3719f8e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,20 @@ +2.2.2 (2017-10-22) +========================= + +- Fixed entries with empty URLs being reported to KeePassHTTP clients [#1031] +- Fixed YubiKey detection and enabled CLI tool for AppImage binary [#1100] +- Added AppStream description [#1082] +- Improved TOTP compatibility and added new Base32 implementation [#1069] +- Fixed error handling when processing invalid cipher stream [#1099] +- Fixed double warning display when opening a database [#1037] +- Fixed unlocking databases with --pw-stdin [#1087] +- Added ability to override QT_PLUGIN_PATH environment variable for AppImages [#1079] +- Fixed transform seed not being regenerated when saving the database [#1068] +- Fixed only one YubiKey slot being polled [#1048] +- Corrected an issue with entry icons while merging [#1008] +- Corrected desktop and tray icons in Snap package [#1030] +- Fixed screen lock and Google fallback settings [#1029] + 2.2.1 (2017-10-01) ========================= diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fddb457..63281f93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ set(CMAKE_AUTOUIC ON) set(KEEPASSXC_VERSION_MAJOR "2") set(KEEPASSXC_VERSION_MINOR "2") -set(KEEPASSXC_VERSION_PATCH "1") +set(KEEPASSXC_VERSION_PATCH "2") set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION_MAJOR}.${KEEPASSXC_VERSION_MINOR}.${KEEPASSXC_VERSION_PATCH}") # Distribution info diff --git a/share/linux/org.keepassxc.appdata.xml b/share/linux/org.keepassxc.appdata.xml index 3a5eb2c5..563450a4 100644 --- a/share/linux/org.keepassxc.appdata.xml +++ b/share/linux/org.keepassxc.appdata.xml @@ -67,7 +67,25 @@ - + + +
    +
  • Fixed entries with empty URLs being reported to KeePassHTTP clients [#1031]
  • +
  • Fixed YubiKey detection and enabled CLI tool for AppImage binary [#1100]
  • +
  • Added AppStream description [#1082]
  • +
  • Improved TOTP compatibility and added new Base32 implementation [#1069]
  • +
  • Fixed error handling when processing invalid cipher stream [#1099]
  • +
  • Fixed double warning display when opening a database [#1037]
  • +
  • Fixed unlocking databases with --pw-stdin [#1087]
  • +
  • Added ability to override QT_PLUGIN_PATH environment variable for AppImages [#1079]
  • +
  • Fixed transform seed not being regenerated when saving the database [#1068]
  • +
  • Fixed only one YubiKey slot being polled [#1048]
  • +
  • Corrected an issue with entry icons while merging [#1008]
  • +
  • Corrected desktop and tray icons in Snap package [#1030]
  • +
  • Fixed screen lock and Google fallback settings [#1029]
  • +
+
+