Skip to content

keepassxc-cli show: resolve references in output#1280

Merged
louib merged 4 commits intokeepassxreboot:developfrom
cyphar:keepasscli-resolve-references
Dec 17, 2017
Merged

keepassxc-cli show: resolve references in output#1280
louib merged 4 commits intokeepassxreboot:developfrom
cyphar:keepasscli-resolve-references

Conversation

@cyphar
Copy link
Copy Markdown
Contributor

@cyphar cyphar commented Dec 14, 2017

Previously, keepassxc-cli show would not resolve references. This
would make it quite hard to script around its output (since there's not
interface to resolve references manually either). Fix this by using
resolveMultiplePlaceholders as with all other users of ->password() and
related entry fields.

Fixes #1260
Fixes #1269
Fixes #1211
Signed-off-by: Aleksa Sarai cyphar@cyphar.com

How has this been tested?

I tested this on my own KeePassXC database on several different entries (included nested ones), and verified that entries which were references now resolved to the correct value and that non-reference values also are correctly handled.

Types of changes

  • ✅ Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]
  • ✅ I have added tests to cover my changes.

LeakSanitiser gives errors on develop at the moment, but as far as I can tell no additional ASAN errors were added by this change.

@TheZ3ro TheZ3ro requested review from TheZ3ro and louib December 14, 2017 17:09
@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Dec 14, 2017

Just a note. Notes field also need to be resolved (see below)

setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->notes()));

@cyphar
Copy link
Copy Markdown
Contributor Author

cyphar commented Dec 14, 2017

Ah, I didn't know you could use references for Notes (though I guess that makes sense, since references are used everywhere).

As an aside, I have a proposal that we should be applying resolveMultiplePlaceholders by default to all entry->m_attributes->value invocations, and you have to explicitly use something like entry->rawPassword() in order to not resolve the password. At the moment resolveMultiplePlaceholders is very repetitive and error prone (as this bug shows).

@chuinul
Copy link
Copy Markdown
Contributor

chuinul commented Dec 14, 2017

Is this working for you? The fix seems correct but from an up-to-date develop it gives me an unexpected output: "resolved" fields are empty.

When tracing, Entry::resolveReferencePlaceholderRecursive captures all information from the reference, but refEntry is not found. Am I the only one in that situation?

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Dec 14, 2017

@cyphar I agree, but we need to make a deep refactor of the code

@cyphar
Copy link
Copy Markdown
Contributor Author

cyphar commented Dec 14, 2017

@chuinul I've seen this as well. I've figured it out and will push a fix for this problem and add some tests (the bug was that uuid::toHex() is lowercase, but references can be uppercase and the default style is uppercase).

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Dec 14, 2017

Yup, it's already tracked as #1269

@cyphar
Copy link
Copy Markdown
Contributor Author

cyphar commented Dec 15, 2017

Alright, I've done quite a few fixes in this PR now.

  1. UUID searching is now case-insensitive (in particular the searching is done by-Uuid rather than a string comparison), which fixes the current bug in develop.
  2. keepassxc-cli show resolves references.
  3. KeePassHTTP's Access Control dialog resolves references.
  4. Added tests to better protect against reference resolution regressions (especially in relation to cloned entries).

Tests all pass, and I've verified that things work now.

Copy link
Copy Markdown
Contributor

@TheZ3ro TheZ3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. 👍 for testing

Database db;
Group* root = db.rootGroup();

Entry *original = new Entry();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyphar we normally place pointers on the left, just like Group* root above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

4c4d8a5 ("Implement search for reference placeholder based on
fields other than ID") changed the semantics of searching-by-reference
in KeePassXC. Unforuntately it contained a bug where it implicitly
became case-sensitive to UUIDs, which broke existing databases that used
references (especially since the default reference format uses a
different case to the UUID used while searching).

The tests didn't catch this because ->toHex() preserves the case that it
was provided, they have been updated to check that UUIDs are case
insensitive.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Previously, `keepassxc-cli show` would not resolve references. This
would make it quite hard to script around its output (since there's not
interface to resolve references manually either). Fix this by using
resolveMultiplePlaceholders as with all other users of ->password() and
related entry fields.

Fixes: #1260
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
The access control dialog previously would not show the "real" username
or "real" title when asking for permission to give access to entries.
Fix this by resolving it, as we do in many other places.

Fixes: #1269
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This ensures that the most "intuitive" current usage of references
(through the clone feature of the GUI) remains self-consistent and
always produces the correct results. In addition, explicitly test that
case insensitivity works as expected. These should avoid similar
regressions in reference handling in the future.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
@cyphar
Copy link
Copy Markdown
Contributor Author

cyphar commented Dec 17, 2017

Rebased on #1289 since it's been merged.

@louib louib merged commit 9f8943c into keepassxreboot:develop Dec 17, 2017
@cyphar cyphar deleted the keepasscli-resolve-references branch December 17, 2017 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants