Skip to content

Commit f6cf98b

Browse files
thomas-serre-sonarsourcesonartech
authored andcommitted
SONARPY-2801 TLS cipher suite: Cover PyOpenSSL methods
GitOrigin-RevId: 60bae9f06836f7341467edadd8b349fff03a2004
1 parent da6107f commit f6cf98b

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

python-checks/src/main/java/org/sonar/python/checks/RobustCipherAlgorithmCheck.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public class RobustCipherAlgorithmCheck extends PythonSubscriptionCheck {
6969
"DEFAULT@SECLEVEL=1"
7070
);
7171

72-
public static final String SSL_SET_CIPHERS_FQN = "ssl.SSLContext.set_ciphers";
72+
public static final Set<String> SSL_SET_CIPHERS_FQN = Set.of(
73+
"ssl.SSLContext.set_ciphers",
74+
"OpenSSL.SSL.Context.set_cipher_list"
75+
);
7376

7477
private static final Set<String> SENSITIVE_CALLEE_FQNS = Set.of(
7578
"Crypto.Cipher.ARC2.new",
@@ -110,7 +113,7 @@ private static void checkCallExpression(SubscriptionContext subscriptionContext)
110113
.ifPresent(fullyQualifiedName -> {
111114
if (SENSITIVE_CALLEE_FQNS.contains(fullyQualifiedName) || INSECURE_CIPHERS_PREFIXES.stream().anyMatch(fullyQualifiedName::startsWith)) {
112115
subscriptionContext.addIssue(callExpr.callee(), MESSAGE);
113-
} else if (SSL_SET_CIPHERS_FQN.equals(fullyQualifiedName)) {
116+
} else if (SSL_SET_CIPHERS_FQN.contains(fullyQualifiedName)) {
114117
checkForInsecureCiphers(subscriptionContext, callExpr);
115118
}
116119
});

python-checks/src/test/resources/checks/robustCipherAlgorithm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ def pyssl_examples():
134134
ctx.set_ciphers(ciphers6) # Noncompliant
135135
# ^^^^^^^^^^^^^^^
136136

137+
def py_open_ssl_examples():
138+
import socket
139+
from OpenSSL import SSL
140+
141+
ctx = SSL.Context(SSL.TLS1_3_VERSION)
142+
ctx.set_cipher_list(b"@SECLEVEL=0") # Noncompliant
143+
# ^^^^^^^^^^^^^^^^^^^
144+
145+
ciphers2 = b'ECDHE:RSA:AES256:LOW:ECDHE-RSA-AES256-SHA'
146+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^> {{The following cipher strings are insecure: `LOW`, `SHA`}}
147+
ctx.set_cipher_list(ciphers2) # Noncompliant
148+
# ^^^^^^^^^^^^^^^^^^^
149+
137150
def pycryptodome_compliant():
138151
from Crypto.Cipher import AES
139152
key = b'Sixteen byte key'

python-frontend/typeshed_serializer/resources/custom/OpenSSL/SSL.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VERIFY_NONE: int
66

77
class Context(CustomStubBase):
88
def set_verify(self, *args, **kwargs) -> None: ...
9-
9+
def set_cipher_list(self, *args, **kwargs) -> None: ...
1010

1111
class Connection(CustomStubBase):
1212
...

0 commit comments

Comments
 (0)