-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Openssl bump #5634
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
Openssl bump #5634
Conversation
New versions of OpenSSL will reject non-canonical DER signatures. However, it'll happily decode them. Decode then re-encode before verification in order to ensure that it is properly consumed.
|
ACK: code reviewed, and fixes unit test errors running on OSX with OpenSSL 1.0.1k |
src/ecwrapper.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use vchSig.begin(); don't use [0] unless it's guaranteed that the length is at least 1.
EDIT: not introduced by your commit, feel free to ignore, but it apparently upsets some MSVC debug mode.
|
untested ACK |
|
tested ACK |
|
@sipa afaik the iterator isn't guaranteed to be a pointer to the element there. Added an early return instead, you ok with that? |
|
Tested ACK. (tests and a invalidate/reconsider loop back to 338221. Reindexed without checkpoints from 0 to 198k (still in progress)) Also +1 Tested ACK from an anonymous tester on IRC. |
|
ut ACK |
|
Tested ACK. As mentioned by Gavin, verified this fixes the unit tests on OSX when building with 1.0.1k |
|
Un |
|
tested ack, invalidated to 322000 reconsidered upto 327086 (still running) |
|
tested ACK, -checkpoints=0 reindexes on testnet and mainnet. |
New versions of OpenSSL will reject non-canonical DER signatures. However, it'll happily decode them. Decode then re-encode before verification in order to ensure that it is properly consumed. Github-Pull: bitcoin#5634 Rebased-From: 488ed32
Github-Pull: bitcoin#5634 Rebased-From: 8dccba6
|
This patch serves no purpose other than providing a "hack" around a flaw in the Bitcoin core. Previously OpenSSL did not look for invalid DER encoded data with possible trailing garbage but in the latest version it does. The actual problem is that Bitcoin accepts invalid DER encoded signatures and this is completely unrelated to OpenSSL. Now you are taking the invalid-DER encoded data and DER encoding it before calling ECDSA_verify. Because of this the same operation will be performed twice for every signature verification wasting CPU cycles. You MUST always DER encode your signature before passing it off to OpenSSL and this is nothing new. So this being "low" on OpenSSL's list is correct from my expert opinion as it is only performing validation and Bitcoin is passing invalid data. ECDSA_verify: |
|
@john-connor It is quite relevant in consensus systems, which must maintain bug-for-bug compatibility. It is impossible to rewind history, and un-accept signatures that have been previously accepted. |
|
@jgarzik The bug is in Bitcoin, not OpenSSL. This patch does not fix the bug. It is a hack. |
|
@jgarzik I know the blockchain is permanently flawed because of this bug but gavin and everybody else is blaming OpenSSL it seems. Accept the fact that Bitcoin core has a major flaw in that it does not DER encode signatures. This is something that could become fatal to Bitcoin in the future if OpenSSL were to further enforce it's fully understood rules. Why not fix the problem and hard fork instead of hacking the code? |
|
@john-connor "Trailing garbage" is technically incorrect. What OpenSSL's ECDSA_verify previously supported was a very broad subset of BER. For example, encoding R and S with leading zeros. This is substantive, non-backwards compatible, arguably somewhat under-disclosed (seems that you were also unaware of the actual change, in that you refer to it as "trailing garbage"), breaking API change from the existing and widely known behavior. Signatures come from the outside world (Bitcoin Core itself has never generated anything but strictly minimal encodings), and the decoding functions are OpenSSL internal. As a result previously accepted encodings (and not just 'trailing garbage') will be rejected. While this may not matter for most applications, a switch to be more conservative is not something that can be done in an uncoordinated way for a consensus system without resulting in an opening for funds loss. This is just the state of things, and not a question of "flaw" or blame. My description (http://sourceforge.net/p/bitcoin/mailman/message/33221963/) of the matter is just a statement of the facts about it. |
|
The documentation does say that.... but openssl itself seems to be calling ECDSA_SIG_new() before d2i_ECDSA_SIG. Possibly there's a memory leak in openssl itself here. |
|
@rnicoll Objectively, the current version does not leak (I tested with valgrind.) OpenSSL itself allocates first, so preserving its own behavior seemed to be conservative. The code in question appears to check the nullness of the pointer and allocates only if null, meaning the documentation is actually dangerously incorrect (since if you believed the documentation you may send uninitialized memory in there and have it fail to allocate). Thanks for noticing th documentation disagreed, previously I'd just valgrinded and checked the code. |
|
@gmaxwell Great, thanks for checking. |
|
d2i_ECDSA_SIG does indeed segfault if passed an uninitialized pointer. |
Add some defensive programming on top of bitcoin#5634. This copies the respective OpenSSL code in ECDSA_verify in OpenSSL pre-1.0.1k (e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_1j/crypto/ecdsa/ecs_vrf.c#L89) more closely. As reported by @SergioDemianLerner.
Add some defensive programming on top of #5634. This copies the respective OpenSSL code in ECDSA_verify in OpenSSL pre-1.0.1k (e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_1j/crypto/ecdsa/ecs_vrf.c#L89) more closely. As reported by @SergioDemianLerner. Github-Pull: #5640 Rebased-From: c6b7b29
Add some defensive programming on top of #5634. This copies the respective OpenSSL code in ECDSA_verify in OpenSSL pre-1.0.1k (e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_1j/crypto/ecdsa/ecs_vrf.c#L89) more closely. As reported by @SergioDemianLerner. Github-Pull: #5640 Rebased-From: c6b7b29
Add some defensive programming on top of #5634. This copies the respective OpenSSL code in ECDSA_verify in OpenSSL pre-1.0.1k (e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_1j/crypto/ecdsa/ecs_vrf.c#L89) more closely. As reported by @SergioDemianLerner. Github-Pull: #5640 Rebased-From: c6b7b29
Add some defensive programming on top of bitcoin#5634. This copies the respective OpenSSL code in ECDSA_verify in OpenSSL pre-1.0.1k (e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_1j/crypto/ecdsa/ecs_vrf.c#L89) more closely. As reported by @SergioDemianLerner. Bitcoin Github-Pull: bitcoin#5640 Rebased-From: c6b7b29
New versions of OpenSSL will reject non-canonical DER signatures. However, it'll happily decode them. Decode then re-encode before verification in order to ensure that it is properly consumed. Github-Pull: bitcoin#5634 Rebased-From: 488ed32 Conflicts: src/key.cpp cherry-picked: bitcoin@b8e81b7 bitcoin@60c51f1 bitcoin@037bfef
|
Would there be a new point release or a patch for 0.9.3? This cannot be cleanly applied to 0.9.3 as-is ( |
|
Try checking out and/or cherry-picking from the v0.9.4 tag, it has the same changes. |
|
I'll just checkout v0.9.4 then. Thanks! |
Bump to 1.0.1k and cope with its more strict DER checks.