Skip to content
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

Fix bug in CKey DER encoding #10043

Closed

Conversation

jonasschnelli
Copy link
Contributor

At the moment, due to a mistake in our code, we DER export uncompressed keys as compressed.
Addresses #10041.

@@ -135,6 +135,7 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
if (!ec_privkey_import_der(secp256k1_context_sign, (unsigned char*)begin(), &privkey[0], privkey.size()))
return false;
fCompressed = fCompressedIn;
assert(privkey[1] == (fCompressed ? 0x81 : 0x82));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is correct and if we should abort if this the assumption is not true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we do not call this function at all anyway...

@fanquake fanquake added the Bug label Mar 21, 2017
@jonasschnelli jonasschnelli changed the title 2017/03/fix der comp Fix bug in CKey DER encoding Mar 21, 2017
@NicolasDorier
Copy link
Contributor

I am quite surprised we even export private key in DER, I never had a need for it. Why is it used ?

@jonasschnelli
Copy link
Contributor Author

AFAIK the only place where we use DER private keys is when storing/retrieving from the wallet.dat BDB database. We should probably change that, but reading DER must be supported at least.

@laanwj
Copy link
Member

laanwj commented Mar 21, 2017

Thanks for the fix!
How does this affect users of the wallet or RPC? Does this need backports?

@jonasschnelli
Copy link
Contributor Author

How does this affect users of the wallet or RPC? Does this need backports?

I'm not entirely sure. I haven't analysed the full ramification.
It looks like, that we only use the DER encoding during serialisation to and deserialisation from the database. Internally it should be treated correctly. Walletdump, etc. should be correct.

At the moment, I'm not sure what happens if you import an uncompressed WIF priv key. Or what happened when we introduced the bug with already existing uncompressed DER encoded keys in the wallet.

@gmaxwell
Copy link
Contributor

(as was discussed in the last meeting)

This has no effect, we never read it. It's just idiocy in the format that a public key is saved inside the private key at all. I think it should just always set compressed here. We use the public key outside of the private key for everything interesting.

@laanwj
Copy link
Member

laanwj commented Apr 7, 2017

OK so this is not really a bug, just a peculiarity of our data format.
I think then that we should close this and keep things as-is (and later on, switch to a better storage format)

@jonasschnelli
Copy link
Contributor Author

OK so this is not really a bug, just a peculiarity of our data format.
I think then that we should close this and keep things as-is (and later on, switch to a better storage format)

Yes. Agree. We could optimise this out maybe together with the new, non backward compatible HD internal/external database format.

@jonasschnelli
Copy link
Contributor Author

Closing

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.

None yet

6 participants