Skip to content

Commit f825438

Browse files
committed
Python: Add MISSING: CryptographicOperationAlgorithm annotations
For RSA it's unclear what the algorithm name should even be. Signatures based on RSA private keys with PSS scheme is ok, but with pkcs#1 v1.5 they are weak/vulnerable. So clearly just putting RSA as the algorithm name is not enough information... and that problem is also why I wanted to do this commit separetely (to call extra atten to this).
1 parent 23140df commit f825438

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

python/ql/test/library-tests/frameworks/cryptodome/test_dsa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
signer = DSS.new(private_key, mode='fips-186-3')
2222

2323
hasher = SHA256.new(message) # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=message
24-
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher
24+
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher # MISSING: CryptographicOperationAlgorithm=DSA
2525

2626
print("signature={}".format(signature))
2727

@@ -30,12 +30,12 @@
3030
verifier = DSS.new(public_key, mode='fips-186-3')
3131

3232
hasher = SHA256.new(message) # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=message
33-
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature
33+
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature # MISSING: CryptographicOperationAlgorithm=DSA
3434
print("Signature verified (as expected)")
3535

3636
try:
3737
hasher = SHA256.new(b"other message") # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=b"other message"
38-
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature
38+
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature # MISSING: CryptographicOperationAlgorithm=DSA
3939
raise Exception("Signature verified (unexpected)")
4040
except ValueError:
4141
print("Signature mismatch (as expected)")

python/ql/test/library-tests/frameworks/cryptodome/test_ec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
signer = DSS.new(private_key, mode='fips-186-3')
1919

2020
hasher = SHA256.new(message) # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=message
21-
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher
21+
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher # MISSING: CryptographicOperationAlgorithm=ECDSA
2222

2323
print("signature={}".format(signature))
2424

@@ -32,7 +32,7 @@
3232

3333
try:
3434
hasher = SHA256.new(b"other message") # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=b"other message"
35-
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature
35+
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature # MISSING: CryptographicOperationAlgorithm=ECDSA
3636
raise Exception("Signature verified (unexpected)")
3737
except ValueError:
3838
print("Signature mismatch (as expected)")

python/ql/test/library-tests/frameworks/cryptodome/test_rsa.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
encrypt_cipher = PKCS1_OAEP.new(public_key)
2525

26-
encrypted = encrypt_cipher.encrypt(secret_message) # $ CryptographicOperation CryptographicOperationInput=secret_message
26+
encrypted = encrypt_cipher.encrypt(secret_message) # $ CryptographicOperation CryptographicOperationInput=secret_message # MISSING: CryptographicOperationAlgorithm=RSA-OAEP?
2727

2828
print("encrypted={}".format(encrypted))
2929

3030
print()
3131

3232
decrypt_cipher = PKCS1_OAEP.new(private_key)
3333

34-
decrypted = decrypt_cipher.decrypt(encrypted) # $ CryptographicOperation CryptographicOperationInput=encrypted
34+
decrypted = decrypt_cipher.decrypt(encrypted) # $ CryptographicOperation CryptographicOperationInput=encrypted # MISSING: CryptographicOperationAlgorithm=RSA-OAEP?
3535

3636
print("decrypted={}".format(decrypted))
3737
assert decrypted == secret_message
@@ -50,7 +50,7 @@
5050
signer = pss.new(private_key)
5151

5252
hasher = SHA256.new(message) # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=message
53-
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher
53+
signature = signer.sign(hasher) # $ CryptographicOperation CryptographicOperationInput=hasher # MISSING: CryptographicOperationAlgorithm=RSA-PSS?
5454

5555
print("signature={}".format(signature))
5656

@@ -59,13 +59,13 @@
5959
verifier = pss.new(public_key)
6060

6161
hasher = SHA256.new(message) # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=message
62-
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature
62+
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature # MISSING: CryptographicOperationAlgorithm=RSA-PSS?
6363
print("Signature verified (as expected)")
6464

6565
try:
6666
verifier = pss.new(public_key)
6767
hasher = SHA256.new(b"other message") # $ CryptographicOperation CryptographicOperationAlgorithm=SHA256 CryptographicOperationInput=b"other message"
68-
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature
68+
verifier.verify(hasher, signature) # $ CryptographicOperation CryptographicOperationInput=hasher CryptographicOperationInput=signature # MISSING: CryptographicOperationAlgorithm=RSA-PSS?
6969
raise Exception("Signature verified (unexpected)")
7070
except ValueError:
7171
print("Signature mismatch (as expected)")

0 commit comments

Comments
 (0)