Skip to content

Commit 66a6029

Browse files
committed
Merge branch 'brodes/cipher_operation' into brodes/elliptic_curves
2 parents ac96649 + 5050758 commit 66a6029

File tree

3 files changed

+24
-53
lines changed

3 files changed

+24
-53
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ module JCAModel {
573573
src.asExpr() instanceof CipherGetInstanceCall
574574
}
575575

576-
predicate isSink(DataFlow::Node sink, FlowState state) { none() }
576+
predicate isSink(DataFlow::Node sink, FlowState state) { none() } // TODO: document this, but this is intentional (avoid cross products?)
577577

578578
predicate isSink(DataFlow::Node sink) {
579579
exists(CipherOperationCall c | c.getQualifier() = sink.asExpr())
@@ -914,7 +914,7 @@ module JCAModel {
914914
type instanceof Crypto::TAsymmetricKeyType
915915
}
916916

917-
override DataFlow::Node getOutputKeyArtifact() { result.asExpr() = this }
917+
override Crypto::ArtifactOutputDataFlowNode getOutputKeyArtifact() { result.asExpr() = this }
918918

919919
override Crypto::KeyArtifactType getOutputKeyType() { result = type }
920920

@@ -1271,7 +1271,7 @@ module JCAModel {
12711271
result.asExpr() = this.getInstantiation().getIterationCountArg()
12721272
}
12731273

1274-
override DataFlow::Node getOutputKeyArtifact() {
1274+
override Crypto::ArtifactOutputDataFlowNode getOutputKeyArtifact() {
12751275
result.asExpr() = this and
12761276
super.getMethod().getReturnType().hasName("SecretKey")
12771277
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,5 @@ module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
199199

200200
module GenericDataSourceUniversalFlow = TaintTracking::Global<GenericDataSourceUniversalFlowConfig>;
201201

202-
/*
203-
* class LiteralOrGenericDataSource extends Element {
204-
* DataFlow::Node node;
205-
*
206-
* LiteralOrGenericDataSource() {
207-
* node = this.(Crypto::GenericSourceInstance).getOutputNode() or
208-
* node.asExpr() = this.(Literal)
209-
* }
210-
*
211-
* bindingset[other]
212-
* predicate localFlowsTo(DataFlow::Node other) { DataFlow::localFlow(node, other) }
213-
* }
214-
*/
215-
216202
// Import library-specific modeling
217203
import JCA

shared/cryptography/codeql/cryptography/Model.qll

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
4141
ConsumerElement getConsumer() { result.getInputNode() = this }
4242
}
4343

44+
class ArtifactOutputDataFlowNode extends DataFlowNode {
45+
OutputArtifactInstance getArtifact() { result.getOutputNode() = this }
46+
}
47+
4448
final class UnknownPropertyValue extends string {
4549
UnknownPropertyValue() { this = "<unknown>" }
4650
}
@@ -461,7 +465,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
461465
this = Input::dfn_to_element(inputNode)
462466
}
463467

464-
override KeyArtifactType getKeyType() { result instanceof TUnknownKeyType }
468+
override KeyArtifactType getKeyType() { result instanceof TUnknownKeyType } // A consumer node does not have a key type, refer to source (TODO: refine, should this be none())
465469

466470
final override ConsumerInputDataFlowNode getInputNode() { result = inputNode }
467471
}
@@ -674,7 +678,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
674678
/**
675679
* Gets the key artifact produced by this operation.
676680
*/
677-
abstract DataFlowNode getOutputKeyArtifact();
681+
abstract ArtifactOutputDataFlowNode getOutputKeyArtifact();
678682

679683
/**
680684
* Gets the key artifact type produced.
@@ -924,29 +928,8 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
924928
predicate isExcludedFromGraph() { none() }
925929
}
926930

927-
signature string getDefaultValueSig();
928-
929-
signature ConsumerInputDataFlowNode getConsumerSig();
930-
931-
signature class NodeBaseSig instanceof NodeBase;
932-
933-
module PropertyOutput<getDefaultValueSig/0 getDefault, getConsumerSig/0 getConsumer> {
934-
bindingset[root]
935-
predicate get(NodeBase root, string value, Location location) {
936-
if not exists(getDefault()) and not exists(getConsumer().getConsumer().getASource())
937-
then value instanceof UnknownPropertyValue and location instanceof UnknownLocation
938-
else (
939-
if exists(getDefault())
940-
then
941-
value = "Default:" + getDefault() and
942-
location = root.getLocation()
943-
else node_as_property(getConsumer().getConsumer().getAGenericSourceNode(), value, location)
944-
)
945-
}
946-
}
947-
948931
/**
949-
* A generic source node is a source of data that is not resolvable to a specific value or type.
932+
* A generic source node is a source of data that is not resolvable to a specific asset.
950933
*/
951934
private class GenericSourceNode extends NodeBase, TGenericSourceNode {
952935
GenericSourceInstance instance;
@@ -982,7 +965,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
982965
* Holds if `node` is a potential candidate for a known algorithm node.
983966
* This predicate should be used to restrict the set of candidate algorithm node types.
984967
*/
985-
abstract predicate isCandidateKnownAlgorithmNode(AlgorithmNode node);
968+
abstract predicate isCandidateAlgorithmNode(AlgorithmNode node);
986969

987970
/**
988971
* Gets the algorithm or generic source nodes consumed as an algorithm associated with this operation.
@@ -994,12 +977,12 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
994977
}
995978

996979
/**
997-
* Gets a known algorithm associated with this operation, subject to `isCandidateKnownAlgorithmNode`.
980+
* Gets a known algorithm associated with this operation, subject to `isCandidateAlgorithmNode`.
998981
*/
999982
AlgorithmNode getAKnownAlgorithm() {
1000983
result =
1001984
this.asElement().(OperationInstance).getAnAlgorithmValueConsumer().getAKnownSourceNode() and
1002-
this.isCandidateKnownAlgorithmNode(result)
985+
this.isCandidateAlgorithmNode(result)
1003986
}
1004987

1005988
override NodeBase getChild(string edgeName) {
@@ -1173,9 +1156,11 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
11731156
// [KNOWN_OR_UNKNOWN] - only if asymmetric
11741157
edgeName = "Algorithm" and
11751158
instance.getKeyType() instanceof TAsymmetricKeyType and
1176-
if exists(this.getAKnownAlgorithmOrGenericSourceNode())
1177-
then result = this.getAKnownAlgorithmOrGenericSourceNode()
1178-
else result = this
1159+
(
1160+
if exists(this.getAKnownAlgorithmOrGenericSourceNode())
1161+
then result = this.getAKnownAlgorithmOrGenericSourceNode()
1162+
else result = this
1163+
)
11791164
}
11801165

11811166
override predicate properties(string key, string value, Location location) {
@@ -1243,7 +1228,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
12431228

12441229
override LocatableElement asElement() { result = instance }
12451230

1246-
override predicate isCandidateKnownAlgorithmNode(AlgorithmNode node) {
1231+
override predicate isCandidateAlgorithmNode(AlgorithmNode node) {
12471232
node instanceof MACAlgorithmNode
12481233
}
12491234

@@ -1318,7 +1303,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
13181303

13191304
KeyGenerationOperationNode() { keyGenInstance = instance }
13201305

1321-
override predicate isCandidateKnownAlgorithmNode(AlgorithmNode node) {
1306+
override predicate isCandidateAlgorithmNode(AlgorithmNode node) {
13221307
node instanceof CipherAlgorithmNode
13231308
}
13241309

@@ -1352,7 +1337,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
13521337
result.asElement() = kdfInstance.getOutputKeySizeConsumer().getConsumer().getAGenericSource()
13531338
}
13541339

1355-
override predicate isCandidateKnownAlgorithmNode(AlgorithmNode node) {
1340+
override predicate isCandidateAlgorithmNode(AlgorithmNode node) {
13561341
node instanceof KeyDerivationAlgorithmNode
13571342
}
13581343

@@ -1611,7 +1596,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
16111596

16121597
override string getInternalType() { result = "CipherOperation" }
16131598

1614-
override predicate isCandidateKnownAlgorithmNode(AlgorithmNode node) {
1599+
override predicate isCandidateAlgorithmNode(AlgorithmNode node) {
16151600
node instanceof CipherAlgorithmNode
16161601
}
16171602

@@ -1930,7 +1915,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
19301915
type instanceof SM4 and name = "SM4" and s = Block()
19311916
or
19321917
type instanceof OtherCipherType and
1933-
name instanceof UnknownPropertyValue and
1918+
name instanceof UnknownPropertyValue and // TODO: get rid of this hack to bind structure and type
19341919
s = UnknownCipherStructureType()
19351920
}
19361921

@@ -1985,7 +1970,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
19851970

19861971
override LocatableElement asElement() { result = instance }
19871972

1988-
override predicate isCandidateKnownAlgorithmNode(AlgorithmNode node) {
1973+
override predicate isCandidateAlgorithmNode(AlgorithmNode node) {
19891974
node instanceof HashAlgorithmNode
19901975
}
19911976

0 commit comments

Comments
 (0)