Skip to content

Commit

Permalink
Cherry-Pick fix for CVE-2023-49083 from (pyca#9927)
Browse files Browse the repository at this point in the history
* Fixed crash when loading a PKCS#7 bundle with no certificates (pyca#9926)
pyca#9926
  • Loading branch information
icanhasmath committed Jan 18, 2024
1 parent 82b6ce2 commit 25c123c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

.. _v3-3-2-1:

3.3.2.1 - 2024-01-18
~~~~~~~~~~~~~~~~~~~~

* Fixed a null-pointer-dereference and segfault that could occur when loading
certificates from a PKCS#7 bundle. Credit to **pkuzco** for reporting the
issue. **CVE-2023-49083**

.. _v3-3-2:

3.3.2 - 2021-02-07
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ decrypted
decrypting
deprecations
DER
dereference
deserialize
deserialized
Deserialization
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
__uri__ = "https://github.com/pyca/cryptography"

__version__ = "3.3.2"
__version__ = "3.3.2.1"

__author__ = "The cryptography developers"
__email__ = "cryptography-dev@python.org"
Expand Down
5 changes: 4 additions & 1 deletion src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2664,9 +2664,12 @@ def _load_pkcs7_certificates(self, p7):
_Reasons.UNSUPPORTED_SERIALIZATION,
)

certs = []
if p7.d.sign == self._ffi.NULL:
return certs

sk_x509 = p7.d.sign.cert
num = self._lib.sk_X509_num(sk_x509)
certs = []
for i in range(num):
x509 = self._lib.sk_X509_value(sk_x509, i)
self.openssl_assert(x509 != self._ffi.NULL)
Expand Down
6 changes: 6 additions & 0 deletions tests/hazmat/primitives/test_pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def test_load_pkcs7_unsupported_type(self):
mode="rb",
)

def test_load_pkcs7_empty_certificates(self, backend):
der = b"\x30\x0B\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x07\x02"

certificates = pkcs7.load_der_pkcs7_certificates(der)
assert certificates == []


# We have no public verification API and won't be adding one until we get
# some requirements from users so this function exists to give us basic
Expand Down
2 changes: 1 addition & 1 deletion vectors/cryptography_vectors/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

__uri__ = "https://github.com/pyca/cryptography"

__version__ = "3.3.2"
__version__ = "3.3.2.1"

__author__ = "The cryptography developers"
__email__ = "cryptography-dev@python.org"
Expand Down

0 comments on commit 25c123c

Please sign in to comment.