From 19db013fa66fb4eb38e105e7fd46599aad51bf30 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 12 Apr 2019 23:36:20 -0400 Subject: Fixes #4830 -- handle negative serial numbers (#4843) --- src/cryptography/hazmat/backends/openssl/backend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index 74dedbe0..ee864137 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -334,7 +334,10 @@ class Backend(object): bin_len = self._lib.BN_bn2bin(bn, bin_ptr) # A zero length means the BN has value 0 self.openssl_assert(bin_len >= 0) - return int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big") + val = int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big") + if self._lib.BN_is_negative(bn): + val = -val + return val else: # Under Python 2 the best we can do is hex() hex_cdata = self._lib.BN_bn2hex(bn) -- cgit v1.2.3