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

(EC)DSA signature fix #670

Merged
merged 4 commits into from
Jul 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ask for signature length before allocating a buffer.
This fixes a potential heap buffer overflow that may happen when a signature
is longer than the private key, as with X9.62 ECDSA (#609).
  • Loading branch information
Jakub Zakrzewski authored and reaperhulk committed Jul 20, 2017
commit 36f8d81b1d82add6ee6dcfbc80cc50c52127c722
10 changes: 7 additions & 3 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2801,9 +2801,13 @@ def sign(pkey, data, digest):
_lib.EVP_SignInit(md_ctx, digest_obj)
_lib.EVP_SignUpdate(md_ctx, data, len(data))

pkey_length = (PKey.bits(pkey) + 7) // 8
signature_buffer = _ffi.new("unsigned char[]", pkey_length)
signature_length = _ffi.new("unsigned int*")
# obtain the length of the signature.
signature_length = _ffi.new("unsigned int[]", 1)
len_result = _lib.EVP_SignFinal(
md_ctx, _ffi.NULL, signature_length, pkey._pkey)
_openssl_assert(len_result == 1)

signature_buffer = _ffi.new("unsigned char[]", signature_length[0])
final_result = _lib.EVP_SignFinal(
md_ctx, signature_buffer, signature_length, pkey._pkey)
_openssl_assert(final_result == 1)
Expand Down