Skip to content

Commit

Permalink
Improved error messages when opening database
Browse files Browse the repository at this point in the history
* Reduced wording and confusion
* Streamlined delivery format
* Fix #813
  • Loading branch information
droidmonkey committed Apr 7, 2019
1 parent 791b796 commit 0201fcd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/format/Kdbx3Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ bool Kdbx3Reader::readDatabaseImpl(QIODevice* device,
QByteArray realStart = cipherStream.read(32);

if (realStart != m_streamStartBytes) {
raiseError(tr("Wrong key or database file is corrupt."));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt."));
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/format/Kdbx4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ bool Kdbx4Reader::readDatabaseImpl(QIODevice* device,
// clang-format off
QByteArray hmacKey = KeePass2::hmacKey(m_masterSeed, db->transformedMasterKey());
if (headerHmac != CryptoHash::hmac(headerData, HmacBlockStream::getHmacKey(UINT64_MAX, hmacKey), CryptoHash::Sha256)) {
raiseError(tr("Wrong key or database file is corrupt. (HMAC mismatch)"));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt.") + " " + tr("(HMAC mismatch)"));
return false;
}
HmacBlockStream hmacStream(device, hmacKey);
Expand Down
3 changes: 2 additions & 1 deletion src/format/KeePass1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ KeePass1Reader::testKeys(const QString& password, const QByteArray& keyfileData,
}

if (!cipherStream) {
raiseError(tr("Wrong key or database file is corrupt."));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt."));
}

return cipherStream.take();
Expand Down
7 changes: 3 additions & 4 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ void DatabaseOpenWidget::openDatabase()
bool ok = m_db->open(m_filename, masterKey, &error, false);
QApplication::restoreOverrideCursor();
if (!ok) {
m_ui->messageWidget->showMessage(tr("Unable to open the database:\n%1").arg(error),
MessageWidget::MessageType::Error);
m_ui->messageWidget->showMessage(error, MessageWidget::MessageType::Error);
return;
}

Expand Down Expand Up @@ -223,7 +222,7 @@ void DatabaseOpenWidget::openDatabase()
}
emit dialogFinished(true);
} else {
m_ui->messageWidget->showMessage(tr("Unable to open the database:\n%1").arg(error), MessageWidget::Error);
m_ui->messageWidget->showMessage(error, MessageWidget::Error);
m_ui->editPassword->setText("");

#ifdef WITH_XC_TOUCHID
Expand Down Expand Up @@ -268,7 +267,7 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::databaseKey()
QString keyFilename = m_ui->comboKeyFile->currentText();
QString errorMsg;
if (!key->load(keyFilename, &errorMsg)) {
m_ui->messageWidget->showMessage(tr("Can't open key file:\n%1").arg(errorMsg), MessageWidget::Error);
m_ui->messageWidget->showMessage(tr("Failed to open key file: %1").arg(errorMsg), MessageWidget::Error);
return {};
}
if (key->type() != FileKey::Hashed && !config()->get("Messages/NoLegacyKeyFileWarning").toBool()) {
Expand Down
6 changes: 2 additions & 4 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,7 @@ void TestCli::testKeyFileOption()
m_stdoutFile->readLine(); // skip password prompt
m_stderrFile->seek(posErr);
QCOMPARE(m_stdoutFile->readAll(), QByteArray(""));
QCOMPARE(m_stderrFile->readAll(),
QByteArray("Error while reading the database: Wrong key or database file is corrupt. (HMAC mismatch)\n"));
QVERIFY(m_stderrFile->readAll().contains("Invalid credentials were provided"));

// Should raise an error if key file path is invalid.
pos = m_stdoutFile->pos();
Expand Down Expand Up @@ -736,8 +735,7 @@ void TestCli::testNoPasswordOption()
m_stdoutFile->readLine(); // skip password prompt
m_stderrFile->seek(posErr);
QCOMPARE(m_stdoutFile->readAll(), QByteArray(""));
QCOMPARE(m_stderrFile->readAll(),
QByteArray("Error while reading the database: Wrong key or database file is corrupt. (HMAC mismatch)\n"));
QVERIFY(m_stderrFile->readAll().contains("Invalid credentials were provided"));
}

void TestCli::testList()
Expand Down

0 comments on commit 0201fcd

Please sign in to comment.