CVE-2020-25659
Python-cryptography 3.2 vulnerable to Bleichenbacher timing attacks in RSA decryption due to PKCS#1 v1.5 ciphertext timing differences
- CVSS 5.9
- CWE-385 Covert Timing Channel
- Cryptographic
- Remote
python-cryptography 3.2 is vulnerable to Bleichenbacher timing attacks in the RSA decryption API, via timed processing of valid PKCS#1 v1.5 ciphertext.
- CVSS base score
- 5.9
- Published
- 2021-01-11
- OWASP
- A02 Cryptographic Failures
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Timing Issues
- Category
- Cryptographic
- Subcategory
- Cryptographic Implementation Error
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- python-cryptography
- Fixed by upgrading
- Yes
Solution
Update python-cryptography to version 3.4.
Vulnerable code sample
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa, padding
def vulnerable_rsa_decrypt(private_key, ciphertext):
try:
# Directly decrypting without constant-time checks can lead to timing attacks
plaintext = private_key.decrypt(
ciphertext,
padding.PKCS1v15()
)
return plaintext
except Exception as e:
# Different exceptions may lead to timing discrepancies
return None
# Example usage
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
# Simulated ciphertext (should be a valid PKCS#1 v1.5 ciphertext)
ciphertext = b'...' # Replace with actual ciphertext
plaintext = vulnerable_rsa_decrypt(private_key, ciphertext)Patched code sample
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import utils
from cryptography.exceptions import InvalidSignature
def safe_rsa_decrypt(private_key, ciphertext):
try:
# Use a constant-time comparison to avoid timing attacks
plaintext = private_key.decrypt(
ciphertext,
padding.PKCS1v15()
)
return plaintext
except Exception as e:
# Handle exceptions in a way that does not leak timing information
return None
# Example usage
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
# Simulated ciphertext (should be a valid PKCS#1 v1.5 ciphertext)
ciphertext = b'...' # Replace with actual ciphertext
plaintext = safe_rsa_decrypt(private_key, ciphertext)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Attempt to mitigate Bleichenbacher attacks on RSA decryption (pyca/cryptography)
src/cryptography/hazmat/backends/openssl/rsa.py,src/cryptography/hazmat/backends/openssl/rsa.py · _enc_dec_rsa_pkey_ctx
Cite this entry
@misc{vaitp:cve202025659,
title = {{Python-cryptography 3.2 vulnerable to Bleichenbacher timing attacks in RSA decryption due to PKCS#1 v1.5 ciphertext timing differences}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-25659},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-25659/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
