Skip to content

Commit

Permalink
Fix being unable to unset to just a ChallengeResponse key
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored and droidmonkey committed Oct 4, 2022
1 parent 087de27 commit 6cf9c7c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/man/keepassxc-cli.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ It provides the ability to query and modify the entries of a KeePass database, d
*--no-password*::
Deactivates the password key for the database.

*-y*, *--yubikey* <__slot__>::
*-y*, *--yubikey* <__slot[:serial]__>::
Specifies a yubikey slot for unlocking the database.
In a merge operation this option is used to specify the YubiKey slot for the first database.

Expand All @@ -182,7 +182,7 @@ It provides the ability to query and modify the entries of a KeePass database, d
*--no-password-from*::
Deactivates password key for the database to merge from.

*--yubikey-from* <__slot__>::
*--yubikey-from* <__slot[:serial]__>::
YubiKey slot for the second database.

*-s*, *--same-credentials*::
Expand Down
6 changes: 3 additions & 3 deletions src/cli/DatabaseEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ QSharedPointer<CompositeKey> DatabaseEdit::getNewDatabaseKey(QSharedPointer<Data

auto currentPasswordKey = database->key()->getKey(PasswordKey::UUID);
auto currentFileKey = database->key()->getKey(FileKey::UUID);
auto currentChallengeResponseKey = database->key()->getKey(ChallengeResponseKey::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;
Expand Down Expand Up @@ -162,10 +162,10 @@ QSharedPointer<CompositeKey> DatabaseEdit::getNewDatabaseKey(QSharedPointer<Data
}

if (!currentChallengeResponseKey.isNull()) {
newDatabaseKey->addKey(currentChallengeResponseKey);
newDatabaseKey->addChallengeResponseKey(currentChallengeResponseKey);
}

if (newDatabaseKey->keys().isEmpty()) {
if (newDatabaseKey->keys().isEmpty() && newDatabaseKey->challengeResponseKeys().isEmpty()) {
err << QObject::tr("Cannot remove all the keys from a database.") << endl;
return {};
}
Expand Down
10 changes: 10 additions & 0 deletions src/keys/CompositeKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ QSharedPointer<Key> CompositeKey::getKey(const QUuid keyId) const
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;
Expand Down
1 change: 1 addition & 0 deletions src/keys/CompositeKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CompositeKey : public Key

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);
Expand Down

0 comments on commit 6cf9c7c

Please sign in to comment.