diff --git a/docs/man/keepassxc-cli.1.adoc b/docs/man/keepassxc-cli.1.adoc index 3696f090f..1cee5ad68 100644 --- a/docs/man/keepassxc-cli.1.adoc +++ b/docs/man/keepassxc-cli.1.adoc @@ -256,6 +256,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*:: diff --git a/src/core/PassphraseGenerator.cpp b/src/core/PassphraseGenerator.cpp index 57dd2bb57..ef1d867e2 100644 --- a/src/core/PassphraseGenerator.cpp +++ b/src/core/PassphraseGenerator.cpp @@ -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) {