add diceware and passgen to the cli interface

This commit is contained in:
thez3ro 2018-01-19 15:48:40 +01:00
parent 490e92167d
commit 27f8aa095a
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
7 changed files with 291 additions and 1 deletions

View File

@ -20,6 +20,8 @@ set(cli_SOURCES
Clip.h
Command.cpp
Command.h
Diceware.cpp
Diceware.h
Edit.cpp
Edit.h
Estimate.cpp
@ -32,6 +34,8 @@ set(cli_SOURCES
Locate.h
Merge.cpp
Merge.h
PassGen.cpp
PassGen.h
Remove.cpp
Remove.h
Show.cpp

View File

@ -24,12 +24,14 @@
#include "Add.h"
#include "Clip.h"
#include "Diceware.h"
#include "Edit.h"
#include "Estimate.h"
#include "Extract.h"
#include "List.h"
#include "Locate.h"
#include "Merge.h"
#include "PassGen.h"
#include "Remove.h"
#include "Show.h"
@ -61,12 +63,14 @@ void populateCommands()
if (commands.isEmpty()) {
commands.insert(QString("add"), new Add());
commands.insert(QString("clip"), new Clip());
commands.insert(QString("diceware"), new Diceware());
commands.insert(QString("edit"), new Edit());
commands.insert(QString("estimate"), new Estimate());
commands.insert(QString("extract"), new Extract());
commands.insert(QString("locate"), new Locate());
commands.insert(QString("ls"), new List());
commands.insert(QString("merge"), new Merge());
commands.insert(QString("passgen"), new PassGen());
commands.insert(QString("rm"), new Remove());
commands.insert(QString("show"), new Show());
}

79
src/cli/Diceware.cpp Normal file
View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <stdio.h>
#include "Diceware.h"
#include <QCommandLineParser>
#include <QTextStream>
#include "core/PassphraseGenerator.h"
Diceware::Diceware()
{
this->name = QString("diceware");
this->description = QObject::tr("Generate a new random password.");
}
Diceware::~Diceware()
{
}
int Diceware::execute(QStringList arguments)
{
QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
QTextStream outputTextStream(stdout, QIODevice::WriteOnly);
QCommandLineParser parser;
parser.setApplicationDescription(this->description);
QCommandLineOption wordlistFile(QStringList() << "w"
<< "wordlist",
QObject::tr("Wordlist fot the diceware generator.\n[Default: EFF English]"),
QObject::tr("path"));
parser.addOption(wordlistFile);
parser.addPositionalArgument("words", QObject::tr("Word count for the diceware generator."));
parser.process(arguments);
const QStringList args = parser.positionalArguments();
if (args.size() != 1) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli diceware");
return EXIT_FAILURE;
}
PassphraseGenerator dicewareGenerator;
int words = args.at(0).toInt();
dicewareGenerator.setWordCount(words);
if (!parser.value(wordlistFile).isEmpty()) {
dicewareGenerator.setWordList(parser.value(wordlistFile));
} else {
dicewareGenerator.setDefaultWordList();
}
if (!dicewareGenerator.isValid()) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen");
return EXIT_FAILURE;
}
QString password = dicewareGenerator.generatePassphrase();
outputTextStream << password << endl;
return EXIT_SUCCESS;
}

31
src/cli/Diceware.h Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSXC_DICEWARE_H
#define KEEPASSXC_DICEWARE_H
#include "Command.h"
class Diceware : public Command
{
public:
Diceware();
~Diceware();
int execute(QStringList arguments);
};
#endif // KEEPASSXC_DICEWARE_H

108
src/cli/PassGen.cpp Normal file
View File

@ -0,0 +1,108 @@
/*
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <stdio.h>
#include "PassGen.h"
#include <QCommandLineParser>
#include <QTextStream>
#include "core/PasswordGenerator.h"
PassGen::PassGen()
{
this->name = QString("passgen");
this->description = QObject::tr("Generate a new random password.");
}
PassGen::~PassGen()
{
}
int PassGen::execute(QStringList arguments)
{
QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
QTextStream outputTextStream(stdout, QIODevice::WriteOnly);
QCommandLineParser parser;
parser.setApplicationDescription(this->description);
QCommandLineOption lower(QStringList() << "l",
QObject::tr("Use lowercase in the generated password."));
parser.addOption(lower);
QCommandLineOption upper(QStringList() << "u",
QObject::tr("Use uppercase in the generated password."));
parser.addOption(upper);
QCommandLineOption numeric(QStringList() << "n",
QObject::tr("Use numbers in the generated password."));
parser.addOption(numeric);
QCommandLineOption special(QStringList() << "s",
QObject::tr("Use special characters in the generated password."));
parser.addOption(special);
QCommandLineOption extended(QStringList() << "e",
QObject::tr("Use extended ascii in the generated password."));
parser.addOption(extended);
parser.addPositionalArgument("length", QObject::tr("Length of the generated password."));
parser.process(arguments);
const QStringList args = parser.positionalArguments();
if (args.size() != 1) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen");
return EXIT_FAILURE;
}
PasswordGenerator passwordGenerator;
int length = args.at(0).toInt();
passwordGenerator.setLength(length);
PasswordGenerator::CharClasses classes = 0x0;
if (parser.isSet(lower)) {
classes |= PasswordGenerator::LowerLetters;
}
if (parser.isSet(upper)) {
classes |= PasswordGenerator::UpperLetters;
}
if (parser.isSet(numeric)) {
classes |= PasswordGenerator::Numbers;
}
if (parser.isSet(special)) {
classes |= PasswordGenerator::SpecialCharacters;
}
if (parser.isSet(extended)) {
classes |= PasswordGenerator::EASCII;
}
if (classes == 0x0) {
passwordGenerator.setCharClasses(PasswordGenerator::LowerLetters | PasswordGenerator::UpperLetters |
PasswordGenerator::Numbers);
} else {
passwordGenerator.setCharClasses(classes);
}
if (!passwordGenerator.isValid()) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen");
return EXIT_FAILURE;
}
QString password = passwordGenerator.generatePassword();
outputTextStream << password << endl;
return EXIT_SUCCESS;
}

31
src/cli/PassGen.h Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSXC_PASSGEN_H
#define KEEPASSXC_PASSGEN_H
#include "Command.h"
class PassGen : public Command
{
public:
PassGen();
~PassGen();
int execute(QStringList arguments);
};
#endif // KEEPASSXC_PASSGEN_H

View File

@ -1,4 +1,4 @@
.TH KEEPASSXC-CLI 1 "Aug 22, 2017"
.TH KEEPASSXC-CLI 1 "Jan 19, 2018"
.SH NAME
keepassxc-cli \- command line interface for the \fBKeePassXC\fP password manager.
@ -19,6 +19,9 @@ Adds a new entry to a database. A password can be generated (\fI-g\fP option), o
.IP "clip [options] <database> <entry> [timeout]"
Copies the password of a database entry to the clipboard. If multiple entries with the same name exist in different groups, only the password for the first one is going to be copied. For copying the password of an entry in a specific group, the group path to the entry should be specified as well, instead of just the name. Optionally, a timeout in seconds can be specified to automatically clear the clipboard.
.IP "diceware [options] <words>"
Generate a random diceware passphrase.
.IP "edit [options] <database> <entry>"
Edits a database entry. A password can be generated (\fI-g\fP option), or a prompt can be displayed to input the password (\fI-p\fP option).
@ -37,6 +40,9 @@ Lists the contents of a group in a database. If no group is specified, it will d
.IP "merge [options] <database1> <database2>"
Merges two databases together. The first database file is going to be replaced by the result of the merge, for that reason it is advisable to keep a backup of the two database files before attempting a merge. In the case that both databases make use of the same credentials, the \fI--same-credentials\fP or \fI-s\fP option can be used.
.IP "passgen [options] <length>"
Generate a random password
.IP "rm [options] <database> <entry>"
Removes an entry from a database. If the database has a recycle bin, the entry will be moved there. If the entry is already in the recycle bin, it will be removed permanently.
@ -104,6 +110,33 @@ with each attribute shown one-per-line in the given order. If no attributes are
specified, a summary of the default attributes is given.
.SS "Diceware options"
.IP "-w, --wordlist <path>"
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.
.SS "PassGen options"
.IP "-l"
Use lowercase characters for the password generator
.IP "-u"
Use uppercase characters for the password generator
.IP "-n"
Use numbers characters for the password generator
.IP "-s"
Use special characters for the password generator
.IP "-e"
Use extended ascii characters for the password generator
.SH REPORTING BUGS
Bugs and feature requests can be reported on GitHub at https://github.com/keepassxreboot/keepassxc/issues.