diff --git a/snapcraft.yaml b/snapcraft.yaml index f7bc1434..417efac1 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -34,6 +34,7 @@ parts: - -DKEEPASSXC_BUILD_TYPE=PreRelease - -DWITH_TESTS=OFF - -DWITH_XC_ALL=ON + - -DWITH_XC_KEESHARE_SECURE=ON build-packages: - g++ - libgcrypt20-dev @@ -50,6 +51,7 @@ parts: - libsodium-dev - libargon2-0-dev - libqrencode-dev + - libquazip5-dev stage-packages: - dbus - qttranslations5-l10n # common translations @@ -60,6 +62,9 @@ parts: - libxtst6 - libqt5x11extras5 - libqt5svg5 + - libqrencode3 + - libqt5concurrent5 + - libquazip5-1 - libusb-1.0-0 - qtwayland5 override-build: | @@ -71,3 +76,24 @@ parts: - -opt after: [desktop-qt5] + desktop-qt5: + source: https://github.com/ubuntu/snapcraft-desktop-helpers.git + source-subdir: qt + plugin: make + make-parameters: ["FLAVOR=qt5"] + build-packages: + - qtbase5-dev + - dpkg-dev + stage-packages: + - libxkbcommon0 + - ttf-ubuntu-font-family + - dmz-cursor-theme + - light-themes + - adwaita-icon-theme + - gnome-themes-standard + - shared-mime-info + - libqt5gui5 + - libgdk-pixbuf2.0-0 + - libqt5svg5 # for loading icon themes which are svg + - try: [appmenu-qt5] # not available on core18 + - locales-all \ No newline at end of file diff --git a/src/browser/BrowserOptionDialog.cpp b/src/browser/BrowserOptionDialog.cpp index 78a51d2a..90da8cde 100644 --- a/src/browser/BrowserOptionDialog.cpp +++ b/src/browser/BrowserOptionDialog.cpp @@ -32,13 +32,24 @@ BrowserOptionDialog::BrowserOptionDialog(QWidget* parent) { m_ui->setupUi(this); + // clang-format off + QString snapInstructions; +#if defined(KEEPASSXC_DIST_SNAP) + snapInstructions = "

" + + tr("Due to Snap sandboxing, you must run a script to enable browser integration." + "
" + "You can obtain this script from %1") + .arg("https://keepassxc.org"); +#endif + m_ui->extensionLabel->setOpenExternalLinks(true); m_ui->extensionLabel->setText( - tr("KeePassXC-Browser is needed for the browser integration to work.
Download it for %1 and %2.") + tr("KeePassXC-Browser is needed for the browser integration to work.
Download it for %1 and %2.%3") .arg("Firefox", - "Google Chrome / Chromium / Vivaldi")); + "" + "Google Chrome / Chromium / Vivaldi", + snapInstructions)); + // clang-format on m_ui->scriptWarningWidget->setVisible(false); m_ui->scriptWarningWidget->setAutoHideTimeout(-1); @@ -119,10 +130,18 @@ void BrowserOptionDialog::loadSettings() m_ui->supportBrowserProxy->setChecked(true); m_ui->supportBrowserProxy->setEnabled(false); #elif defined(KEEPASSXC_DIST_SNAP) - m_ui->enableBrowserSupport->setChecked(false); - m_ui->enableBrowserSupport->setEnabled(false); + // Disable settings that will not work + m_ui->supportBrowserProxy->setChecked(true); + m_ui->supportBrowserProxy->setEnabled(false); + m_ui->useCustomProxy->setChecked(false); + m_ui->useCustomProxy->setEnabled(false); + m_ui->browsersGroupBox->setVisible(false); + m_ui->browsersGroupBox->setEnabled(false); + m_ui->updateBinaryPath->setChecked(false); + m_ui->updateBinaryPath->setEnabled(false); + // Show notice to user m_ui->browserGlobalWarningWidget->showMessage( - tr("We're sorry, but KeePassXC-Browser is not supported for Snap releases at the moment."), + tr("Please see special instructions for browser extension use below"), MessageWidget::Warning); m_ui->browserGlobalWarningWidget->setCloseButtonVisible(false); m_ui->browserGlobalWarningWidget->setAutoHideTimeout(-1); diff --git a/src/browser/NativeMessagingBase.cpp b/src/browser/NativeMessagingBase.cpp index 11ba3784..a6b8d97c 100644 --- a/src/browser/NativeMessagingBase.cpp +++ b/src/browser/NativeMessagingBase.cpp @@ -137,7 +137,9 @@ void NativeMessagingBase::sendReply(const QString& reply) QString NativeMessagingBase::getLocalServerPath() const { const QString serverPath = "/kpxc_server"; -#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) +#if defined(KEEPASSXC_DIST_SNAP) + return QProcessEnvironment::systemEnvironment().value("SNAP_COMMON") + serverPath; +#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) // Use XDG_RUNTIME_DIR instead of /tmp if it's available QString path = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); return path.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverPath diff --git a/utils/keepassxc-snap-helper.sh b/utils/keepassxc-snap-helper.sh new file mode 100755 index 00000000..4b2ce94d --- /dev/null +++ b/utils/keepassxc-snap-helper.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# +# KeePassXC Browser Extension Native Messaging Installer Tool +# 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 . + +set -e + +DEBUG=false + +JSON_BASE=$(cat << EOF +{ + "name": "org.keepassxc.keepassxc_browser", + "description": "KeePassXC integration with native messaging support", + "path": "/snap/bin/keepassxc.proxy", + "type": "stdio", + __EXT__ +} +EOF +) + +JSON_FIREFOX=$(cat << EOF +"allowed_extensions": [ + "keepassxc-browser@keepassxc.org" + ] +EOF +) + +JSON_CHROME=$(cat << EOF +"allowed_origins": [ + "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", + "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/" + ] +EOF +) + +JSON_OUT="" +BASE_DIR="." +INSTALL_DIR="" +INSTALL_FILE="org.keepassxc.keepassxc_browser.json" + +buildJson() { + if [[ ! -z $1 ]]; then + # Insert Firefox data + JSON_OUT="${JSON_BASE/__EXT__/$JSON_FIREFOX}" + else + # Insert Chrome data + JSON_OUT="${JSON_BASE/__EXT__/$JSON_CHROME}" + fi +} + +askBrowserSnap() { + if (whiptail --title "Snap Choice" --defaultno \ + --yesno "Is this browser installed as a snap (usually NO)?" 8 60); then + # BASE_DIR="$1" + whiptail --title "Snap Choice" --msgbox "Sorry, browsers installed as snaps are not supported at this time" 8 50 + exit 0 + fi +} + +setupFirefox() { + askBrowserSnap "./snap/firefox/common" + buildJson "firefox" + INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts" +} + +setupChrome() { + buildJson + INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts" +} + +setupChromium() { + askBrowserSnap "./snap/chromium/current" + buildJson + INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts" +} + +setupVivaldi() { + buildJson + INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts" +} + +setupTorBrowser() { + buildJson "firefox" + INSTALL_DIR="${BASE_DIR}/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts" +} + +# -------------------------------- +# Start of script +# -------------------------------- + +BROWSER=$(whiptail \ + --title "Browser Selection" \ + --menu "Choose a browser to integrate with KeePassXC:" \ + 15 60 5 \ + "1" "Firefox" \ + "2" "Chrome" \ + "3" "Chromium" \ + "4" "Vivaldi" \ + "5" "Tor Browser" \ + 3>&1 1>&2 2>&3) + +clear + +exitstatus=$? +if [ $exitstatus = 0 ]; then + # Configure settings for the chosen browser + case "$BROWSER" in + 1) setupFirefox ;; + 2) setupChrome ;; + 3) setupChromium ;; + 4) setupVivaldi ;; + 5) setupTorBrowser ;; + esac + + # Install the JSON file + cd ~ + mkdir -p "$INSTALL_DIR" + echo "$JSON_OUT" > ${INSTALL_DIR}/${INSTALL_FILE} + + $DEBUG && echo "Installed to: ${INSTALL_DIR}/${INSTALL_FILE}" + + whiptail \ + --title "Installation Complete" \ + --msgbox "You will need to restart your browser in order to connect to KeePassXC" \ + 8 50 +else + whiptail --title "Installation Canceled" --msgbox "No changes were made to your system" 8 50 +fi +