Skip to content

Commit

Permalink
Support key files with Auto Open feature
Browse files Browse the repository at this point in the history
Fixes #3495

* Look for keyfile in username parameter of the Auto Open entries. If present, pass on to unlock call to the database.
  • Loading branch information
metaphys authored and droidmonkey committed Sep 6, 2019
1 parent 0a3b19e commit 83831bb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
12 changes: 12 additions & 0 deletions docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@ There is a simple overview of shared groups to keep track of your data.
Sharing relies on the combination of file exports and imports as well as the synchronization mechanism provided by KeePassXC. Since the merge algorithm uses the history of entries to prevent data loss, this history must be enabled and have a sufficient size. Furthermore, the merge algorithm is location independend, therefore it does not matter if entries are moved outside of an import group. These entries will be updated none the less. Moving entries outside of export groups will prevent a further export of the entry, but it will not ensure that the already shared data will be removed from any client.

KeeShare uses a custom certification mechanism to ensure that the source of the data is the expected one. This ensures that the data was exported by the signer but it is not possible to detect if someone replaced the data with an older version from a valid signer. To prevent this, the container could be placed at a location which is only writeable for valid signers.

## Using Auto Open

The Auto Open feature automatically loads and unlocks additional databases when you unlock your main database.
In order to use this functionnality, do the following:

1. Create a group called **AutoOpen** at the root of your main database.
1. In this group, create a new entry for each database that should be opened automatically:
* Put the *password of the database* in the **Password** field
* Put the *path to the database's file* in the **URL** field* (it can be formatted either as **file://**, a **/path/to/the/file** form, or a relative file path.)
* If the extra database requires a keyfile to be unlocked, put the *path to the keyfile* in the **Username** field. The path options are the same as for the database's file in the URL field.
1. The next time you unlock your database these databases will be opened and unlocked automatically.
5 changes: 3 additions & 2 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ void DatabaseTabWidget::addDatabaseTab(DatabaseWidget* dbWidget, bool inBackgrou
}

connect(dbWidget, SIGNAL(databaseFilePathChanged(QString, QString)), SLOT(updateTabName()));
connect(
dbWidget, SIGNAL(requestOpenDatabase(QString, bool, QString)), SLOT(addDatabaseTab(QString, bool, QString)));
connect(dbWidget,
SIGNAL(requestOpenDatabase(QString, bool, QString, QString)),
SLOT(addDatabaseTab(QString, bool, QString, QString)));
connect(dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabaseTabFromSender()));
connect(dbWidget, SIGNAL(databaseModified()), SLOT(updateTabName()));
connect(dbWidget, SIGNAL(databaseSaved()), SLOT(updateTabName()));
Expand Down
25 changes: 19 additions & 6 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,8 @@ void DatabaseWidget::unlockDatabase(bool accepted)
}
replaceDatabase(db);
if (db->isReadOnly()) {
showMessage(tr("This database is opened in read-only mode. Autosave is disabled."),
MessageWidget::Warning,
false,
-1);
showMessage(
tr("This database is opened in read-only mode. Autosave is disabled."), MessageWidget::Warning, false, -1);
}

restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock);
Expand Down Expand Up @@ -1740,6 +1738,8 @@ void DatabaseWidget::processAutoOpen()
continue;
}
QFileInfo filepath;
QFileInfo keyfile;

if (entry->url().startsWith("file://")) {
QUrl url(entry->url());
filepath.setFile(url.toLocalFile());
Expand All @@ -1755,7 +1755,20 @@ void DatabaseWidget::processAutoOpen()
continue;
}

// Request to open the database file in the background
emit requestOpenDatabase(filepath.canonicalFilePath(), true, entry->password());
if (!entry->username().isEmpty()) {
if (entry->username().startsWith("file://")) {
QUrl keyfileUrl(entry->username());
keyfile.setFile(keyfileUrl.toLocalFile());
} else {
keyfile.setFile(entry->username());
if (keyfile.isRelative()) {
QFileInfo currentpath(m_db->filePath());
keyfile.setFile(currentpath.absoluteDir(), entry->username());
}
}
}

// Request to open the database file in the background with a password and keyfile
emit requestOpenDatabase(filepath.canonicalFilePath(), true, entry->password(), keyfile.canonicalFilePath());
}
}
3 changes: 2 additions & 1 deletion src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class DatabaseWidget : public QStackedWidget
void currentModeChanged(DatabaseWidget::Mode mode);
void groupChanged();
void entrySelectionChanged();
void requestOpenDatabase(const QString& filePath, bool inBackground, const QString& password);
void
requestOpenDatabase(const QString& filePath, bool inBackground, const QString& password, const QString& keyFile);
void databaseMerged(QSharedPointer<Database> mergedDb);
void groupContextMenuRequested(const QPoint& globalPos);
void entryContextMenuRequested(const QPoint& globalPos);
Expand Down

0 comments on commit 83831bb

Please sign in to comment.