Skip to content

Commit ae574f7

Browse files
committed
Resolving hash and cipher types for openssl not using literals but KnownOpenSSLAlgorithmConstant.
1 parent f72efa6 commit ae574f7

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

cpp/ql/lib/experimental/Quantum/OpenSSL/EVPCipherAlgorithmSource.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import OpenSSLAlgorithmGetter
99
* If the literal does not represent any known cipher algorithm,
1010
* this predicate will not hold (i.e., it will not bind an unknown to an unknown cipher type)
1111
*/
12-
predicate literalToCipherFamilyType(Literal e, Crypto::TCipherType type) {
13-
exists(string name, string algType | algType.toLowerCase().matches("%encryption") |
14-
resolveAlgorithmFromLiteral(e, name, algType) and
12+
predicate knownOpenSSLConstantToCipherFamilyType(KnownOpenSSLAlgorithmConstant e, Crypto::TCipherType type) {
13+
exists(string name | e.getAlgType().toLowerCase().matches("%encryption") |
14+
name = e.getNormalizedName() and
1515
(
1616
name.matches("AES%") and type instanceof Crypto::AES
1717
or
@@ -97,5 +97,9 @@ class KnownOpenSSLCipherConstantAlgorithmInstance extends Crypto::CipherAlgorith
9797

9898
override string getRawAlgorithmName() { result = this.(Literal).getValue().toString() }
9999

100-
override Crypto::TCipherType getCipherFamily() { literalToCipherFamilyType(this, result) }
101-
}
100+
override Crypto::TCipherType getCipherFamily() {
101+
knownOpenSSLConstantToCipherFamilyType(this, result)
102+
or
103+
not knownOpenSSLConstantToCipherFamilyType(this, _) and result = Crypto::OtherCipherType()
104+
}
105+
}

cpp/ql/lib/experimental/Quantum/OpenSSL/EVPHashAlgorithmSource.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import cpp
22
import experimental.Quantum.Language
33
import OpenSSLAlgorithmGetter
44

5-
predicate literalToHashFamilyType(Literal e, Crypto::THashType type) {
6-
exists(string name, string algType | algType.toLowerCase().matches("hash") |
7-
resolveAlgorithmFromLiteral(e, name, algType) and
5+
predicate knownOpenSSLConstantToHashFamilyType(KnownOpenSSLAlgorithmConstant e, Crypto::THashType type) {
6+
exists(string name | e.getAlgType().toLowerCase().matches("hash") |
7+
name = e.getNormalizedName() and
88
(
99
name.matches("BLAKE2B") and type instanceof Crypto::BLAKE2B
1010
or
@@ -70,7 +70,10 @@ class KnownOpenSSLHashConstantAlgorithmInstance extends Crypto::HashAlgorithmIns
7070
AlgGetterToAlgConsumerFlow::flow(getterCall.getResultNode(), DataFlow::exprNode(result))
7171
}
7272

73-
override Crypto::THashType getHashFamily() { literalToHashFamilyType(this, result) }
73+
override Crypto::THashType getHashFamily() {
74+
knownOpenSSLConstantToHashFamilyType(this, result) or
75+
not knownOpenSSLConstantToHashFamilyType(this, _) and result = Crypto::OtherHashType()
76+
}
7477

7578
override string getRawAlgorithmName() { result = this.(Literal).getValue().toString() }
7679

0 commit comments

Comments
 (0)