Repository navigation
wallet: include a checksum of encrypted private keys - #16946
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
33d1bf5 to
2b79a27
Compare
|
I'm afraid the current version of this PR will introduce a bug in Please note the first |
2b79a27 to
d76d302
Compare
Whoops, fixed. |
|
Concept ACK |
d76d302 to
667b7c7
Compare
What happens if I open with new version, then switch back to an old version, generate some new keys, then switch back to the new? Is a wallet flag really needed at all? Shouldn't verifying checksums also reveal if there are checksums missing? |
667b7c7 to
28ac72e
Compare
|
This is currently getting messed up by the ScriptPubKeyMan changes. Will fix, rebase, and address comments after ScriptPubKeyMan is fully introduced. |
28ac72e to
667b7c7
Compare
667b7c7 to
93a1e2a
Compare
|
I've rebased onto master and included #17369 as a prerequisite. I've also reworked it according to @luke-jr's suggestions. Instead of a wallet flag, we reuse |
93a1e2a to
8746a6d
Compare
|
Might want to rebase to get rid of the commits from #17369 and make it easier to review. |
8746a6d to
8ad4244
Compare
|
Rebased |
…ms are valid Change fDecryptionThoroughlyChecked to default to true so that it can latch to false when an invalid checksum is seen. Checksums may be invalid if the wallet does not have checksums or if the wallet became corrupted. It is safe to default fDecryptionThoroughlyChecked to true because any existing wallet without a checksum will set it to false. Any new or blank wallet where encrypted keys are added will then set this to true when the first encrypted key is generated by virtue of CheckDecryptionKey doing that during the initial Unlock prior to keys being added.
If fDecryptionThoroughlyChecked is false, after a key has been checked, write (or rewrite) its checksum. This serves to upgrade wallets and correct those which have the checksum corrupted but not the key.
8ad4244 to
d67055e
Compare
meshcollider
left a comment
There was a problem hiding this comment.
Code review ACK d67055e
|
ping @instagibbs |
|
code review ACK d67055e |
Summary: d67055e00dd90f504384e5c3f229fc95306d5aac Upgrade or rewrite encrypted key checksums (Andrew Chow) c9a9ddb4142af0af5f7b1a5ccd13f8e585007089 Set fDecryptionThoroughlyChecked based on whether crypted key checksums are valid (Andrew Chow) a8334f7ac39532528c5f8bd3b0eea05aa63e8794 Read and write a checksum for encrypted keys (Andrew Chow) Pull request description: Adds a checksum to the encrypted key record in the wallet database so that encrypted keys can be checked for corruption on wallet loading, in the same way that unencrypted keys are. This allows for us to skip the full decryption of keys upon the first unlocking of the wallet in that session as any key corruption will have already been detected. The checksum is just the double SHA256 of the encrypted key and it is appended to the record after the encrypted key itself. This is backwards compatible as old wallets will be able to read the encrypted key and ignore that there is more data in the stream. Additionally, old wallets will be upgraded upon their first unlocking (so that key decryption is checked before we commit to a checksum of the encrypted key) and a wallet flag set indicating that. The presence of the wallet flag lets us skip the full decryption as if `fDecryptionThoroughlyChecked` were true. This does mean that the first time an old wallet is unlocked in a new version will take much longer, but subsequent unlocks will be instantaneous. Furthermore, corruption will be detected upon loading rather than on trying to send so wallet corruption will be detected sooner. Fixes #12423 --- Backport of Core [[bitcoin/bitcoin#16946 | PR16946]] Test Plan: ninja all check check-functional Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D9156
Adds a checksum to the encrypted key record in the wallet database so that encrypted keys can be checked for corruption on wallet loading, in the same way that unencrypted keys are. This allows for us to skip the full decryption of keys upon the first unlocking of the wallet in that session as any key corruption will have already been detected. The checksum is just the double SHA256 of the encrypted key and it is appended to the record after the encrypted key itself.
This is backwards compatible as old wallets will be able to read the encrypted key and ignore that there is more data in the stream. Additionally, old wallets will be upgraded upon their first unlocking (so that key decryption is checked before we commit to a checksum of the encrypted key) and a wallet flag set indicating that. The presence of the wallet flag lets us skip the full decryption as if
fDecryptionThoroughlyCheckedwere true.This does mean that the first time an old wallet is unlocked in a new version will take much longer, but subsequent unlocks will be instantaneous. Furthermore, corruption will be detected upon loading rather than on trying to send so wallet corruption will be detected sooner.
Fixes #12423