Fix AssertionError on decryption whenever there is another ECC key in the keychain #470
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whenever there are other public keys in the GPG keychain with the ECC alogrithm, decryption is not possible.
How to reproduce:
Short:
Suppose our trezor-key has the uuid: 'trezor'. We create another public key called 'Alice' and encrypt a file with both keys.
Decryption is not possible.
Long:
gpg --full-generate-key --expert
(9) ECC and ECC
(3) NIST P-256
Key is valid for? (0) 0
Real name: Alice
gpg --delete-secret-key 'Alice'
gpg -e -r Alice -r trezor test
gpg -d test.gpg
Result: There is an AssertionError:
File "/home/user/projects/trezor-agent/libagent/gpg/agent.py", line 174, in get_identity
assert pubkey.key_id() == pubkey_dict['key_id']
AssertionError
This is the case, because all compatible keys in the keychain are being tried and when the key is not the same with the key on the HW device an Assertion error is thrown.
Fix by: Ignore keys which do not correspond to key on device instead of throwing an Assertion Error