Validate an exported secret key is decryptable by Sequoia #7026
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.
Status
Ready for review
Description of Changes
When we export a secret key in EncryptionManager, validate the output by checking that it is decryptable by Sequoia using the given passphrase and has the expected fingerprint.
A new redwood function, is_valid_secret_key() is the sibling to the eixsting is_valid_public_key(), except that it also takes a passphrase and verifies the secret key can be unlocked using the passphrase.
If the key passes all the conditions, only then is it returned by EncryptionManager to be saved in the database, and deleted out of GPG. If, for whatever reason, GPG fails at exporting the key, or exports something Sequoia can't handle, the key will not be stored and it'll continue to fall back to using GPG for decryption.
While we're at it, the export function is now named
get_source_secret_key_from_gpg
, to highlight that this specifically just exports the key from GPG and won't work for Sequoia based sources.Refs #7025.
Testing
I don't have any manual steps because this is to guard against an edge case in which GPG export fails, so it's easiest to prove with mocks and test cases, but if people have suggestions, they could be added to the test plan!
Deployment
Any special considerations for deployment? No
Checklist
make lint
) and tests (make test
) pass in the development container