mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-08 06:22:53 -04:00
[CLI] Add a db-edit command (#8400)
This commit is contained in:
parent
b1e7c34b82
commit
db98f114f9
16 changed files with 529 additions and 52 deletions
|
@ -22,9 +22,11 @@ set(cli_SOURCES
|
|||
AttachmentRemove.cpp
|
||||
Clip.cpp
|
||||
Close.cpp
|
||||
Create.cpp
|
||||
Command.cpp
|
||||
DatabaseCommand.cpp
|
||||
DatabaseCreate.cpp
|
||||
DatabaseEdit.cpp
|
||||
DatabaseInfo.cpp
|
||||
Diceware.cpp
|
||||
Edit.cpp
|
||||
Estimate.cpp
|
||||
|
@ -33,7 +35,6 @@ set(cli_SOURCES
|
|||
Generate.cpp
|
||||
Help.cpp
|
||||
Import.cpp
|
||||
Info.cpp
|
||||
List.cpp
|
||||
Merge.cpp
|
||||
Move.cpp
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
#include "AttachmentRemove.h"
|
||||
#include "Clip.h"
|
||||
#include "Close.h"
|
||||
#include "Create.h"
|
||||
#include "DatabaseCreate.h"
|
||||
#include "DatabaseEdit.h"
|
||||
#include "DatabaseInfo.h"
|
||||
#include "Diceware.h"
|
||||
#include "Edit.h"
|
||||
#include "Estimate.h"
|
||||
|
@ -32,7 +34,6 @@
|
|||
#include "Generate.h"
|
||||
#include "Help.h"
|
||||
#include "Import.h"
|
||||
#include "Info.h"
|
||||
#include "List.h"
|
||||
#include "Merge.h"
|
||||
#include "Move.h"
|
||||
|
@ -172,8 +173,9 @@ namespace Commands
|
|||
s_commands.insert(QStringLiteral("attachment-rm"), QSharedPointer<Command>(new AttachmentRemove()));
|
||||
s_commands.insert(QStringLiteral("clip"), QSharedPointer<Command>(new Clip()));
|
||||
s_commands.insert(QStringLiteral("close"), QSharedPointer<Command>(new Close()));
|
||||
s_commands.insert(QStringLiteral("db-create"), QSharedPointer<Command>(new Create()));
|
||||
s_commands.insert(QStringLiteral("db-info"), QSharedPointer<Command>(new Info()));
|
||||
s_commands.insert(QStringLiteral("db-create"), QSharedPointer<Command>(new DatabaseCreate()));
|
||||
s_commands.insert(QStringLiteral("db-edit"), QSharedPointer<Command>(new DatabaseEdit()));
|
||||
s_commands.insert(QStringLiteral("db-info"), QSharedPointer<Command>(new DatabaseInfo()));
|
||||
s_commands.insert(QStringLiteral("diceware"), QSharedPointer<Command>(new Diceware()));
|
||||
s_commands.insert(QStringLiteral("edit"), QSharedPointer<Command>(new Edit()));
|
||||
s_commands.insert(QStringLiteral("estimate"), QSharedPointer<Command>(new Estimate()));
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Create.h"
|
||||
#include "DatabaseCreate.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "keys/FileKey.h"
|
||||
|
@ -23,34 +23,39 @@
|
|||
#include <QCommandLineParser>
|
||||
#include <QFileInfo>
|
||||
|
||||
const QCommandLineOption Create::DecryptionTimeOption =
|
||||
const QCommandLineOption DatabaseCreate::DecryptionTimeOption =
|
||||
QCommandLineOption(QStringList() << "t"
|
||||
<< "decryption-time",
|
||||
QObject::tr("Target decryption time in MS for the database."),
|
||||
QObject::tr("time"));
|
||||
|
||||
const QCommandLineOption Create::SetKeyFileOption =
|
||||
QCommandLineOption(QStringList() << "k"
|
||||
<< "set-key-file",
|
||||
const QCommandLineOption DatabaseCreate::SetKeyFileShortOption = QCommandLineOption(
|
||||
QStringList() << "k",
|
||||
QObject::tr("Set the key file for the database.\nThis options is deprecated, use --set-key-file instead."),
|
||||
QObject::tr("path"));
|
||||
|
||||
const QCommandLineOption DatabaseCreate::SetKeyFileOption =
|
||||
QCommandLineOption(QStringList() << "set-key-file",
|
||||
QObject::tr("Set the key file for the database."),
|
||||
QObject::tr("path"));
|
||||
|
||||
const QCommandLineOption Create::SetPasswordOption =
|
||||
const QCommandLineOption DatabaseCreate::SetPasswordOption =
|
||||
QCommandLineOption(QStringList() << "p"
|
||||
<< "set-password",
|
||||
QObject::tr("Set a password for the database."));
|
||||
|
||||
Create::Create()
|
||||
DatabaseCreate::DatabaseCreate()
|
||||
{
|
||||
name = QString("db-create");
|
||||
description = QObject::tr("Create a new database.");
|
||||
positionalArguments.append({QString("database"), QObject::tr("Path of the database."), QString("")});
|
||||
options.append(Create::SetKeyFileOption);
|
||||
options.append(Create::SetPasswordOption);
|
||||
options.append(Create::DecryptionTimeOption);
|
||||
options.append(DatabaseCreate::SetKeyFileOption);
|
||||
options.append(DatabaseCreate::SetKeyFileShortOption);
|
||||
options.append(DatabaseCreate::SetPasswordOption);
|
||||
options.append(DatabaseCreate::DecryptionTimeOption);
|
||||
}
|
||||
|
||||
QSharedPointer<Database> Create::initializeDatabaseFromOptions(const QSharedPointer<QCommandLineParser>& parser)
|
||||
QSharedPointer<Database> DatabaseCreate::initializeDatabaseFromOptions(const QSharedPointer<QCommandLineParser>& parser)
|
||||
{
|
||||
if (parser.isNull()) {
|
||||
return {};
|
||||
|
@ -60,7 +65,7 @@ QSharedPointer<Database> Create::initializeDatabaseFromOptions(const QSharedPoin
|
|||
auto& err = Utils::STDERR;
|
||||
|
||||
// Validate the decryption time before asking for a password.
|
||||
QString decryptionTimeValue = parser->value(Create::DecryptionTimeOption);
|
||||
QString decryptionTimeValue = parser->value(DatabaseCreate::DecryptionTimeOption);
|
||||
int decryptionTime = 0;
|
||||
if (decryptionTimeValue.length() != 0) {
|
||||
decryptionTime = decryptionTimeValue.toInt();
|
||||
|
@ -78,7 +83,7 @@ QSharedPointer<Database> Create::initializeDatabaseFromOptions(const QSharedPoin
|
|||
|
||||
auto key = QSharedPointer<CompositeKey>::create();
|
||||
|
||||
if (parser->isSet(Create::SetPasswordOption)) {
|
||||
if (parser->isSet(DatabaseCreate::SetPasswordOption)) {
|
||||
auto passwordKey = Utils::getConfirmedPassword();
|
||||
if (passwordKey.isNull()) {
|
||||
err << QObject::tr("Failed to set database password.") << endl;
|
||||
|
@ -87,10 +92,18 @@ QSharedPointer<Database> Create::initializeDatabaseFromOptions(const QSharedPoin
|
|||
key->addKey(passwordKey);
|
||||
}
|
||||
|
||||
if (parser->isSet(Create::SetKeyFileOption)) {
|
||||
if (parser->isSet(DatabaseCreate::SetKeyFileOption) || parser->isSet(DatabaseCreate::SetKeyFileShortOption)) {
|
||||
QSharedPointer<FileKey> fileKey;
|
||||
|
||||
if (!Utils::loadFileKey(parser->value(Create::SetKeyFileOption), fileKey)) {
|
||||
QString keyFilePath;
|
||||
if (parser->isSet(DatabaseCreate::SetKeyFileShortOption)) {
|
||||
qWarning("The -k option will be deprecated. Please use the --set-key-file option instead.");
|
||||
keyFilePath = parser->value(DatabaseCreate::SetKeyFileShortOption);
|
||||
} else {
|
||||
keyFilePath = parser->value(DatabaseCreate::SetKeyFileOption);
|
||||
}
|
||||
|
||||
if (!Utils::loadFileKey(keyFilePath, fileKey)) {
|
||||
err << QObject::tr("Loading the key file failed") << endl;
|
||||
return {};
|
||||
}
|
||||
|
@ -141,7 +154,7 @@ QSharedPointer<Database> Create::initializeDatabaseFromOptions(const QSharedPoin
|
|||
*
|
||||
* @return EXIT_SUCCESS on success, or EXIT_FAILURE on failure
|
||||
*/
|
||||
int Create::execute(const QStringList& arguments)
|
||||
int DatabaseCreate::execute(const QStringList& arguments)
|
||||
{
|
||||
QSharedPointer<QCommandLineParser> parser = getCommandLineParser(arguments);
|
||||
if (parser.isNull()) {
|
||||
|
@ -159,7 +172,7 @@ int Create::execute(const QStringList& arguments)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
QSharedPointer<Database> db = Create::initializeDatabaseFromOptions(parser);
|
||||
QSharedPointer<Database> db = DatabaseCreate::initializeDatabaseFromOptions(parser);
|
||||
if (!db) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
|
@ -15,22 +15,23 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSXC_CREATE_H
|
||||
#define KEEPASSXC_CREATE_H
|
||||
#ifndef KEEPASSXC_DATABASECREATE_H
|
||||
#define KEEPASSXC_DATABASECREATE_H
|
||||
|
||||
#include "Command.h"
|
||||
|
||||
class Create : public Command
|
||||
class DatabaseCreate : public Command
|
||||
{
|
||||
public:
|
||||
Create();
|
||||
DatabaseCreate();
|
||||
int execute(const QStringList& arguments) override;
|
||||
|
||||
static QSharedPointer<Database> initializeDatabaseFromOptions(const QSharedPointer<QCommandLineParser>& parser);
|
||||
|
||||
static const QCommandLineOption SetKeyFileOption;
|
||||
static const QCommandLineOption SetKeyFileShortOption;
|
||||
static const QCommandLineOption SetPasswordOption;
|
||||
static const QCommandLineOption DecryptionTimeOption;
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_CREATE_H
|
||||
#endif // KEEPASSXC_DATABASECREATE_H
|
174
src/cli/DatabaseEdit.cpp
Normal file
174
src/cli/DatabaseEdit.cpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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 "DatabaseEdit.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "cli/DatabaseCreate.h"
|
||||
#include "keys/ChallengeResponseKey.h"
|
||||
#include "keys/FileKey.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QFileInfo>
|
||||
|
||||
const QCommandLineOption DatabaseEdit::UnsetPasswordOption =
|
||||
QCommandLineOption(QStringList() << "unset-password", QObject::tr("Unset the password for the database."));
|
||||
const QCommandLineOption DatabaseEdit::UnsetKeyFileOption =
|
||||
QCommandLineOption(QStringList() << "unset-key-file", QObject::tr("Unset the key file for the database."));
|
||||
|
||||
DatabaseEdit::DatabaseEdit()
|
||||
{
|
||||
name = QString("db-edit");
|
||||
description = QObject::tr("Edit a database.");
|
||||
options.append(DatabaseCreate::SetKeyFileOption);
|
||||
options.append(DatabaseCreate::SetPasswordOption);
|
||||
options.append(DatabaseEdit::UnsetKeyFileOption);
|
||||
options.append(DatabaseEdit::UnsetPasswordOption);
|
||||
}
|
||||
|
||||
int DatabaseEdit::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
|
||||
{
|
||||
auto& out = Utils::STDOUT;
|
||||
auto& err = Utils::STDERR;
|
||||
|
||||
const QStringList args = parser->positionalArguments();
|
||||
bool databaseWasChanged = false;
|
||||
|
||||
if (parser->isSet(DatabaseCreate::SetPasswordOption) && parser->isSet(DatabaseEdit::UnsetPasswordOption)) {
|
||||
err << QObject::tr("Cannot use %1 and %2 at the same time.")
|
||||
.arg(DatabaseCreate::SetPasswordOption.names().at(0))
|
||||
.arg(DatabaseEdit::UnsetPasswordOption.names().at(0))
|
||||
<< endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (parser->isSet(DatabaseCreate::SetKeyFileOption) && parser->isSet(DatabaseEdit::UnsetKeyFileOption)) {
|
||||
err << QObject::tr("Cannot use %1 and %2 at the same time.")
|
||||
.arg(DatabaseCreate::SetKeyFileOption.names().at(0))
|
||||
.arg(DatabaseEdit::UnsetKeyFileOption.names().at(0))
|
||||
<< endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
bool hasKeyChange =
|
||||
(parser->isSet(DatabaseCreate::SetPasswordOption) || parser->isSet(DatabaseCreate::SetKeyFileOption)
|
||||
|| parser->isSet(DatabaseEdit::UnsetPasswordOption) || parser->isSet(DatabaseEdit::UnsetKeyFileOption));
|
||||
|
||||
if (hasKeyChange) {
|
||||
auto newDatabaseKey = getNewDatabaseKey(database,
|
||||
parser->isSet(DatabaseCreate::SetPasswordOption),
|
||||
parser->isSet(DatabaseEdit::UnsetPasswordOption),
|
||||
parser->value(DatabaseCreate::SetKeyFileOption),
|
||||
parser->isSet(DatabaseEdit::UnsetKeyFileOption));
|
||||
if (newDatabaseKey.isNull()) {
|
||||
err << QObject::tr("Could not change the database key.") << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
database->setKey(newDatabaseKey);
|
||||
databaseWasChanged = true;
|
||||
}
|
||||
|
||||
if (!databaseWasChanged) {
|
||||
out << QObject::tr("Database was not modified.") << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
QString errorMessage;
|
||||
if (!database->save(Database::Atomic, {}, &errorMessage)) {
|
||||
err << QObject::tr("Writing the database failed: %1").arg(errorMessage) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
out << QObject::tr("Successfully edited the database.") << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
QSharedPointer<CompositeKey> DatabaseEdit::getNewDatabaseKey(QSharedPointer<Database> database,
|
||||
bool updatePassword,
|
||||
bool removePassword,
|
||||
QString newFileKeyPath,
|
||||
bool removeKeyFile)
|
||||
{
|
||||
auto& err = Utils::STDERR;
|
||||
auto newDatabaseKey = QSharedPointer<CompositeKey>::create();
|
||||
bool updateKeyFile = !newFileKeyPath.isEmpty();
|
||||
|
||||
auto currentPasswordKey = database->key()->getKey(PasswordKey::UUID);
|
||||
auto currentFileKey = database->key()->getKey(FileKey::UUID);
|
||||
auto currentChallengeResponseKey = database->key()->getChallengeResponseKey(ChallengeResponseKey::UUID);
|
||||
|
||||
if (removePassword && currentPasswordKey.isNull()) {
|
||||
err << QObject::tr("Cannot remove password: The database does not have a password.") << endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (removeKeyFile && currentFileKey.isNull()) {
|
||||
err << QObject::tr("Cannot remove file key: The database does not have a file key.") << endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (updatePassword) {
|
||||
QSharedPointer<PasswordKey> newPasswordKey = Utils::getConfirmedPassword();
|
||||
if (newPasswordKey.isNull()) {
|
||||
err << QObject::tr("Failed to set database password.") << endl;
|
||||
return {};
|
||||
}
|
||||
newDatabaseKey->addKey(newPasswordKey);
|
||||
} else if (!removePassword && !currentPasswordKey.isNull()) {
|
||||
newDatabaseKey->addKey(currentPasswordKey);
|
||||
}
|
||||
|
||||
if (updateKeyFile) {
|
||||
QSharedPointer<FileKey> newFileKey = QSharedPointer<FileKey>::create();
|
||||
QString errorMessage;
|
||||
if (!Utils::loadFileKey(newFileKeyPath, newFileKey)) {
|
||||
err << QObject::tr("Loading the new key file failed: %1").arg(errorMessage) << endl;
|
||||
return {};
|
||||
}
|
||||
newDatabaseKey->addKey(newFileKey);
|
||||
} else if (!removeKeyFile && !currentFileKey.isNull()) {
|
||||
newDatabaseKey->addKey(currentFileKey);
|
||||
}
|
||||
|
||||
// This is a sanity check to make sure that this function is not used if
|
||||
// new key types are introduced. Otherwise, those key types would be
|
||||
// silently removed from the database.
|
||||
for (const QSharedPointer<Key>& key : database->key()->keys()) {
|
||||
if (key->uuid() != PasswordKey::UUID && key->uuid() != FileKey::UUID) {
|
||||
err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << endl;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
for (const QSharedPointer<ChallengeResponseKey>& key : database->key()->challengeResponseKeys()) {
|
||||
if (key->uuid() != ChallengeResponseKey::UUID) {
|
||||
err << QObject::tr("Found unexpected Key type %1").arg(key->uuid().toString()) << endl;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentChallengeResponseKey.isNull()) {
|
||||
newDatabaseKey->addChallengeResponseKey(currentChallengeResponseKey);
|
||||
}
|
||||
|
||||
if (newDatabaseKey->keys().isEmpty() && newDatabaseKey->challengeResponseKeys().isEmpty()) {
|
||||
err << QObject::tr("Cannot remove all the keys from a database.") << endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
return newDatabaseKey;
|
||||
}
|
41
src/cli/DatabaseEdit.h
Normal file
41
src/cli/DatabaseEdit.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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_DATABASEEDIT_H
|
||||
#define KEEPASSXC_DATABASEEDIT_H
|
||||
|
||||
#include "DatabaseCommand.h"
|
||||
|
||||
class DatabaseEdit : public DatabaseCommand
|
||||
{
|
||||
public:
|
||||
DatabaseEdit();
|
||||
|
||||
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;
|
||||
|
||||
static const QCommandLineOption UnsetKeyFileOption;
|
||||
static const QCommandLineOption UnsetPasswordOption;
|
||||
|
||||
private:
|
||||
QSharedPointer<CompositeKey> getNewDatabaseKey(QSharedPointer<Database> database,
|
||||
bool updatePassword,
|
||||
bool removePassword,
|
||||
QString newFileKeyPath,
|
||||
bool removeKeyFile);
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_DATABASEEDIT_H
|
|
@ -15,7 +15,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Info.h"
|
||||
#include "DatabaseInfo.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "core/DatabaseStats.h"
|
||||
|
@ -25,13 +25,13 @@
|
|||
|
||||
#include <QCommandLineParser>
|
||||
|
||||
Info::Info()
|
||||
DatabaseInfo::DatabaseInfo()
|
||||
{
|
||||
name = QString("db-info");
|
||||
description = QObject::tr("Show a database's information.");
|
||||
}
|
||||
|
||||
int Info::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser>)
|
||||
int DatabaseInfo::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser>)
|
||||
{
|
||||
auto& out = Utils::STDOUT;
|
||||
|
|
@ -15,17 +15,17 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSXC_INFO_H
|
||||
#define KEEPASSXC_INFO_H
|
||||
#ifndef KEEPASSXC_DATABASEINFO_H
|
||||
#define KEEPASSXC_DATABASEINFO_H
|
||||
|
||||
#include "DatabaseCommand.h"
|
||||
|
||||
class Info : public DatabaseCommand
|
||||
class DatabaseInfo : public DatabaseCommand
|
||||
{
|
||||
public:
|
||||
Info();
|
||||
DatabaseInfo();
|
||||
|
||||
int executeWithDatabase(QSharedPointer<Database> db, QSharedPointer<QCommandLineParser> parser) override;
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_INFO_H
|
||||
#endif // KEEPASSXC_DATABASEINFO_H
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "Import.h"
|
||||
|
||||
#include "Create.h"
|
||||
#include "DatabaseCreate.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <QCommandLineParser>
|
||||
|
@ -40,9 +40,10 @@ Import::Import()
|
|||
description = QObject::tr("Import the contents of an XML database.");
|
||||
positionalArguments.append({QString("xml"), QObject::tr("Path of the XML database export."), QString("")});
|
||||
positionalArguments.append({QString("database"), QObject::tr("Path of the new database."), QString("")});
|
||||
options.append(Create::SetKeyFileOption);
|
||||
options.append(Create::SetPasswordOption);
|
||||
options.append(Create::DecryptionTimeOption);
|
||||
options.append(DatabaseCreate::SetKeyFileOption);
|
||||
options.append(DatabaseCreate::SetKeyFileShortOption);
|
||||
options.append(DatabaseCreate::SetPasswordOption);
|
||||
options.append(DatabaseCreate::DecryptionTimeOption);
|
||||
}
|
||||
|
||||
int Import::execute(const QStringList& arguments)
|
||||
|
@ -64,7 +65,7 @@ int Import::execute(const QStringList& arguments)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
QSharedPointer<Database> db = Create::initializeDatabaseFromOptions(parser);
|
||||
QSharedPointer<Database> db = DatabaseCreate::initializeDatabaseFromOptions(parser);
|
||||
if (!db) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -169,6 +169,36 @@ void CompositeKey::addKey(const QSharedPointer<Key>& key)
|
|||
m_keys.append(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the \link Key with the specified ID.
|
||||
*
|
||||
* @param keyId the ID of the key to get.
|
||||
*/
|
||||
QSharedPointer<Key> CompositeKey::getKey(const QUuid keyId) const
|
||||
{
|
||||
for (const QSharedPointer<Key>& key : m_keys) {
|
||||
if (key->uuid() == keyId) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the \link ChallengeResponseKey with the specified ID.
|
||||
*
|
||||
* @param keyId the ID of the key to get.
|
||||
*/
|
||||
QSharedPointer<ChallengeResponseKey> CompositeKey::getChallengeResponseKey(const QUuid keyId) const
|
||||
{
|
||||
for (const QSharedPointer<ChallengeResponseKey>& key : m_challengeResponseKeys) {
|
||||
if (key->uuid() == keyId) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of Keys which are part of this CompositeKey
|
||||
*/
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
bool challenge(const QByteArray& seed, QByteArray& result, QString* error = nullptr) const;
|
||||
|
||||
void addKey(const QSharedPointer<Key>& key);
|
||||
QSharedPointer<Key> getKey(const QUuid keyType) const;
|
||||
QSharedPointer<ChallengeResponseKey> getChallengeResponseKey(const QUuid keyType) const;
|
||||
const QList<QSharedPointer<Key>>& keys() const;
|
||||
|
||||
void addChallengeResponseKey(const QSharedPointer<ChallengeResponseKey>& key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue