Skip to content

Commit

Permalink
Handle FileKey::load errors (--key-file) (keepassxreboot#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored Jul 29, 2017
1 parent ece6969 commit fe87748
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,24 +402,28 @@ Database* Database::openDatabaseFile(QString fileName, CompositeKey key)

Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilename)
{
CompositeKey compositeKey;

if (!keyFilename.isEmpty()) {
FileKey fileKey;
QString errorMessage;
if (!fileKey.load(keyFilename, &errorMessage)) {
qCritical("Failed to load key file %s : %s", qPrintable(keyFilename), qPrintable(errorMessage));
return nullptr;
}
compositeKey.addKey(fileKey);
}

QTextStream outputTextStream(stdout);

outputTextStream << QString("Insert password to unlock " + databaseFilename + "\n> ");
outputTextStream.flush();

CompositeKey compositeKey;

QString line = Utils::getPassword();
PasswordKey passwordKey;
passwordKey.setPassword(line);
compositeKey.addKey(passwordKey);

if (!keyFilename.isEmpty()) {
FileKey fileKey;
fileKey.load(keyFilename);
compositeKey.addKey(fileKey);
}

return Database::openDatabaseFile(databaseFilename, compositeKey);
}

Expand Down

0 comments on commit fe87748

Please sign in to comment.