Skip to content

Commit 704a06e

Browse files
committed
Crypto: Update JCA PBKDF2 modeling: 1) add further inheritance structures to make the inheritance decomposition and caveats clearer, and 2) use getConsumer to establish the hash and hmac consumer. Update the Model to expect hash node types specifically for HMAC getHashALgorithmOrUnknown.
1 parent 850c1ec commit 704a06e

File tree

2 files changed

+28
-12
lines changed
  • java/ql/lib/experimental/quantum
  • shared/quantum/codeql/quantum/experimental

2 files changed

+28
-12
lines changed

java/ql/lib/experimental/quantum/JCA.qll

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,23 +1265,39 @@ module JCAModel {
12651265
override int getFixedDigestLength() { exists(hash_name_to_type_known(hashName, result)) }
12661266
}
12671267

1268-
//TODO: handle PBE
1269-
class Pbkdf2AlgorithmStringLiteral extends KdfAlgorithmStringLiteral,
1270-
Crypto::Pbkdf2AlgorithmInstance, Crypto::HmacAlgorithmInstance
1268+
//TODO: handle PBE "with" cases
1269+
class Pbkdf2WithHmac_Pbkdf2AlgorithmInstance extends Crypto::Pbkdf2AlgorithmInstance,
1270+
KdfAlgorithmStringLiteral, // this is a parent already, but extending to have immediate access to 'getConsumer()'
1271+
Pbkdf2WithHmac_KeyOperationAlgorithmStringLiteral
12711272
{
1272-
Pbkdf2AlgorithmStringLiteral() { super.getKdfType() instanceof Crypto::PBKDF2 }
1273-
1274-
override Crypto::AlgorithmValueConsumer getHmacAlgorithmValueConsumer() { result = this }
1273+
override Crypto::AlgorithmValueConsumer getHmacAlgorithmValueConsumer() {
1274+
result = this.getConsumer()
1275+
}
1276+
}
12751277

1276-
override Crypto::AlgorithmValueConsumer getHashAlgorithmValueConsumer() { result = this }
1278+
// NOTE: must use instanceof to avoid non-monotonic recursion
1279+
class Pbkdf2WithHmac_HmacAlgorithmInstance extends Crypto::HmacAlgorithmInstance instanceof Pbkdf2WithHmac_KeyOperationAlgorithmStringLiteral
1280+
{
1281+
override Crypto::AlgorithmValueConsumer getHashAlgorithmValueConsumer() {
1282+
result = this.(KdfAlgorithmStringLiteral).getConsumer()
1283+
}
12771284

1278-
override int getKeySizeFixed() { none() }
1285+
override int getKeySizeFixed() {
1286+
// already defined by parent key operation algorithm, but extending an instance
1287+
// still requires we override this method
1288+
result = super.getKeySizeFixed()
1289+
}
12791290

1280-
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() { none() }
1291+
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() {
1292+
// already defined by parent key operation algorithm, but extending an instance
1293+
// still requires we override this method
1294+
result = super.getKeySizeConsumer()
1295+
}
12811296

12821297
override string getRawAlgorithmName() {
1283-
// Note: hard coding "hmac" since that should be the only option
1284-
result = "Hmac"
1298+
// already defined by parent key operation algorithm, but extending an instance
1299+
// still requires we override this method
1300+
result = super.getRawAlgorithmName()
12851301
}
12861302

12871303
override Crypto::KeyOpAlg::AlgorithmType getAlgorithmType() {

shared/quantum/codeql/quantum/experimental/Model.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
16331633

16341634
override string getInternalType() { result = "HMACAlgorithm" }
16351635

1636-
NodeBase getHashAlgorithmOrUnknown() {
1636+
HashAlgorithmNode getHashAlgorithmOrUnknown() {
16371637
result.asElement() = hmacInstance.getHashAlgorithmValueConsumer().getASource()
16381638
}
16391639

0 commit comments

Comments
 (0)