Skip to content

Commit f524de4

Browse files
committed
Crypto: Updating insecure iv/nonce to consider if an operation is known for it, and if so do not alert on non-secure random if it is tied to decryption
1 parent 7a57496 commit f524de4

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

java/ql/src/experimental/quantum/Analysis/InsecureIVorNonceSource.ql

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* @name Insecure nonce/iv (static value or weak random source)
33
* @id java/quantum/insecure-iv-or-nonce
44
* @description A nonce/iv is generated from a source that is not secure. This can lead to
5-
* vulnerabilities such as replay attacks or key recovery.
5+
* vulnerabilities such as replay attacks or key recovery. Insecure generation
6+
* is any static nonce, or any known insecure source for a nonce/iv if
7+
* the value is used for an encryption operation (decryption operations are ignored
8+
* as the nonce/iv would be provided alongside the ciphertext).
69
* @kind problem
710
* @problem.severity error
811
* @precision high
@@ -12,8 +15,33 @@
1215

1316
import experimental.quantum.Language
1417

15-
from Crypto::NonceArtifactNode nonce, Crypto::NodeBase src
18+
from Crypto::NonceArtifactNode nonce, Crypto::NodeBase src, Crypto::NodeBase op, string msg
1619
where
1720
nonce.getSourceNode() = src and
18-
not src.asElement() instanceof SecureRandomnessInstance
19-
select nonce, "Nonce or IV uses insecure or constant source $@", src, src.toString()
21+
(
22+
// Case 1: Any constant nonce/iv is bad, regardless of how it is used
23+
src.asElement() instanceof Crypto::GenericConstantSourceInstance and
24+
op = nonce and // binding op by not using it
25+
msg = "Nonce or IV uses constant source $@"
26+
or
27+
// Case 2: The nonce has a non-random source and there is no known operation for the nonce
28+
// assume it is used for encryption
29+
not src.asElement() instanceof SecureRandomnessInstance and
30+
not src.asElement() instanceof Crypto::GenericConstantSourceInstance and
31+
not exists(Crypto::CipherOperationNode o | o.getANonce() = nonce) and
32+
op = nonce and // binding op, but not using it
33+
msg =
34+
"Nonce or IV uses insecure source $@ with no observed nonce usage (assuming could be for encryption)."
35+
or
36+
// Case 3: The nonce has a non-random source and is used in an encryption operation
37+
not src.asElement() instanceof SecureRandomnessInstance and
38+
not src.asElement() instanceof Crypto::GenericConstantSourceInstance and
39+
op.(Crypto::CipherOperationNode).getANonce() = nonce and
40+
(
41+
op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TEncryptMode
42+
or
43+
op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TWrapMode
44+
) and
45+
msg = "Nonce or IV uses insecure source $@ at encryption operation $@"
46+
)
47+
select nonce, msg, src, src.toString(), op, op.toString()
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| InsecureIVorNonceSource.java:20:51:20:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:14:21:14:81 | Constant | Constant |
2-
| InsecureIVorNonceSource.java:49:51:49:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:42:21:42:21 | Constant | Constant |
3-
| InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:57:13:57:62 | Constant | Constant |
4-
| InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:58:13:58:63 | Constant | Constant |
5-
| InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:73:13:73:73 | Constant | Constant |
6-
| InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:74:13:74:74 | Constant | Constant |
7-
| InsecureIVorNonceSource.java:206:51:206:56 | Nonce | Nonce or IV uses insecure or constant source $@ | InsecureIVorNonceSource.java:194:26:194:30 | RandomNumberGeneration | RandomNumberGeneration |
1+
| InsecureIVorNonceSource.java:20:51:20:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:14:21:14:81 | Constant | Constant | InsecureIVorNonceSource.java:20:51:20:56 | Nonce | Nonce |
2+
| InsecureIVorNonceSource.java:49:51:49:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:42:21:42:21 | Constant | Constant | InsecureIVorNonceSource.java:49:51:49:56 | Nonce | Nonce |
3+
| InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:57:13:57:62 | Constant | Constant | InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce |
4+
| InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:58:13:58:63 | Constant | Constant | InsecureIVorNonceSource.java:65:51:65:56 | Nonce | Nonce |
5+
| InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:73:13:73:73 | Constant | Constant | InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce |
6+
| InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce or IV uses constant source $@ | InsecureIVorNonceSource.java:74:13:74:74 | Constant | Constant | InsecureIVorNonceSource.java:81:51:81:56 | Nonce | Nonce |
7+
| InsecureIVorNonceSource.java:206:51:206:56 | Nonce | Nonce or IV uses insecure source $@ at encryption operation $@ | InsecureIVorNonceSource.java:194:26:194:30 | RandomNumberGeneration | RandomNumberGeneration | InsecureIVorNonceSource.java:208:16:208:31 | EncryptOperation | EncryptOperation |

0 commit comments

Comments
 (0)