Skip to content

Commit 6f997ae

Browse files
committed
Java: Label spurious results.
1 parent 300e48e commit 6f997ae

3 files changed

Lines changed: 3 additions & 7 deletions

File tree

java/ql/test/experimental/query-tests/quantum/examples/BadMacUse/BadMacOrderDecryptToMac.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ nodes
3232
subpaths
3333
testFailures
3434
| BadMacUse.java:92:16:92:36 | doFinal(...) : byte[] | Unexpected result: Source |
35-
| BadMacUse.java:124:42:124:51 | ciphertext | Unexpected result: Alert |

java/ql/test/experimental/query-tests/quantum/examples/BadMacUse/BadMacOrderMacOnEncryptPlaintext.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,3 @@ nodes
4444
| BadMacUse.java:146:48:146:57 | ciphertext : byte[] [[]] : Object | semmle.label | ciphertext : byte[] [[]] : Object |
4545
| BadMacUse.java:152:42:152:51 | ciphertext | semmle.label | ciphertext |
4646
subpaths
47-
testFailures
48-
| BadMacUse.java:139:79:139:90 | input : byte[] | Unexpected result: Source |
49-
| BadMacUse.java:152:42:152:51 | ciphertext | Unexpected result: Alert |

java/ql/test/experimental/query-tests/quantum/examples/BadMacUse/BadMacUse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public byte[] falsePositiveDecryptToMac(byte[] encryptionKeyBytes, byte[] macKey
121121
SecretKey macKey = new SecretKeySpec(macKeyBytes, "HmacSHA256");
122122
Mac mac = Mac.getInstance("HmacSHA256");
123123
mac.init(macKey);
124-
byte[] computedMac = mac.doFinal(ciphertext); // False Positive
124+
byte[] computedMac = mac.doFinal(ciphertext); // $ SPURIOUS: Alert[java/quantum/examples/bad-mac-order-decrypt-to-mac]
125125

126126
// Concatenate ciphertext and MAC
127127
byte[] output = new byte[ciphertext.length + computedMac.length];
@@ -136,7 +136,7 @@ public byte[] falsePositiveDecryptToMac(byte[] encryptionKeyBytes, byte[] macKey
136136
* The function decrypts THEN computes the MAC on the plaintext.
137137
* It should have the MAC computed on the ciphertext first.
138138
*/
139-
public void decryptThenMac(byte[] encryptionKeyBytes, byte[] macKeyBytes, byte[] input) throws Exception {
139+
public void decryptThenMac(byte[] encryptionKeyBytes, byte[] macKeyBytes, byte[] input) throws Exception { // $ SPURIOUS: Source[java/quantum/examples/bad-mac-order-encrypt-plaintext-also-in-mac]
140140
// Split input into ciphertext and MAC
141141
int macLength = 32; // HMAC-SHA256 output length
142142
byte[] ciphertext = Arrays.copyOfRange(input, 0, input.length - macLength);
@@ -149,7 +149,7 @@ public void decryptThenMac(byte[] encryptionKeyBytes, byte[] macKeyBytes, byte[]
149149
SecretKey macKey = new SecretKeySpec(macKeyBytes, "HmacSHA256");
150150
Mac mac = Mac.getInstance("HmacSHA256");
151151
mac.init(macKey);
152-
byte[] computedMac = mac.doFinal(ciphertext); // $ Alert[java/quantum/examples/bad-mac-order-decrypt-then-mac], False positive for Plaintext reuse
152+
byte[] computedMac = mac.doFinal(ciphertext); // $ Alert[java/quantum/examples/bad-mac-order-decrypt-then-mac] SPURIOUS: Alert[java/quantum/examples/bad-mac-order-encrypt-plaintext-also-in-mac]
153153

154154
if (!MessageDigest.isEqual(receivedMac, computedMac)) {
155155
throw new SecurityException("MAC verification failed");

0 commit comments

Comments
 (0)