Snap: Improve Web-browser Native Messaging host functionality (#10906)

* Snap: Improve Web-browser Native Messaging host functionality

This commit allows for the snap distribution of KeepassXC to self-manage native messaging manifests
This is done by making the binary aware of the snapd environment changes that currently prevent this.
Furthermore, the snap sandbox is expanded to the bare minimum needed to access these privileged files.

Please note if running a self-compiled / untrusted KeepassXC snap build (I.E, installed with --dangerous)
that you must manually run `sudo snap connect keepassxc:browser-native-messaging` to grant permissions.

This will work on all distributions that expose `/snap/bin/` - such as Ubuntu, Debian, etc.
For systems which don't provide `/snap/`, such as Fedora, follow instructions for enabling "Classic" snaps.
e.g., `sudo ln -s /var/lib/snapd/snap /snap`

---------

Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
James Carroll 2024-06-19 20:49:30 +01:00 committed by Jonathan White
parent 48bf993ac5
commit ee08ef421d
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
4 changed files with 31 additions and 30 deletions

View file

@ -226,6 +226,16 @@ QString NativeMessageInstaller::getNativeMessagePath(SupportedBrowsers browser)
} else {
basePath = QDir::homePath() + "/.config";
}
#elif defined(KEEPASSXC_DIST_SNAP)
// Same as Flatpak above, with the exception that Snap also redefines $HOME
// Therefore we must explicitly reference $SNAP_REAL_HOME
if (browser == SupportedBrowsers::TOR_BROWSER) {
basePath = qEnvironmentVariable("SNAP_REAL_HOME") + "/.local/share";
} else if (browser == SupportedBrowsers::FIREFOX) {
basePath = qEnvironmentVariable("SNAP_REAL_HOME");
} else {
basePath = qEnvironmentVariable("SNAP_REAL_HOME") + "/.config";
}
#elif defined(Q_OS_LINUX) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
if (browser == SupportedBrowsers::TOR_BROWSER) {
basePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
@ -296,6 +306,8 @@ QString NativeMessageInstaller::getInstalledProxyPath() const
path = QProcessEnvironment::systemEnvironment().value("APPIMAGE");
#elif defined(KEEPASSXC_DIST_FLATPAK)
path = constructFlatpakPath();
#elif defined(KEEPASSXC_DIST_SNAP)
path = "/snap/bin/keepassxc.proxy";
#else
path = QCoreApplication::applicationDirPath() + QStringLiteral("/keepassxc-proxy");
#ifdef Q_OS_WIN