PYSEC-2024-225: 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

Published Feb 21, 2024
·
Updated

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.serializekeyandcertificates is called with both a certificate whose public key did not match the provided private key and an encryptionalgorithm with hmachash set (via PrivateFormat.PKCS12.encryptionbuilder().hmachash(...), 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.

Affected Software

1 affected component
pypi/cryptography>=38.0.0<42.0.4

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade cryptography to a version that resolves this vulnerability.

    Fixed in 42.0.4

Event History

Feb 21, 2024
CVE Published
via OSV·04:28 PM
Data Sourced
via OSV·04:28 PM
DescriptionSeverityWeakness

Frequently Asked Questions

1

Which deployments are affected?

Applications using pypi/cryptography versions 38.0.0 through versions before 42.0.4 are affected, but only when they call pkcs12.serialize_key_and_certificates with a certificate and private key that do not match and configure an encryption algorithm with an hmac_hash override.

2

What does an attacker need to trigger the issue?

The vulnerable call must receive a non-matching certificate and private key, and the caller must use PrivateFormat.PKCS12.encryption_builder().hmac_hash(...) to set hmac_hash. Under those conditions, the call can crash the Python process through a NULL pointer dereference.

3

Is a default PKCS#12 serialization configuration affected?

The issue requires an hmac_hash override on the encryption algorithm. The provided information does not indicate that serialization without this override is affected.

4

What is the remediation and expected behavior after updating?

Update cryptography to version 42.0.4 or later. In 42.0.4, this invalid certificate/private-key combination properly raises ValueError rather than dereferencing a NULL pointer and crashing the process.

5

How can teams identify potentially affected code paths?

Review calls to pkcs12.serialize_key_and_certificates for code that accepts or constructs both a certificate and private key, and look specifically for encryption configuration using PrivateFormat.PKCS12.encryption_builder().hmac_hash(...). Such paths should ensure the certificate public key matches the supplied private key.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203