Skip to content

Commit 3dc28c2

Browse files
committed
Move language-agnostic model to shared library
1 parent cd70acd commit 3dc28c2

File tree

7 files changed

+34
-26
lines changed

7 files changed

+34
-26
lines changed

cpp/ql/lib/experimental/Quantum/Language.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
private import Base
1+
private import codeql.cryptography.Model
22
private import cpp as Lang
33

44
module CryptoInput implements InputSig<Lang::Location> {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ module OpenSSLModel {
7777

7878
HKDF() { algorithmStringToKDFFetchArgFlow("HKDF", origin, this) }
7979

80+
override string getRawAlgorithmName() { result = origin.getValue() }
81+
8082
override Crypto::HashAlgorithm getHashAlgorithm() { none() }
8183

8284
override Crypto::LocatableElement getOrigin(string name) {
@@ -89,6 +91,8 @@ module OpenSSLModel {
8991

9092
PKCS12KDF() { algorithmStringToKDFFetchArgFlow("PKCS12KDF", origin, this) }
9193

94+
override string getRawAlgorithmName() { result = origin.getValue() }
95+
9296
override Crypto::HashAlgorithm getHashAlgorithm() { none() }
9397

9498
override Crypto::NodeBase getOrigin(string name) {

cpp/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extractor: cpp
66
library: true
77
upgrades: upgrades
88
dependencies:
9+
codeql/cryptography: ${workspace}
910
codeql/dataflow: ${workspace}
1011
codeql/mad: ${workspace}
1112
codeql/rangeanalysis: ${workspace}

cpp/ql/src/experimental/Quantum/cbom.sh renamed to misc/scripts/cryptography/cbom.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
CODEQL_PATH="/Users/nicolaswill/Library/Application Support/Code/User/globalStorage/github.vscode-codeql/distribution5/codeql/codeql"
44
DATABASE_PATH="/Users/nicolaswill/openssl_codeql/openssl/openssl_db"
5-
QUERY_FILE="CBOMGraph.ql"
5+
QUERY_FILE="/Users/nicolaswill/pqc/codeql/cpp/ql/src/experimental/Quantum/CBOMGraph.ql"
66
OUTPUT_DIR="graph_output"
77

88
python3 generate_cbom.py -c "$CODEQL_PATH" -d "$DATABASE_PATH" -q "$QUERY_FILE" -o "$OUTPUT_DIR"

cpp/ql/lib/experimental/Quantum/Base.qll renamed to shared/cryptography/codeql/cryptography/Model.qll

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
9494
*/
9595
abstract string getAlgorithmName();
9696

97-
/**
97+
/**
9898
* Gets the raw name of this algorithm from source (no parsing or formatting)
9999
*/
100100
abstract string getRawAlgorithmName();
@@ -151,7 +151,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
151151
abstract THashType getHashType();
152152

153153
override string getAlgorithmName() { this.hashTypeToNameMapping(this.getHashType(), result) }
154-
155154
}
156155

157156
/**
@@ -199,26 +198,23 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
199198
}
200199

201200
newtype TEllipticCurveFamilyType =
202-
// We're saying by this that all of these have an identical interface / properties / edges
203-
NIST() or
204-
SEC() or
205-
NUMS() or
206-
PRIME() or
207-
BRAINPOOL() or
208-
CURVE25519() or
209-
CURVE448() or
210-
C2() or
211-
SM2() or
212-
ES() or
213-
OtherEllipticCurveFamilyType()
214-
201+
// We're saying by this that all of these have an identical interface / properties / edges
202+
NIST() or
203+
SEC() or
204+
NUMS() or
205+
PRIME() or
206+
BRAINPOOL() or
207+
CURVE25519() or
208+
CURVE448() or
209+
C2() or
210+
SM2() or
211+
ES() or
212+
OtherEllipticCurveFamilyType()
215213

216214
/**
217215
* Elliptic curve algorithm
218216
*/
219217
abstract class EllipticCurve extends Algorithm {
220-
221-
222218
abstract string getKeySize(Location location);
223219

224220
abstract TEllipticCurveFamilyType getCurveFamilyType();
@@ -235,18 +231,18 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
235231
// other properties, like field type are possible, but not modeled until considered necessary
236232
}
237233

238-
override string getAlgorithmName() { result = this.getRawAlgorithmName().toUpperCase()}
234+
override string getAlgorithmName() { result = this.getRawAlgorithmName().toUpperCase() }
239235

240236
/**
241237
* Mandating that for Elliptic Curves specifically, users are responsible
242-
* for providing as the 'raw' name, the official name of the algorithm.
243-
* Casing doesn't matter, we will enforce further naming restrictions on
244-
* `getAlgorithmName` by default.
238+
* for providing as the 'raw' name, the official name of the algorithm.
239+
* Casing doesn't matter, we will enforce further naming restrictions on
240+
* `getAlgorithmName` by default.
245241
* Rationale: elliptic curve names can have a lot of variation in their components
246242
* (e.g., "secp256r1" vs "P-256"), trying to produce generalized set of properties
247-
* is possible to capture all cases, but such modeling is likely not necessary.
248-
* if all properties need to be captured, we can reassess how names are generated.
243+
* is possible to capture all cases, but such modeling is likely not necessary.
244+
* if all properties need to be captured, we can reassess how names are generated.
249245
*/
250-
override abstract string getRawAlgorithmName();
246+
abstract override string getRawAlgorithmName();
251247
}
252248
}

shared/cryptography/qlpack.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: codeql/cryptography
2+
version: 0.0.0-dev
3+
groups: shared
4+
library: true
5+
dependencies:
6+
codeql/util: ${workspace}
7+
warnOnImplicitThis: true

0 commit comments

Comments
 (0)