VAITP Dataset

← Back to the dataset

CVE-2020-26263

RSA PKCS#1 v1.5 decryption side-channel leakage in tlslite-ng < 0.7.6 and < 0.8.0-alpha39

  • CVSS 7.5
  • CWE-326 Inadequate Encryption Strength
  • Cryptographic
  • Remote

tlslite-ng is an open source python library that implements SSL and TLS cryptographic protocols. In tlslite-ng before versions 0.7.6 and 0.8.0-alpha39, the code that performs decryption and padding check in RSA PKCS#1 v1.5 decryption is data dependant. In particular, the code has multiple ways in which it leaks information about the decrypted ciphertext. It aborts as soon as the plaintext doesn't start with 0x00, 0x02. All TLS servers that enable RSA key exchange as well as applications that use the RSA decryption API directly are vulnerable. This is patched in versions 0.7.6 and 0.8.0-alpha39. Note: the patches depend on Python processing the individual bytes in side-channel free manner, this is known to not the case (see reference). As such, users that require side-channel resistance are recommended to use different TLS implementations, as stated in the security policy of tlslite-ng.

CVSS base score
7.5
Published
2020-12-21
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Cryptographic
Subcategory
Cryptographic Implementation Error
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
tlslite-ng
Fixed by upgrading
Yes

Solution

Update tlslite-ng to version 0.7.6 or 0.8.0-alpha39.

Vulnerable code sample

from tlslite.utils import decodePEM, RSAKey

def vulnerable_rsa_decrypt(ciphertext, private_key):
    # Decrypt the ciphertext using the RSA private key
    plaintext = private_key.decrypt(ciphertext)

    # Check the padding in a vulnerable manner
    if plaintext[0] != 0x00 or plaintext[1] != 0x02:
        # Early abort can leak information about the ciphertext
        raise ValueError("Invalid padding")

    # Further processing of the plaintext...
    return plaintext

# Example usage
private_key = RSAKey()  # Load or generate your RSA private key
ciphertext = b'...'  # Encrypted data
plaintext = vulnerable_rsa_decrypt(ciphertext, private_key)

Patched code sample

from tlslite.utils import decodePEM, RSAKey
from tlslite import TLSConnection

def safe_rsa_decrypt(ciphertext, private_key):
    # This is a mock function to represent safe decryption without side-channel leaks.
    # The actual implementation should ensure constant-time operations.

    # Decrypt the ciphertext using the RSA private key
    plaintext = private_key.decrypt(ciphertext)

    # Check the padding in a side-channel resistant manner
    if not is_valid_pkcs1v15_padding(plaintext):
        raise ValueError("Invalid padding")

    return plaintext

def is_valid_pkcs1v15_padding(plaintext):
    # Implement a constant-time check for PKCS#1 v1.5 padding
    if len(plaintext) < 11:
        return False

    # Check the first byte is 0x00, the second byte is 0x02, and the padding bytes are non-zero
    if plaintext[0] != 0x00 or plaintext[1] != 0x02:
        return False

    # Ensure padding bytes are non-zero
    padding_length = plaintext[2]
    if padding_length < 8 or any(b == 0 for b in plaintext[3:3 + padding_length]):
        return False

    return True

# Example usage
private_key = RSAKey()  # Load or generate your RSA private key
ciphertext = b'...'  # Encrypted

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.

  • stop conversion from bytes to int to bytes with m2crypto (tlsfuzzer/tlslite-ng)
    tlslite/utils/openssl_rsakey.py, tlslite/utils/rsakey.py, tlslite/utils/rsakey.py · RSAKey.decrypt, tlslite/utils/rsakey.py · RSAKey.encrypt, tlslite/utils/rsakey.py · RSAKey.RSASSA_PSS_sign, tlslite/utils/rsakey.py · RSAKey.RSASSA_PSS_verify, tlslite/utils/rsakey.py · RSAKey._raw_pkcs1_sign, tlslite/utils/rsakey.py · RSAKey._raw_pkcs1_verify

Cite this entry

@misc{vaitp:cve202026263,
  title        = {{RSA PKCS#1 v1.5 decryption side-channel leakage in tlslite-ng < 0.7.6 and < 0.8.0-alpha39}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-26263},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-26263/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.