8000 wallet: Include a signature with encrypted keys to mitigate a wallet scam by achow101 · Pull Request #25766 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wallet: Include a signature with encrypted keys to mitigate a wallet scam #25766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

achow101
Copy link
Member
@achow101 achow101 commented Aug 1, 2022

This PR adds a signature to the encrypted key records (ckey and walletdescriptorckey) which acts as an additional checksum. The signature is produced by the private key, and signs the encrypted private key data. It is a schnorr signature. The signature is verified when the encrypted key record is loaded, and if it fails to verify then the loading fails with a wallet corrupted error.

The purpose of doing this is to mitigate a common scam where users are given/sold a wallet file that contains "encrypted" private keys that correspond to several high valued UTXOs. However the "encrypted" keys are not actually encrypted, they are just garbage data. The signature allows the wallet to ensure that the private keys for the stated pubkeys was known at the time of encryption, so it should help mitigate this scam by making it harder for scammers to make high value UTXOs appear to be IsMine.

There is, of course, a downgrade attack where the scammer can continue to do this with a wallet that does not have signatures over the encrypted keys. To mitigate this, the user will get a warning when they open a wallet that has encrypted keys without signatures. When the wallet is next unlocked, the signatures will be generated and written to the wallet file.

@fanquake fanquake added the Wallet label Aug 1, 2022
@DrahtBot
Copy link
Contributor
DrahtBot commented Aug 2, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK 1440000bytes, benthecarman, theStack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27286 (wallet: Keep track of the wallet's own transaction outputs in memory by achow101)
  • #26728 (wallet: Have the wallet store the key for automatically generated descriptors by achow101)
  • #26596 (wallet: Migrate legacy wallets to descriptor wallets without requiring BDB by achow101)
  • #25907 (wallet: rpc to add automatically generated descriptors by achow101)
  • #25297 (wallet: group independent db writes on single batched db transaction by furszy)
  • #24914 (wallet: Load database records in a particular order by achow101)
  • #22341 (rpc: add getxpub by Sjors)
  • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ghost
Copy link
ghost commented Aug 2, 2022

Concept ACK

1 similar comment
@benthecarman
Copy link
Contributor

Concept ACK

@theStack
Copy link
Contributor
theStack commented Aug 7, 2022

Concept ACK

Comment on lines -249 to +259
// Rewrite these encrypted keys with checksums
batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]);
// Rewrite these encrypted keys with checksums and signatures
uint256 enckey_hash = Hash(vchCryptedSecret);
std::vector<unsigned char> sig(64);
if (!key.SignSchnorr(enckey_hash, sig, nullptr, uint256())) {
keyFail = true;
break;
}
batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()], sig);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if this change would better fit into the later commit 20451e7 ("wallet: Write encrypted key sig if it is not present"), where the same is (only) done for DescriptorScriptPubKeyMan?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it cannot be moved to later since WriteCryptedKey also changes in this commit. The later commit is for DescriptorSPKM only because it doesn't already have an existing upgrading mechanism that needed changes.

@luke-jr
Copy link
Member
luke-jr commented Aug 10, 2022

I suspect this might actually make the problem worse. With this, a degree of trust in wallets having valid encrypted keys could develop, and it doesn't actually prevent the scam (the scammer just needs access to sufficient funds which remain not at risk).

@bitcoin bitcoin deleted a comment Nov 19, 2022
In order to mitigate scams, we write a signature created by the now
encrypted key, with a message of the encrypted key data. This signature
will be verified on loading.
In DescriptorScriptPubKeyMan, we now set m_decryption_thoroughly_checked
to false when the encrypted key signature is not present.
Instead of copying and overwriting wallet files directly, we can use the
backupwallet and restorewallet RPCs.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0