Fix AssertionError on decryption whenever there is another ECC key in the keychain
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:
- Generate second key with the following properties: ECC and ECC (encryption) - nistp256
gpg --full-generate-key --expert(9) ECC and ECC (3) NIST P-256 Key is valid for? (0) 0 Real name: Alice - Delete secret key for key 'Alice'
gpg --delete-secret-key 'Alice' - Encrypt a test file with both keys
gpg -e -r Alice -r trezor test - Restart trezor gpg agent
- Try to decrypt
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
Looks like I duplicated this work in #483. The comment there has a script to automate key generation & testing/repro.