Skip to content

Commit

Permalink
Handle retrieving credentials from HTTP Basic Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Dec 10, 2018
1 parent b6eeaba commit f9c244d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/browser/BrowserAccessControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ bool BrowserAccessControlDialog::remember() const
void BrowserAccessControlDialog::setRemember(bool r)
{
m_ui->rememberDecisionCheckBox->setChecked(r);
}
}
4 changes: 3 additions & 1 deletion src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ QJsonObject BrowserAction::handleGetLogins(const QJsonObject& json, const QStrin

const QString id = decrypted.value("id").toString();
const QString submit = decrypted.value("submitUrl").toString();
const QJsonArray users = m_browserService.findMatchingEntries(id, url, submit, "", keyList);
const QString auth = decrypted.value("httpAuth").toString();
const bool httpAuth = auth.compare("true", Qt::CaseSensitive) == 0 ? true : false;
const QJsonArray users = m_browserService.findMatchingEntries(id, url, submit, "", keyList, httpAuth);

if (users.isEmpty()) {
return getErrorReply(action, ERROR_KEEPASS_NO_LOGINS_FOUND);
Expand Down
22 changes: 17 additions & 5 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
const QString& url,
const QString& submitUrl,
const QString& realm,
const StringPairList& keyList)
const StringPairList& keyList,
const bool httpAuth)
{
QJsonArray result;
if (thread() != QThread::currentThread()) {
Expand All @@ -219,7 +220,8 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
Q_ARG(QString, url),
Q_ARG(QString, submitUrl),
Q_ARG(QString, realm),
Q_ARG(StringPairList, keyList));
Q_ARG(StringPairList, keyList),
Q_ARG(bool, httpAuth));
return result;
}

Expand All @@ -231,6 +233,12 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
QList<Entry*> pwEntriesToConfirm;
QList<Entry*> pwEntries;
for (Entry* entry : searchEntries(url, keyList)) {
// HTTP Basic Auth always needs a confirmation
if (httpAuth) {
pwEntriesToConfirm.append(entry);
continue;
}

switch (checkAccess(entry, host, submitHost, realm)) {
case Denied:
continue;
Expand All @@ -250,7 +258,7 @@ QJsonArray BrowserService::findMatchingEntries(const QString& id,
}

// Confirm entries
if (confirmEntries(pwEntriesToConfirm, url, host, submitHost, realm)) {
if (confirmEntries(pwEntriesToConfirm, url, host, submitHost, realm, httpAuth)) {
pwEntries.append(pwEntriesToConfirm);
}

Expand Down Expand Up @@ -573,7 +581,8 @@ bool BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm,
const QString& url,
const QString& host,
const QString& submitHost,
const QString& realm)
const QString& realm,
const bool httpAuth)
{
if (pwEntriesToConfirm.isEmpty() || m_dialogActive) {
return false;
Expand Down Expand Up @@ -642,7 +651,10 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
}

BrowserService::Access
BrowserService::checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm)
BrowserService::checkAccess(const Entry* entry,
const QString& host,
const QString& submitHost,
const QString& realm)
{
BrowserEntryConfig config;
if (!config.load(entry)) {
Expand Down
11 changes: 8 additions & 3 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public slots:
const QString& url,
const QString& submitUrl,
const QString& realm,
const StringPairList& keyList);
const StringPairList& keyList,
const bool httpAuth = false);
QString storeKey(const QString& key);
void updateEntry(const QString& id,
const QString& uuid,
Expand Down Expand Up @@ -99,9 +100,13 @@ public slots:
const QString& url,
const QString& host,
const QString& submitHost,
const QString& realm);
const QString& realm,
const bool httpAuth);
QJsonObject prepareEntry(const Entry* entry);
Access checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm);
Access checkAccess(const Entry* entry,
const QString& host,
const QString& submitHost,
const QString& realm);
Group* findCreateAddEntryGroup(QSharedPointer<Database> selectedDb = {});
int
sortPriority(const Entry* entry, const QString& host, const QString& submitUrl, const QString& baseSubmitUrl) const;
Expand Down

0 comments on commit f9c244d

Please sign in to comment.