cryptography NULL pointer deference with pkcs12.serialize_key_and_certificates when called with a non-matching certificate and private key and an hmac_hash override
Description
cryptography is a package designed to expose cryptographic primitives and recipes to Python developers. Starting in version 38.0.0 and prior to version 42.0.4, if pkcs12.serialize_key_and_certificates is called with both a certificate whose public key did not match the provided private key and an encryption_algorithm with hmac_hash set (via PrivateFormat.PKCS12.encryption_builder().hmac_hash(...), then a NULL pointer dereference would occur, crashing the Python process. This has been resolved in version 42.0.4, the first version in which a ValueError is properly raised.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Cryptography Python package <=42.0.3 crashes via NULL pointer dereference when `pkcs12.serialize_key_and_certificates` is called with a mismatched key/cert and an HMAC hash override.
A null pointer dereference vulnerability exists in the cryptography Python package (versions 38.0.0 through 42.0.3) within the pkcs12.serialize_key_and_certificates function. The bug occurs when the function is called with both a certificate whose public key does not match the provided private key and an encryption_algorithm that has an hmac_hash set via PrivateFormat.PKCS12.encryption_builder().hmac_hash(...) [1][4]. Under these conditions, the code path attempts to dereference a pointer that is null, leading to a crash of the Python process.
Exploitation requires an attacker to supply a mismatched certificate and private key pair along with a crafted encryption algorithm. In typical usage, developers or systems invoking this function (e.g., in certificate management or PKCS#12 generation) would be vulnerable if they inadvertently pass inconsistent arguments. The function does not validate the public-private key match before attempting to compute the HMAC, allowing the null pointer dereference to trigger [2][4].
The impact is a denial of service (DoS) through process termination. An attacker who can control inputs to this function could cause the Python application to crash, disrupting availability. No authentication or special privileges are required beyond the ability to call the vulnerable API endpoint. The crash is silent—no proper exception is raised, only a segmentation fault occurs [1].
The issue is resolved in version 42.0.4, where a ValueError is now raised instead of dereferencing a null pointer [2][3]. Users are strongly advised to upgrade to the patched version. No workarounds are documented; if upgrading is not possible, developers should ensure that the public key of the certificate matches the private key provided and avoid using the hmac_hash override with mismatched inputs [4].
- NVD - CVE-2024-26130
- Fixes #10422 -- don't crash when a PKCS#12 key and cert don't match by alex · Pull Request #10423 · pyca/cryptography
- advisory-database/vulns/cryptography/PYSEC-2024-225.yaml at main · pypa/advisory-database
- NULL pointer deference with pkcs12.serialize_key_and_certificates when called with a non-matching certificate and private key and an hmac_hash override
AI Insight generated on May 20, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
cryptographyPyPI | >= 38.0.0, < 42.0.4 | 42.0.4 |
Affected products
53- osv-coords52 versionspkg:apk/chainguard/azpkg:apk/chainguard/az-iamguarded-compatpkg:apk/chainguard/ggshieldpkg:apk/chainguard/kubeflow-pipelinespkg:apk/chainguard/kubeflow-pipelines-apiserverpkg:apk/chainguard/kubeflow-pipelines-cache-deployerpkg:apk/chainguard/kubeflow-pipelines-cache-deployer-compatpkg:apk/chainguard/kubeflow-pipelines-cache_serverpkg:apk/chainguard/kubeflow-pipelines-frontendpkg:apk/chainguard/kubeflow-pipelines-metadata-envoy-configpkg:apk/chainguard/kubeflow-pipelines-metadata-writerpkg:apk/chainguard/kubeflow-pipelines-metadata-writer-compatpkg:apk/chainguard/kubeflow-pipelines-persistence_agentpkg:apk/chainguard/kubeflow-pipelines-scheduledworkflowpkg:apk/chainguard/kubeflow-pipelines-viewer-crd-controllerpkg:apk/chainguard/mitmproxypkg:apk/chainguard/py3.10-cryptographypkg:apk/chainguard/py3.11-cryptographypkg:apk/chainguard/py3.12-cryptographypkg:apk/chainguard/py3-cassandra-medusapkg:apk/chainguard/py3-cassandra-medusa-compatpkg:apk/chainguard/py3-cryptographypkg:apk/chainguard/request-1276pkg:apk/chainguard/request-1276-compatpkg:apk/wolfi/azpkg:apk/wolfi/az-iamguarded-compatpkg:apk/wolfi/ggshieldpkg:apk/wolfi/kubeflow-pipelinespkg:apk/wolfi/kubeflow-pipelines-apiserverpkg:apk/wolfi/kubeflow-pipelines-cache-deployerpkg:apk/wolfi/kubeflow-pipelines-cache-deployer-compatpkg:apk/wolfi/kubeflow-pipelines-cache_serverpkg:apk/wolfi/kubeflow-pipelines-frontendpkg:apk/wolfi/kubeflow-pipelines-metadata-envoy-configpkg:apk/wolfi/kubeflow-pipelines-metadata-writerpkg:apk/wolfi/kubeflow-pipelines-metadata-writer-compatpkg:apk/wolfi/kubeflow-pipelines-persistence_agentpkg:apk/wolfi/kubeflow-pipelines-scheduledworkflowpkg:apk/wolfi/kubeflow-pipelines-viewer-crd-controllerpkg:apk/wolfi/mitmproxypkg:apk/wolfi/py3.10-cryptographypkg:apk/wolfi/py3.11-cryptographypkg:apk/wolfi/py3.12-cryptographypkg:apk/wolfi/py3-cassandra-medusapkg:apk/wolfi/py3-cassandra-medusa-compatpkg:apk/wolfi/py3-cryptographypkg:pypi/cryptographypkg:rpm/almalinux/python3.12-cryptographypkg:rpm/opensuse/python-cryptography&distro=openSUSE%20Leap%2015.5pkg:rpm/opensuse/python-cryptography&distro=openSUSE%20Leap%2015.6pkg:rpm/suse/python-cryptography&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Python%203%2015%20SP5pkg:rpm/suse/python-cryptography&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Python%203%2015%20SP6
< 2.58.0-r0+ 51 more
- (no CPE)range: < 2.58.0-r0
- (no CPE)range: < 2.58.0-r0
- (no CPE)range: < 1.25.0-r0
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 12.2.1-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 0.19.1-r1
- (no CPE)range: < 0.19.1-r1
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 0.23.0-r30
- (no CPE)range: < 0.23.0-r30
- (no CPE)range: < 2.58.0-r0
- (no CPE)range: < 2.58.0-r0
- (no CPE)range: < 1.25.0-r0
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 2.0.5-r3
- (no CPE)range: < 12.2.1-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: < 0.19.1-r1
- (no CPE)range: < 0.19.1-r1
- (no CPE)range: < 42.0.4-r0
- (no CPE)range: >= 38.0.0, < 42.0.4
- (no CPE)range: < 41.0.7-2.el9_6.1
- (no CPE)range: < 41.0.3-150400.16.15.1
- (no CPE)range: < 41.0.3-150600.23.3.1
- (no CPE)range: < 41.0.3-150400.16.15.1
- (no CPE)range: < 41.0.3-150600.23.3.1
- pyca/cryptographyv5Range: >= 38.0.0, < 42.0.4
Patches
197d231672763Fixes #10422 -- don't crash when a PKCS#12 key and cert don't match (#10423)
2 files changed · +27 −0
src/cryptography/hazmat/backends/openssl/backend.py+9 −0 modified@@ -623,6 +623,15 @@ def serialize_key_and_certificates_to_pkcs12( mac_iter, 0, ) + if p12 == self._ffi.NULL: + errors = self._consume_errors() + raise ValueError( + ( + "Failed to create PKCS12 (does the key match the " + "certificate?)" + ), + errors, + ) if ( self._lib.Cryptography_HAS_PKCS12_SET_MAC
tests/hazmat/primitives/test_pkcs12.py+18 −0 modified@@ -660,6 +660,24 @@ def test_key_serialization_encryption_set_mac_unsupported( b"name", cakey, cacert, [], algorithm ) + @pytest.mark.supported( + only_if=lambda backend: backend._lib.Cryptography_HAS_PKCS12_SET_MAC, + skip_message="Requires OpenSSL with PKCS12_set_mac", + ) + def test_set_mac_key_certificate_mismatch(self, backend): + cacert, _ = _load_ca(backend) + key = ec.generate_private_key(ec.SECP256R1()) + encryption = ( + serialization.PrivateFormat.PKCS12.encryption_builder() + .hmac_hash(hashes.SHA256()) + .build(b"password") + ) + + with pytest.raises(ValueError): + serialize_key_and_certificates( + b"name", key, cacert, [], encryption + ) + @pytest.mark.skip_fips( reason="PKCS12 unsupported in FIPS mode. So much bad crypto in it."
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-6vqw-3v5j-54x4ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-26130ghsaADVISORY
- github.com/pyca/cryptography/commit/97d231672763cdb5959a3b191e692a362f1b9e55ghsax_refsource_MISCWEB
- github.com/pyca/cryptography/pull/10423ghsax_refsource_MISCWEB
- github.com/pyca/cryptography/security/advisories/GHSA-6vqw-3v5j-54x4ghsax_refsource_CONFIRMWEB
- github.com/pypa/advisory-database/tree/main/vulns/cryptography/PYSEC-2024-225.yamlghsaWEB
News mentions
0No linked articles in our index yet.