blob: ddab86e21a7a959e45a1b7292560548c29ad2d3b [file] [log] [blame] [edit]
From f09c261ca10a31fe41b1262306db7f8f1da0e48a Mon Sep 17 00:00:00 2001
From: Michael Kochera <kochera@google.com>
Date: Mon, 27 Nov 2023 14:35:35 -0500
Subject: [PATCH] Fix CVE-2023-49083
* Fixed crash when loading a PKCS#7 bundle with no certificates (#9926)
* Temporarily allow a new clippy warning (#9835)
* Temporarily allow a new clippy warning
* Update lib.rs
* Update lib.rs
* Need to accept this to skip test
* It's a word
---
docs/spelling_wordlist.txt | 1 +
src/cryptography/hazmat/backends/openssl/backend.py | 5 ++++-
src/rust/src/lib.rs | 2 ++
tests/hazmat/primitives/test_pkcs7.py | 6 ++++++
4 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index 62a62fb96e3..74642f324e6 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -38,6 +38,7 @@ decrypted
decrypting
deprecations
DER
+dereference
deserialize
deserialized
Deserialization
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index 02d51094cfe..f1c79008b68 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -2466,9 +2466,12 @@ def _load_pkcs7_certificates(self, p7) -> typing.List[x509.Certificate]:
_Reasons.UNSUPPORTED_SERIALIZATION,
)
+ certs: list[x509.Certificate] = []
+ 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)
diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs
index 4d88e2813b5..b58fa316ea0 100644
--- a/src/rust/src/lib.rs
+++ b/src/rust/src/lib.rs
@@ -3,6 +3,8 @@
// for complete details.
#![deny(rust_2018_idioms)]
+// Work-around for https://github.com/PyO3/pyo3/issues/3561
+#![allow(unknown_lints, clippy::unnecessary_fallible_conversions)]
// Temporarily allow `clippy::borrow_deref_ref` until we can upgrade to the
// latest pyo3: https://github.com/PyO3/pyo3/pull/2503
//
diff --git a/tests/hazmat/primitives/test_pkcs7.py b/tests/hazmat/primitives/test_pkcs7.py
index 172cf40bd6e..f6ad64151cb 100644
--- a/tests/hazmat/primitives/test_pkcs7.py
+++ b/tests/hazmat/primitives/test_pkcs7.py
@@ -88,6 +88,12 @@ def test_load_pkcs7_unsupported_type(self, backend):
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