Skip to content

Commit b913928

Browse files
Renamed queries and merged qhelp files
1 parent bd7e7b1 commit b913928

10 files changed

+43
-88
lines changed

java/ql/src/experimental/Security/CWE/CWE-208/NonConstantTimeCheckOnSignature.qhelp

Lines changed: 0 additions & 30 deletions
This file was deleted.

java/ql/src/experimental/Security/CWE/CWE-208/NonConstantTimeCheckRecommendation.inc.qhelp

Lines changed: 0 additions & 10 deletions
This file was deleted.

java/ql/src/experimental/Security/CWE/CWE-208/NonConstantTimeCheckReferences.inc.qhelp

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
<include src="TimingAttackAgainstSignature.qhelp" />
4+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* @name Using a non-constant-time algorithm for checking a signature
2+
* @name Possible timing attack against signature validation
33
* @description When checking a signature over a message, a constant-time algorithm should be used.
44
* Otherwise, there is a risk of a timing attack that allows an attacker
55
* to forge a valid signature for an arbitrary message. For a successful attack,
66
* the attacker has to be able to send to the validation procedure both the message and the signature.
77
* @kind path-problem
88
* @problem.severity warning
99
* @precision medium
10-
* @id java/non-constant-time-in-signature-check
10+
* @id java/possible-timing-attack-against-signature
1111
* @tags security
1212
* external/cwe/cwe-208
1313
*/
@@ -18,5 +18,5 @@ import DataFlow::PathGraph
1818

1919
from DataFlow::PathNode source, DataFlow::PathNode sink, NonConstantTimeCryptoComparisonConfig conf
2020
where conf.hasFlowPath(source, sink)
21-
select sink.getNode(), source, sink, "Using a non-constant-time method for checking a $@.", source,
21+
select sink.getNode(), source, sink, "Possible timing attack against $@ validation.", source,
2222
source.getNode().(CryptoOperationSource).getCall().getResultType()

java/ql/src/experimental/Security/CWE/CWE-208/SafeMacComparison.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
public boolean check(byte[] signature, byte[] message, SecretKey key) throws Exception {
1+
public boolean validate(HttpRequest request, SecretKey key) throws Exception {
2+
byte[] message = getMessageFrom(request);
3+
byte[] signature = getSignatureFrom(request);
4+
25
Mac mac = Mac.getInstance("HmacSHA256");
36
mac.init(new SecretKeySpec(key.getEncoded(), "HmacSHA256"));
47
byte[] actual = mac.doFinal(message);

java/ql/src/experimental/Security/CWE/CWE-208/SafeMacComparisonWithRemoteInputs.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

java/ql/src/experimental/Security/CWE/CWE-208/TimingAttackAgainstSignature.qhelp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,45 @@ both the message and the signature. A successful attack can result in authentica
1111
</p>
1212
</overview>
1313

14-
<include src="NonConstantTimeCheckRecommendation.inc.qhelp" />
14+
<recommendation>
15+
<p>
16+
Use <code>MessageDigest.isEqual()</code> method to check MACs and signatures.
17+
If this method is used, then the calculation time depends only on the length of input byte arrays,
18+
and does not depend on the contents of the arrays.
19+
</p>
20+
</recommendation>
1521

1622
<example>
1723
<p>
1824
The following example uses <code>Arrays.equals()</code> method for validating a MAC over a message.
1925
This method implements a non-constant-time algorithm.
2026
Both the message and the signature come from an untrusted HTTP request:
2127
</p>
22-
<sample src="UnsafeMacComparisonWithRemoteInputs.java" />
28+
<sample src="UnsafeMacComparison.java" />
2329

2430
<p>
2531
The next example uses a safe constant-time algorithm for validating a MAC:
2632
</p>
27-
<sample src="SafeMacComparisonWithRemoteInputs.java" />
33+
<sample src="SafeMacComparison.java" />
2834
</example>
2935

30-
<include src="NonConstantTimeCheckReferences.inc.qhelp" />
36+
<references>
37+
<li>
38+
Wikipedia:
39+
<a href="https://en.wikipedia.org/wiki/Timing_attack">Timing attack</a>.
40+
</li>
41+
<li>
42+
Coursera:
43+
<a href="https://www.coursera.org/lecture/crypto/timing-attacks-on-mac-verification-FHGW1">Timing attacks on MAC verification</a>
44+
</li>
45+
<li>
46+
NCC Group:
47+
<a href="https://www.nccgroup.trust/globalassets/our-research/us/whitepapers/TimeTrial.pdf">Time Trial: Racing Towards Practical Remote Timing Attacks</a>
48+
</li>
49+
<li>
50+
Java API Specification:
51+
<a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/security/MessageDigest.html#isEqual(byte[],byte[])">MessageDigest.isEqual() method</a>
52+
</li>
53+
</references>
54+
3155
</qhelp>

java/ql/src/experimental/Security/CWE/CWE-208/UnsafeMacComparison.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
public boolean check(byte[] signature, byte[] message, SecretKey key) throws Exception {
1+
public boolean validate(HttpRequest request, SecretKey key) throws Exception {
2+
byte[] message = getMessageFrom(request);
3+
byte[] signature = getSignatureFrom(request);
4+
25
Mac mac = Mac.getInstance("HmacSHA256");
36
mac.init(new SecretKeySpec(key.getEncoded(), "HmacSHA256"));
47
byte[] actual = mac.doFinal(message);

java/ql/src/experimental/Security/CWE/CWE-208/UnsafeMacComparisonWithRemoteInputs.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)