summaryrefslogtreecommitdiff
path: root/src/OpenSSL/crypto.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2017-07-20 10:45:54 +0200
committerHynek Schlawack <hs@ox.cx>2017-07-20 10:45:54 +0200
commit59d26251efd8a2a08abd9029018194430f7f25ca (patch)
tree79a33413aaf11648d18f988e23d81456e52f4b26 /src/OpenSSL/crypto.py
parent8102128e6ad83dcbb3567dd372cdd39c9a8fab44 (diff)
downloadpyopenssl-59d26251efd8a2a08abd9029018194430f7f25ca.tar.gz
(EC)DSA signature fix (#670)
* Write a test - signatures with EC keys (#609) * 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). * change approach to EVP_PKEY_size and add changelog * add a small assert
Diffstat (limited to 'src/OpenSSL/crypto.py')
-rw-r--r--src/OpenSSL/crypto.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py
index 20cf183..4f7e4d8 100644
--- a/src/OpenSSL/crypto.py
+++ b/src/OpenSSL/crypto.py
@@ -2801,9 +2801,10 @@ 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*")
+ length = _lib.EVP_PKEY_size(pkey._pkey)
+ _openssl_assert(length > 0)
+ signature_buffer = _ffi.new("unsigned char[]", length)
+ signature_length = _ffi.new("unsigned int *")
final_result = _lib.EVP_SignFinal(
md_ctx, signature_buffer, signature_length, pkey._pkey)
_openssl_assert(final_result == 1)