diff --git a/src/browser/BrowserOptionDialog.cpp b/src/browser/BrowserOptionDialog.cpp
index e2ed8420b..a52f53e10 100644
--- a/src/browser/BrowserOptionDialog.cpp
+++ b/src/browser/BrowserOptionDialog.cpp
@@ -39,6 +39,13 @@ BrowserOptionDialog::BrowserOptionDialog(QWidget* parent)
"Firefox",
"Google Chrome / Chromium / Vivaldi"));
+ m_ui->scriptWarningWidget->setVisible(false);
+ m_ui->scriptWarningWidget->setAutoHideTimeout(-1);
+ m_ui->scriptWarningWidget->showMessage(tr("Warning, the keepassxc-proxy application was not found!"
+ "
Please check the KeePassXC installation directory or confirm the custom path in advanced options."
+ "
Browser integration WILL NOT WORK without the proxy application."
+ "
Expected Path: "), MessageWidget::Warning);
+
m_ui->warningWidget->showMessage(tr("Warning: The following options can be dangerous!"), MessageWidget::Warning);
m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(-1);
@@ -109,6 +116,17 @@ void BrowserOptionDialog::loadSettings()
m_ui->browserGlobalWarningWidget->setCloseButtonVisible(false);
m_ui->browserGlobalWarningWidget->setAutoHideTimeout(-1);
#endif
+
+ // Check for native messaging host location errors
+ QString path;
+ if (!settings->checkIfProxyExists(path)) {
+ QString text = m_ui->scriptWarningWidget->text();
+ text.append(path);
+ m_ui->scriptWarningWidget->setText(text);
+ m_ui->scriptWarningWidget->setVisible(true);
+ } else {
+ m_ui->scriptWarningWidget->setVisible(false);
+ }
}
void BrowserOptionDialog::saveSettings()
diff --git a/src/browser/BrowserOptionDialog.ui b/src/browser/BrowserOptionDialog.ui
index 24589c147..fa5cda367 100755
--- a/src/browser/BrowserOptionDialog.ui
+++ b/src/browser/BrowserOptionDialog.ui
@@ -49,6 +49,16 @@
General
+ -
+
+
+
+ 0
+ 0
+
+
+
+
-
diff --git a/src/browser/BrowserSettings.cpp b/src/browser/BrowserSettings.cpp
index 96d8f98d7..dc92f5dc8 100644
--- a/src/browser/BrowserSettings.cpp
+++ b/src/browser/BrowserSettings.cpp
@@ -490,3 +490,8 @@ void BrowserSettings::updateBinaryPaths(QString customProxyLocation)
bool isProxy = supportBrowserProxy();
m_hostInstaller.updateBinaryPaths(isProxy, customProxyLocation);
}
+
+bool BrowserSettings::checkIfProxyExists(QString& path)
+{
+ return m_hostInstaller.checkIfProxyExists(supportBrowserProxy(), customProxyLocation(), path);
+}
diff --git a/src/browser/BrowserSettings.h b/src/browser/BrowserSettings.h
index 5dc28593a..e501a1201 100644
--- a/src/browser/BrowserSettings.h
+++ b/src/browser/BrowserSettings.h
@@ -113,6 +113,7 @@ public:
PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
QString generatePassword();
void updateBinaryPaths(QString customProxyLocation = QString());
+ bool checkIfProxyExists(QString& path);
private:
static BrowserSettings* m_instance;
diff --git a/src/browser/HostInstaller.cpp b/src/browser/HostInstaller.cpp
index 99d09f4f7..a2f4c74b8 100644
--- a/src/browser/HostInstaller.cpp
+++ b/src/browser/HostInstaller.cpp
@@ -52,6 +52,12 @@ HostInstaller::HostInstaller()
{
}
+/**
+ * Checks if the selected browser has native messaging host properly installed
+ *
+ * @param browser Selected browser
+ * @return bool Script is installed correctly
+ */
bool HostInstaller::checkIfInstalled(SupportedBrowsers browser)
{
QString fileName = getPath(browser);
@@ -63,6 +69,29 @@ bool HostInstaller::checkIfInstalled(SupportedBrowsers browser)
#endif
}
+/**
+ * Checks if keepassxc-proxy location is found
+ *
+ * @param proxy Is keepassxc-proxy enabled
+ * @param location Custom proxy location
+ * @param path The path is set here and returned to the caller
+ * @return bool
+ */
+bool HostInstaller::checkIfProxyExists(const bool& proxy, const QString& location, QString& path) const
+{
+ QString fileName = getProxyPath(proxy, location);
+ path = fileName;
+ return QFile::exists(fileName);
+}
+
+/**
+ * Installs native messaging JSON script for the selected browser
+ *
+ * @param browser Selected browser
+ * @param enabled Is browser integration enabled
+ * @param proxy Is keepassxc-proxy enabled
+ * @param location Custom proxy location
+ */
void HostInstaller::installBrowser(SupportedBrowsers browser,
const bool& enabled,
const bool& proxy,
@@ -98,6 +127,12 @@ void HostInstaller::installBrowser(SupportedBrowsers browser,
}
}
+/**
+ * Updates the paths to native messaging host for each browser that has been enabled
+ *
+ * @param proxy Is keepassxc-proxy enabled
+ * @param location Custom proxy location
+ */
void HostInstaller::updateBinaryPaths(const bool& proxy, const QString& location)
{
for (int i = 0; i < 4; ++i) {
@@ -107,6 +142,12 @@ void HostInstaller::updateBinaryPaths(const bool& proxy, const QString& location
}
}
+/**
+ * Returns the target path for each browser. Windows uses a registry path instead of a file path
+ *
+ * @param browser Selected browser
+ * @return QString Current target path for the selected browser
+ */
QString HostInstaller::getTargetPath(SupportedBrowsers browser) const
{
switch (browser) {
@@ -123,6 +164,13 @@ QString HostInstaller::getTargetPath(SupportedBrowsers browser) const
}
}
+/**
+ * Returns the browser name
+ * Needed for Windows to separate Chromium- or Firefox-based scripts
+ *
+ * @param browser Selected browser
+ * @return QString Name of the selected browser
+ */
QString HostInstaller::getBrowserName(SupportedBrowsers browser) const
{
switch (browser) {
@@ -139,6 +187,12 @@ QString HostInstaller::getBrowserName(SupportedBrowsers browser) const
}
}
+/**
+ * Returns the path of native messaging JSON script for the selected browser
+ *
+ * @param browser Selected browser
+ * @return QString JSON script path for the selected browser
+ */
QString HostInstaller::getPath(SupportedBrowsers browser) const
{
#ifdef Q_OS_WIN
@@ -160,6 +214,12 @@ QString HostInstaller::getPath(SupportedBrowsers browser) const
#endif
}
+/**
+ * Gets the installation directory for JSON script file (application install path)
+ *
+ * @param browser Selected browser
+ * @return QString Install path
+ */
QString HostInstaller::getInstallDir(SupportedBrowsers browser) const
{
QString path = getTargetPath(browser);
@@ -170,7 +230,14 @@ QString HostInstaller::getInstallDir(SupportedBrowsers browser) const
#endif
}
-QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool& proxy, const QString& location)
+/**
+ * Gets the path to keepassxc-proxy binary
+ *
+ * @param proxy Is keepassxc-proxy used with KeePassXC
+ * @param location Custom proxy path
+ * @return path Path to keepassxc-proxy
+ */
+QString HostInstaller::getProxyPath(const bool& proxy, const QString& location) const
{
QString path;
#ifdef KEEPASSXC_DIST_APPIMAGE
@@ -198,6 +265,20 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&
#endif
#endif // #ifdef KEEPASSXC_DIST_APPIMAGE
+ return path;
+}
+
+/**
+ * Constructs the JSON script file used with native messaging
+ *
+ * @param browser Browser (Chromium- and Firefox-based browsers need a different parameters for the script)
+ * @param proxy Is keepassxc-proxy used with KeePassXC
+ * @param location Custom proxy location
+ * @return script The JSON script file
+ */
+QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool& proxy, const QString& location)
+{
+ QString path = getProxyPath(proxy, location);
QJsonObject script;
script["name"] = HOST_NAME;
@@ -221,11 +302,24 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&
return script;
}
+/**
+ * Checks if a registry setting is found with default value
+ *
+ * @param settings Registry path
+ * @return bool Is the registry value found
+ */
bool HostInstaller::registryEntryFound(const QSettings& settings)
{
return !settings.value("Default").isNull();
}
+/**
+ * Saves a JSON script file
+ *
+ * @param browser Selected browser
+ * @param script JSON native messaging script object
+ * @return bool Write succeeds
+ */
bool HostInstaller::saveFile(SupportedBrowsers browser, const QJsonObject& script)
{
QString path = getPath(browser);
diff --git a/src/browser/HostInstaller.h b/src/browser/HostInstaller.h
index 3b985c300..204c3d982 100644
--- a/src/browser/HostInstaller.h
+++ b/src/browser/HostInstaller.h
@@ -39,6 +39,7 @@ public:
public:
HostInstaller();
bool checkIfInstalled(SupportedBrowsers browser);
+ bool checkIfProxyExists(const bool& proxy, const QString& location, QString& path) const;
void installBrowser(SupportedBrowsers browser,
const bool& enabled,
const bool& proxy = false,
@@ -50,6 +51,7 @@ private:
QString getBrowserName(SupportedBrowsers browser) const;
QString getPath(SupportedBrowsers browser) const;
QString getInstallDir(SupportedBrowsers browser) const;
+ QString getProxyPath(const bool& proxy, const QString& location) const;
QJsonObject constructFile(SupportedBrowsers browser, const bool& proxy, const QString& location);
bool registryEntryFound(const QSettings& settings);
bool saveFile(SupportedBrowsers browser, const QJsonObject& script);