Skip to content

Commit

Permalink
Add warning message to browser integration settings when keepassxc-pr…
Browse files Browse the repository at this point in the history
…oxy is not found
  • Loading branch information
varjolintu committed Oct 19, 2018
1 parent 8074995 commit 0cf4a21
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/browser/BrowserOptionDialog.cpp
Expand Up @@ -39,6 +39,13 @@ BrowserOptionDialog::BrowserOptionDialog(QWidget* parent)
"<a href=\"https://addons.mozilla.org/en-US/firefox/addon/keepassxc-browser/\">Firefox</a>",
"<a href=\"https://chrome.google.com/webstore/detail/keepassxc-browser/oboonakemofpalcgghocfoadofidjkkk\">Google Chrome / Chromium / Vivaldi</a>"));

m_ui->scriptWarningWidget->setVisible(false);
m_ui->scriptWarningWidget->setAutoHideTimeout(-1);
m_ui->scriptWarningWidget->showMessage(tr("<b>Warning</b>, the keepassxc-proxy application was not found!"
"<br />Please check the KeePassXC installation directory or confirm the custom path in advanced options."
"<br />Browser integration WILL NOT WORK without the proxy application."
"<br />Expected Path: "), MessageWidget::Warning);

m_ui->warningWidget->showMessage(tr("<b>Warning:</b> The following options can be dangerous!"), MessageWidget::Warning);
m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(-1);
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions src/browser/BrowserOptionDialog.ui
Expand Up @@ -49,6 +49,16 @@
<string>General</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="MessageWidget" name="scriptWarningWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="extensionLabel">
</widget>
Expand Down
5 changes: 5 additions & 0 deletions src/browser/BrowserSettings.cpp
Expand Up @@ -495,3 +495,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);
}
1 change: 1 addition & 0 deletions src/browser/BrowserSettings.h
Expand Up @@ -114,6 +114,7 @@ class BrowserSettings
QString generatePassword();
int getbits();
void updateBinaryPaths(QString customProxyLocation = QString());
bool checkIfProxyExists(QString& path);

private:
static BrowserSettings* m_instance;
Expand Down
96 changes: 95 additions & 1 deletion src/browser/HostInstaller.cpp
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/browser/HostInstaller.h
Expand Up @@ -39,6 +39,7 @@ class HostInstaller : public QObject
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,
Expand All @@ -50,6 +51,7 @@ class HostInstaller : public QObject
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);
Expand Down

0 comments on commit 0cf4a21

Please sign in to comment.