Skip to content

Commit ca1d4e2

Browse files
committed
Crypto: Separating out an IntLiteral class so it is clearer that some constraints for generic input sources are heuristics to filter sources, and other constraints narrow the literals to a general type (ints). Also adding fixes in KnownAlgorithmConstants to classify some algorithms as key exchange and signature correctly, and added support for a signature constant wrapper.
1 parent 570fdeb commit ca1d4e2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/GenericSourceCandidateLiteral.qll

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import cpp
22
private import semmle.code.cpp.models.Models
33
private import semmle.code.cpp.models.interfaces.FormattingFunction
44

5+
private class IntLiteral extends Literal {
6+
IntLiteral() {
7+
//Heuristics for distinguishing int literals from other literals
8+
exists(this.getValue().toInt()) and
9+
not this instanceof CharLiteral and
10+
not this instanceof StringLiteral
11+
}
12+
}
13+
514
/**
615
* Holds if a StringLiteral could conceivably be used in some way for cryptography.
716
* Note: this predicate should only consider restrictions with respect to strings only.
@@ -38,15 +47,11 @@ private predicate isOpenSSLStringLiteralGenericSourceCandidate(StringLiteral s)
3847
}
3948

4049
/**
41-
* Holds if an IntLiteral could be an algorithm literal.
50+
* Holds if a StringLiteral could conceivably be used in some way for cryptography.
4251
* Note: this predicate should only consider restrictions with respect to integers only.
4352
* General restrictions are in the OpenSSLGenericSourceCandidateLiteral class.
4453
*/
45-
private predicate isOpenSSLIntLiteralGenericSourceCandidate(Literal l) {
46-
exists(l.getValue().toInt()) and
47-
// Ignore char literals
48-
not l instanceof CharLiteral and
49-
not l instanceof StringLiteral and
54+
private predicate isOpenSSLIntLiteralGenericSourceCandidate(IntLiteral l) {
5055
// Ignore integer values of 0, commonly referring to NULL only (no known algorithm 0)
5156
l.getValue().toInt() != 0 and
5257
// ASSUMPTION, no negative numbers are allowed
@@ -86,10 +91,10 @@ private predicate isOpenSSLIntLiteralGenericSourceCandidate(Literal l) {
8691
}
8792

8893
/**
89-
* Any literal that may represent an algorithm for use in an operation, even if an invalid or unknown algorithm.
94+
* Any literal that may be conceivably be used in some way for cryptography.
9095
* The set of all literals is restricted by this class to cases where there is higher
91-
* plausibility that the literal is eventually used as an algorithm.
92-
* Literals are filtered, for example if they are used in a way no indicative of an algorithm use
96+
* plausibility that the literal could be used as a source of configuration.
97+
* Literals are filtered, for example, if they are used in a way no indicative of an algorithm use
9398
* such as in an array index, bitwise operation, or logical operation.
9499
* Note a case like this:
95100
* if(algVal == "AES")

0 commit comments

Comments
 (0)