Skip to content

Commit b564724

Browse files
committed
Crypto: Alterations to OpenSSL cipher algorithms to use new fixed keysize predicate.
1 parent 1baf6d6 commit b564724

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ class KnownOpenSSLCipherConstantAlgorithmInstance extends OpenSSLAlgorithmInstan
104104

105105
override string getRawAlgorithmName() { result = this.(Literal).getValue().toString() }
106106

107-
override string getKeySizeFixed() {
108-
exists(int keySize |
109-
this.(KnownOpenSSLCipherAlgorithmConstant).getExplicitKeySize() = keySize and
110-
result = keySize.toString()
111-
)
107+
override int getKeySizeFixed() {
108+
this.(KnownOpenSSLCipherAlgorithmConstant).getExplicitKeySize() = result
112109
}
113110

114111
override Crypto::KeyOpAlg::Algorithm getAlgorithmType() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ module JCAModel {
353353
else result instanceof KeyOpAlg::TUnknownKeyOperationAlgorithmType
354354
}
355355

356-
override string getKeySizeFixed() {
356+
override int getKeySizeFixed() {
357357
none() // TODO: implement to handle variants such as AES-128
358358
}
359359

@@ -1104,7 +1104,7 @@ module JCAModel {
11041104
KeyGeneratorFlowAnalysisImpl::getInitFromUse(this, _, _).getKeySizeArg() = result.asExpr()
11051105
}
11061106

1107-
override string getKeySizeFixed() { none() }
1107+
override int getKeySizeFixed() { none() }
11081108
}
11091109

11101110
class KeyGeneratorCipherAlgorithm extends CipherStringLiteralAlgorithmInstance {
@@ -1310,7 +1310,7 @@ module JCAModel {
13101310
result.asExpr() = this.getKeySpecInstantiation().(PBEKeySpecInstantiation).getKeyLengthArg()
13111311
}
13121312

1313-
override string getKeySizeFixed() { none() }
1313+
override int getKeySizeFixed() { none() }
13141314

13151315
override string getOutputKeySizeFixed() { none() }
13161316

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
841841
* This will be automatically inferred and applied at the node level.
842842
* See `fixedImplicitCipherKeySize`.
843843
*/
844-
abstract string getKeySizeFixed();
844+
abstract int getKeySizeFixed();
845845

846846
/**
847847
* Gets a consumer for the key size in bits specified for this algorithm variant.
@@ -1044,7 +1044,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
10441044
abstract KeyArtifactType getOutputKeyType();
10451045

10461046
// Defaults or fixed values
1047-
string getKeySizeFixed() { none() }
1047+
int getKeySizeFixed() { none() }
10481048

10491049
// Consumer input nodes
10501050
abstract ConsumerInputDataFlowNode getKeySizeConsumer();
@@ -1900,7 +1900,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
19001900
or
19011901
// [ONLY_KNOWN]
19021902
key = "DefaultKeySize" and
1903-
value = kdfInstance.getKeySizeFixed() and
1903+
value = kdfInstance.getKeySizeFixed().toString() and
19041904
location = this.getLocation()
19051905
or
19061906
// [ONLY_KNOWN] - TODO: refactor for known unknowns
@@ -2259,13 +2259,10 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
22592259
/**
22602260
* Gets the key size variant of this algorithm in bits, e.g., 128 for "AES-128".
22612261
*/
2262-
string getKeySizeFixed() {
2262+
int getKeySizeFixed() {
22632263
result = instance.asAlg().getKeySizeFixed()
22642264
or
2265-
exists(int size |
2266-
KeyOpAlg::fixedImplicitCipherKeySize(instance.asAlg().getAlgorithmType(), size) and
2267-
result = size.toString()
2268-
)
2265+
KeyOpAlg::fixedImplicitCipherKeySize(instance.asAlg().getAlgorithmType(), result)
22692266
}
22702267

22712268
/**
@@ -2333,7 +2330,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
23332330
// [ONLY_KNOWN]
23342331
key = "KeySize" and
23352332
(
2336-
value = this.getKeySizeFixed() and
2333+
value = this.getKeySizeFixed().toString() and
23372334
location = this.getLocation()
23382335
or
23392336
node_as_property(this.getKeySize(), value, location)

0 commit comments

Comments
 (0)