Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2020-09-27 16:00:59 +0300
committerJonathan White <support@dmapps.us>2020-09-27 22:23:03 +0300
commit7426693f1d706fa21755235351bea31b4c2e616f (patch)
tree155a149699395e9d8cc44b55a5b7a222f2bf4563 /src/cli
parente1c2537084651c4cfeb466b28f5bcd71d05dc4ff (diff)
CLI: Add support for okon in offline HIBP checks
* Closes #5447 * Add option `--okon <okon-cli path>` to trigger the use of the okon cli tool to process a database's entries. When using this option the `-H, --hibp` option must point to a post-processed okon file instead of the standard HIBP text file. * Updated documentation
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/Analyze.cpp48
-rw-r--r--src/cli/Analyze.h1
2 files changed, 38 insertions, 11 deletions
diff --git a/src/cli/Analyze.cpp b/src/cli/Analyze.cpp
index 64eac9e70..11bb824ed 100644
--- a/src/cli/Analyze.cpp
+++ b/src/cli/Analyze.cpp
@@ -34,11 +34,17 @@ const QCommandLineOption Analyze::HIBPDatabaseOption = QCommandLineOption(
"https://haveibeenpwned.com/Passwords."),
QObject::tr("FILENAME"));
+const QCommandLineOption Analyze::OkonOption =
+ QCommandLineOption("okon",
+ QObject::tr("Path to okon-cli to search a formatted HIBP file"),
+ QObject::tr("okon-cli"));
+
Analyze::Analyze()
{
name = QString("analyze");
description = QObject::tr("Analyze passwords for weaknesses and problems.");
options.append(Analyze::HIBPDatabaseOption);
+ options.append(Analyze::OkonOption);
}
int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
@@ -46,20 +52,36 @@ int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPoint
auto& out = Utils::STDOUT;
auto& err = Utils::STDERR;
- QString hibpDatabase = parser->value(Analyze::HIBPDatabaseOption);
- QFile hibpFile(hibpDatabase);
- if (!hibpFile.open(QFile::ReadOnly)) {
- err << QObject::tr("Failed to open HIBP file %1: %2").arg(hibpDatabase).arg(hibpFile.errorString()) << endl;
+ QList<QPair<const Entry*, int>> findings;
+ QString error;
+
+ auto hibpDatabase = parser->value(Analyze::HIBPDatabaseOption);
+ if (!QFile::exists(hibpDatabase) || hibpDatabase.isEmpty()) {
+ err << QObject::tr("Cannot find HIBP file: %1").arg(hibpDatabase);
return EXIT_FAILURE;
}
- out << QObject::tr("Evaluating database entries against HIBP file, this will take a while...") << endl;
+ auto okon = parser->value(Analyze::OkonOption);
+ if (!okon.isEmpty()) {
+ out << QObject::tr("Evaluating database entries using okon...") << endl;
- QList<QPair<const Entry*, int>> findings;
- QString error;
- if (!HibpOffline::report(database, hibpFile, findings, &error)) {
- err << error << endl;
- return EXIT_FAILURE;
+ if (!HibpOffline::okonReport(database, okon, hibpDatabase, findings, &error)) {
+ err << error << endl;
+ return EXIT_FAILURE;
+ }
+ } else {
+ QFile hibpFile(hibpDatabase);
+ if (!hibpFile.open(QFile::ReadOnly)) {
+ err << QObject::tr("Failed to open HIBP file %1: %2").arg(hibpDatabase).arg(hibpFile.errorString()) << endl;
+ return EXIT_FAILURE;
+ }
+
+ out << QObject::tr("Evaluating database entries against HIBP file, this will take a while...") << endl;
+
+ if (!HibpOffline::report(database, hibpFile, findings, &error)) {
+ err << error << endl;
+ return EXIT_FAILURE;
+ }
}
for (auto& finding : findings) {
@@ -76,5 +98,9 @@ void Analyze::printHibpFinding(const Entry* entry, int count, QTextStream& out)
path.prepend("/").prepend(g->name());
}
- out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
+ if (count > 0) {
+ out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
+ } else {
+ out << QObject::tr("Password for '%1' has been leaked!", "", count).arg(path) << endl;
+ }
}
diff --git a/src/cli/Analyze.h b/src/cli/Analyze.h
index fbd3dff3c..a616093a4 100644
--- a/src/cli/Analyze.h
+++ b/src/cli/Analyze.h
@@ -27,6 +27,7 @@ public:
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;
static const QCommandLineOption HIBPDatabaseOption;
+ static const QCommandLineOption OkonOption;
private:
void printHibpFinding(const Entry* entry, int count, QTextStream& out);