mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-28 23:37:21 -05:00
Adding a GUI prompt for password. (#587)
This commit is contained in:
parent
a75746c7c1
commit
c3bd5d21aa
@ -26,37 +26,47 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
#include "gui/UnlockDatabaseDialog.h"
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
#include "core/Group.h"
|
#include "core/Group.h"
|
||||||
#include "gui/Clipboard.h"
|
#include "gui/Clipboard.h"
|
||||||
#include "keys/CompositeKey.h"
|
|
||||||
|
|
||||||
int Clip::execute(int argc, char** argv)
|
int Clip::execute(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
|
||||||
|
QStringList arguments;
|
||||||
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
arguments << QString(argv[i]);
|
||||||
|
}
|
||||||
QTextStream out(stdout);
|
QTextStream out(stdout);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(QCoreApplication::translate("main", "Copy a password to the clipboard"));
|
parser.setApplicationDescription(QCoreApplication::translate("main", "Copy a password to the clipboard"));
|
||||||
parser.addPositionalArgument("database", QCoreApplication::translate("main", "Path of the database."));
|
parser.addPositionalArgument("database", QCoreApplication::translate("main", "Path of the database."));
|
||||||
|
QCommandLineOption guiPrompt(
|
||||||
|
QStringList() << "g"
|
||||||
|
<< "gui-prompt",
|
||||||
|
QCoreApplication::translate("main", "Use a GUI prompt unlocking the database."));
|
||||||
|
parser.addOption(guiPrompt);
|
||||||
parser.addPositionalArgument("entry", QCoreApplication::translate("main", "Name of the entry to clip."));
|
parser.addPositionalArgument("entry", QCoreApplication::translate("main", "Name of the entry to clip."));
|
||||||
parser.process(app);
|
parser.process(arguments);
|
||||||
|
|
||||||
const QStringList args = parser.positionalArguments();
|
const QStringList args = parser.positionalArguments();
|
||||||
if (args.size() != 2) {
|
if (args.size() != 2) {
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "Insert the database password\n> ";
|
Database* db = nullptr;
|
||||||
out.flush();
|
QApplication app(argc, argv);
|
||||||
|
if (parser.isSet("gui-prompt")) {
|
||||||
|
db = UnlockDatabaseDialog::openDatabasePrompt(args.at(0));
|
||||||
|
} else {
|
||||||
|
db = Database::unlockFromStdin(args.at(0));
|
||||||
|
}
|
||||||
|
|
||||||
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
|
|
||||||
QString line = inputTextStream.readLine();
|
|
||||||
CompositeKey key = CompositeKey::readFromLine(line);
|
|
||||||
|
|
||||||
Database* db = Database::openDatabaseFile(args.at(0), key);
|
|
||||||
if (!db) {
|
if (!db) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,6 @@ int main(int argc, char** argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoreApplication app(argc, argv);
|
|
||||||
app.setApplicationVersion(KEEPASSX_VERSION);
|
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
|
|
||||||
QString description("KeePassXC command line interface.");
|
QString description("KeePassXC command line interface.");
|
||||||
@ -72,6 +69,8 @@ int main(int argc, char** argv)
|
|||||||
// parser.process(app);
|
// parser.process(app);
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
app.setApplicationVersion(KEEPASSX_VERSION);
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@ -104,6 +103,8 @@ int main(int argc, char** argv)
|
|||||||
exitCode = Show::execute(argc, argv);
|
exitCode = Show::execute(argc, argv);
|
||||||
} else {
|
} else {
|
||||||
qCritical("Invalid command %s.", qPrintable(commandName));
|
qCritical("Invalid command %s.", qPrintable(commandName));
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
app.setApplicationVersion(KEEPASSX_VERSION);
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
@ -396,3 +397,17 @@ Database* Database::openDatabaseFile(QString fileName, CompositeKey key)
|
|||||||
return db;
|
return db;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Database* Database::unlockFromStdin(QString databaseFilename)
|
||||||
|
{
|
||||||
|
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
|
||||||
|
QTextStream outputTextStream(stdout);
|
||||||
|
|
||||||
|
outputTextStream << QString("Insert password to unlock " + databaseFilename + "\n>");
|
||||||
|
outputTextStream.flush();
|
||||||
|
|
||||||
|
QString line = inputTextStream.readLine();
|
||||||
|
CompositeKey key = CompositeKey::readFromLine(line);
|
||||||
|
return Database::openDatabaseFile(databaseFilename, key);
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
QByteArray transformSeed() const;
|
QByteArray transformSeed() const;
|
||||||
quint64 transformRounds() const;
|
quint64 transformRounds() const;
|
||||||
QByteArray transformedMasterKey() const;
|
QByteArray transformedMasterKey() const;
|
||||||
const CompositeKey & key() const;
|
const CompositeKey& key() const;
|
||||||
QByteArray challengeResponseKey() const;
|
QByteArray challengeResponseKey() const;
|
||||||
bool challengeMasterSeed(const QByteArray& masterSeed);
|
bool challengeMasterSeed(const QByteArray& masterSeed);
|
||||||
|
|
||||||
@ -120,6 +120,7 @@ public:
|
|||||||
|
|
||||||
static Database* databaseByUuid(const Uuid& uuid);
|
static Database* databaseByUuid(const Uuid& uuid);
|
||||||
static Database* openDatabaseFile(QString fileName, CompositeKey key);
|
static Database* openDatabaseFile(QString fileName, CompositeKey key);
|
||||||
|
static Database* unlockFromStdin(QString databaseFilename);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void groupDataChanged(Group* group);
|
void groupDataChanged(Group* group);
|
||||||
|
@ -19,18 +19,17 @@
|
|||||||
#include "UnlockDatabaseWidget.h"
|
#include "UnlockDatabaseWidget.h"
|
||||||
|
|
||||||
#include "autotype/AutoType.h"
|
#include "autotype/AutoType.h"
|
||||||
#include "gui/DragTabBar.h"
|
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
|
#include "gui/DragTabBar.h"
|
||||||
|
|
||||||
|
UnlockDatabaseDialog::UnlockDatabaseDialog(QWidget* parent)
|
||||||
UnlockDatabaseDialog::UnlockDatabaseDialog(QWidget *parent)
|
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_view(new UnlockDatabaseWidget(this))
|
, m_view(new UnlockDatabaseWidget(this))
|
||||||
{
|
{
|
||||||
connect(m_view, SIGNAL(editFinished(bool)), this, SLOT(complete(bool)));
|
connect(m_view, SIGNAL(editFinished(bool)), this, SLOT(complete(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnlockDatabaseDialog::setDBFilename(const QString &filename)
|
void UnlockDatabaseDialog::setDBFilename(const QString& filename)
|
||||||
{
|
{
|
||||||
m_view->load(filename);
|
m_view->load(filename);
|
||||||
}
|
}
|
||||||
@ -40,7 +39,7 @@ void UnlockDatabaseDialog::clearForms()
|
|||||||
m_view->clearForms();
|
m_view->clearForms();
|
||||||
}
|
}
|
||||||
|
|
||||||
Database *UnlockDatabaseDialog::database()
|
Database* UnlockDatabaseDialog::database()
|
||||||
{
|
{
|
||||||
return m_view->database();
|
return m_view->database();
|
||||||
}
|
}
|
||||||
@ -54,3 +53,20 @@ void UnlockDatabaseDialog::complete(bool r)
|
|||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Database* UnlockDatabaseDialog::openDatabasePrompt(QString databaseFilename)
|
||||||
|
{
|
||||||
|
|
||||||
|
UnlockDatabaseDialog* unlockDatabaseDialog = new UnlockDatabaseDialog();
|
||||||
|
unlockDatabaseDialog->setObjectName("Open database");
|
||||||
|
unlockDatabaseDialog->setDBFilename(databaseFilename);
|
||||||
|
unlockDatabaseDialog->show();
|
||||||
|
unlockDatabaseDialog->exec();
|
||||||
|
|
||||||
|
Database* db = unlockDatabaseDialog->database();
|
||||||
|
if (!db) {
|
||||||
|
qWarning("Could not open database %s.", qPrintable(databaseFilename));
|
||||||
|
}
|
||||||
|
delete unlockDatabaseDialog;
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
@ -31,10 +31,11 @@ class UnlockDatabaseDialog : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UnlockDatabaseDialog(QWidget *parent = Q_NULLPTR);
|
explicit UnlockDatabaseDialog(QWidget* parent = Q_NULLPTR);
|
||||||
void setDBFilename(const QString& filename);
|
void setDBFilename(const QString& filename);
|
||||||
void clearForms();
|
void clearForms();
|
||||||
Database* database();
|
Database* database();
|
||||||
|
static Database* openDatabasePrompt(QString databaseFilename);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unlockDone(bool);
|
void unlockDone(bool);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user