Skip to main content

Inadequate Encryption Strength Using Weak Keys in SSLContext

PY019
inadequate_encryption_strength
CWE-326
⚠️ Warning

Using weak key sizes for cryptographic algorithms like Elliptic Curve can compromise the security of your encryption and digital signatures. Here's a brief overview of the risks associated with weak key sizes for this algorithm:

Elliptic Curve cryptography provides strong security with relatively small key sizes compared to RSA and DSA. However, even in the case of EC, using weak curve parameters or small key sizes can expose you to vulnerabilities. The strength of an EC key depends on the curve's properties and the size of the prime used.

Recommended EC key sizes depend on the curve you select, but for modern applications, curves like NIST P-256 (secp256r1) with a 256-bit key size are considered secure. Larger curves, like NIST P-384 or P-521, can provide even higher security margins.

Example


warning
import ssl


context = ssl.SSLContext()
context.set_ecdh_curve("prime192v1")

Remediation


Fix Iconfix

Its recommended to increase the key size to at least 224 EC algorithms.

import ssl


context = ssl.SSLContext()
context.set_ecdh_curve("prime256v1")

False Positives


In the case of a false positive the rule can be suppressed. Simply add a trailing or preceding comment line with either the rule ID (PY019) or rule category name (inadequate_encryption_strength).

Fix Iconfix
import ssl


context = ssl.SSLContext()
# suppress: PY019
context.set_ecdh_curve("prime192v1")

See also