Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Diceware wordlists in numbered and/or PGP-signed formats #6791

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/man/keepassxc-cli.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ The same password generation options as documented for the generate command can
Sets the Path of the wordlist for the diceware generator.
The wordlist must have > 1000 words, otherwise the program will fail.
If the wordlist has < 4000 words a warning will be printed to STDERR.
Any *diceware*-compatible wordlist can used. Note however that *KeePassXC* will NOT verify the PGP signature of signed wordlists.

=== Export options
*-f*, *--format*::
Expand Down
24 changes: 22 additions & 2 deletions src/core/PassphraseGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,28 @@ void PassphraseGenerator::setWordList(const QString& path)
}

QTextStream in(&file);
while (!in.atEnd()) {
m_wordlist.append(in.readLine());
QString line = in.readLine();
bool isSigned = line.startsWith("-----BEGIN PGP SIGNED MESSAGE-----");
if (isSigned) {
while (!line.isNull() && !line.trimmed().isEmpty()) {
line = in.readLine();
}
}
QRegExp rx("^[0-9]+(-[0-9]+)*\\s+([^\\s]+)$");
while (!line.isNull()) {
if (isSigned && line.startsWith("-----BEGIN PGP SIGNATURE-----")) {
break;
}
// Handle dash-escaped lines (if the wordlist is signed)
if (isSigned && line.startsWith("- ")) {
line.remove(0, 2);
}
line = line.trimmed();
line.replace(rx, "\\2");
if (!line.isEmpty()) {
m_wordlist.append(line);
}
line = in.readLine();
}

if (m_wordlist.size() < 4000) {
Expand Down