Skip to content

Commit bfc8ead

Browse files
committed
Python: Add example of test-code with weak crypto key
1 parent dfa223a commit bfc8ead

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

python/ql/test/query-tests/Security/CWE-326/WeakCryptoKey.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| test_example.py:7:5:7:22 | ControlFlowNode for Attribute() | Creation of an RSA key uses $@ bits, which is below 2048 and considered breakable. | test_example.py:7:18:7:21 | ControlFlowNode for IntegerLiteral | 1024 |
12
| weak_crypto.py:68:1:68:21 | ControlFlowNode for dsa_gen_key() | Creation of an DSA key uses $@ bits, which is below 2048 and considered breakable. | weak_crypto.py:16:12:16:15 | ControlFlowNode for IntegerLiteral | 1024 |
23
| weak_crypto.py:69:1:69:19 | ControlFlowNode for ec_gen_key() | Creation of an ECC key uses $@ bits, which is below 224 and considered breakable. | weak_crypto.py:22:11:22:24 | ControlFlowNode for Attribute() | 163 |
34
| weak_crypto.py:70:1:70:28 | ControlFlowNode for rsa_gen_key() | Creation of an RSA key uses $@ bits, which is below 2048 and considered breakable. | weak_crypto.py:12:12:12:15 | ControlFlowNode for IntegerLiteral | 1024 |
@@ -7,3 +8,4 @@
78
| weak_crypto.py:76:1:76:22 | ControlFlowNode for Attribute() | Creation of an DSA key uses $@ bits, which is below 2048 and considered breakable. | weak_crypto.py:16:12:16:15 | ControlFlowNode for IntegerLiteral | 1024 |
89
| weak_crypto.py:77:1:77:22 | ControlFlowNode for Attribute() | Creation of an RSA key uses $@ bits, which is below 2048 and considered breakable. | weak_crypto.py:12:12:12:15 | ControlFlowNode for IntegerLiteral | 1024 |
910
| weak_crypto.py:84:12:84:29 | ControlFlowNode for Attribute() | Creation of an RSA key uses $@ bits, which is below 2048 and considered breakable. | weak_crypto.py:12:12:12:15 | ControlFlowNode for IntegerLiteral | 1024 |
11+
| weak_crypto.py:95:12:95:29 | ControlFlowNode for Attribute() | Creation of an RSA key uses $@ bits, which is below 2048 and considered breakable. | test_example.py:9:23:9:26 | ControlFlowNode for IntegerLiteral | 1024 |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from Cryptodome.PublicKey import RSA
2+
3+
from weak_crypto import only_used_by_test
4+
5+
def test_example():
6+
# This is technically not ok, but since it's in a test, we don't want to alert on it
7+
RSA.generate(1024)
8+
9+
only_used_by_test(1024)

python/ql/test/query-tests/Security/CWE-326/weak_crypto.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ def make_new_rsa_key_weak(bits):
8888
def make_new_rsa_key_strong(bits):
8989
return RSA.generate(bits) # OK
9090
make_new_rsa_key_strong(RSA_STRONG)
91+
92+
93+
def only_used_by_test(bits):
94+
# Although this call will technically not be ok, since it's only used in a test, we don't want to alert on it.
95+
return RSA.generate(bits)

0 commit comments

Comments
 (0)