Skip to content

Commit efd3266

Browse files
committed
Added signature input nodes to signature verify operation nodes
1 parent fca90b3 commit efd3266

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ module Signers {
236236
SignatureOperationInstance() { not this.isIntermediate() }
237237

238238
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() {
239-
result = this.getParameters().getAnAlgorithmValueConsumer()
240-
or
241239
result = SignerFlow::getNewFromUse(this, _, _)
242240
}
243241

@@ -266,7 +264,7 @@ module Signers {
266264
result.asExpr() = super.getMessageInput()
267265
}
268266

269-
override Crypto::ConsumerInputDataFlowNode getSignatureArtifactConsumer() {
267+
override Crypto::ConsumerInputDataFlowNode getSignatureConsumer() {
270268
result.asExpr() = super.getSignatureInput()
271269
}
272270

@@ -280,16 +278,6 @@ module Signers {
280278
SignerUseCall getAnUpdateCall() {
281279
result = SignerFlow::getAnIntermediateUseFromFinalUse(this, _, _)
282280
}
283-
284-
Crypto::KeyArtifactOutputInstance getKey() { result.flowsTo(this.getInitCall().getKeyArg()) }
285-
286-
Generators::KeyGenerationOperationInstance getKeyGenerationOperationInstance() {
287-
result.getKeyArtifactOutputInstance() = this.getKey()
288-
}
289-
290-
Params::ParametersInstantiation getParameters() {
291-
result = this.getKeyGenerationOperationInstance().getParameters()
292-
}
293281
}
294282
}
295283

java/ql/lib/experimental/quantum/BouncyCastle/AlgorithmInstances.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ abstract class KeyGenerationAlgorithmInstance extends Crypto::KeyOperationAlgori
150150

151151
override Crypto::PaddingAlgorithmInstance getPaddingAlgorithm() { none() }
152152

153-
// TODO: Model flow from the parameter specification to the key generator.
154153
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() { none() }
155154

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

java/ql/lib/experimental/quantum/BouncyCastle/FlowAnalysis.qll

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,42 @@ class KeyAdditionalFlowSteps extends MethodCall {
247247
DataFlow::Node getOutputNode() { result.asExpr() = this }
248248
}
249249

250+
/**
251+
* Model data flow from an ECDSA signature to the scalars r and s passed to
252+
* `verifySignature()`. The ECDSA signature is represented as a `BigInteger`
253+
* array, where the first element is the scalar r and the second element is the
254+
* scalar s.
255+
*/
256+
class ECDSASignatureAdditionalFlowSteps extends ArrayAccess {
257+
ECDSASignatureAdditionalFlowSteps() {
258+
this.getArray().getType().getName() = "BigInteger[]" and
259+
// It is reasonable to assume that the indices are integer literals
260+
this.getIndexExpr().(IntegerLiteral).getValue().toInt() = [0, 1]
261+
}
262+
263+
/**
264+
* The input node is the ECDSA signature represented as a `BigInteger` array.
265+
*/
266+
DataFlow::Node getInputNode() {
267+
// TODO: This should be the array node `this.getArray()`
268+
result.asExpr() = this.getArray()
269+
}
270+
271+
/**
272+
* The output node is the `BigInteger` element accessed by this array access.
273+
*/
274+
DataFlow::Node getOutputNode() { result.asExpr() = this }
275+
}
276+
250277
predicate additionalFlowSteps(DataFlow::Node node1, DataFlow::Node node2) {
251-
exists(KeyAdditionalFlowSteps call |
252-
node1 = call.getInputNode() and
253-
node2 = call.getOutputNode()
278+
exists(KeyAdditionalFlowSteps fs |
279+
node1 = fs.getInputNode() and
280+
node2 = fs.getOutputNode()
281+
)
282+
or
283+
exists(ECDSASignatureAdditionalFlowSteps fs |
284+
node1 = fs.getInputNode() and
285+
node2 = fs.getOutputNode()
254286
)
255287
}
256288

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,17 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
435435
final override ConsumerInputDataFlowNode getInputNode() { result = inputNode }
436436
}
437437

438+
final private class SignatureArtifactConsumer extends ArtifactConsumerAndInstance {
439+
ConsumerInputDataFlowNode inputNode;
440+
441+
SignatureArtifactConsumer() {
442+
exists(SignatureOperationInstance op | inputNode = op.getSignatureConsumer()) and
443+
this = Input::dfn_to_element(inputNode)
444+
}
445+
446+
final override ConsumerInputDataFlowNode getInputNode() { result = inputNode }
447+
}
448+
438449
/**
439450
* An artifact that is produced by an operation, representing a concrete artifact instance rather than a synthetic consumer artifact.
440451
*/
@@ -471,6 +482,8 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
471482
override DataFlowNode getOutputNode() { result = creator.getOutputArtifact() }
472483

473484
KeyOperationInstance getCreator() { result = creator }
485+
486+
KeyOperationInstance getCreator() { result = creator }
474487
}
475488

476489
/**
@@ -800,6 +813,8 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
800813
*/
801814
abstract class SignatureOperationInstance extends KeyOperationInstance {
802815
/**
816+
* Gets the consumer of the signature that is being verified in case of a
817+
* verification operation.
803818
* Gets the consumer of the signature that is being verified in case of a
804819
* verification operation.
805820
*/
@@ -1300,7 +1315,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
13001315
TKeyOperation(KeyOperationInstance e) or
13011316
TKeyOperationAlgorithm(KeyOperationAlgorithmInstanceOrValueConsumer e) or
13021317
TKeyOperationOutput(KeyOperationOutputArtifactInstance e) or
1303-
TSignature(SignatureOperationInstance e) or
13041318
// Non-Standalone Algorithms (e.g., Mode, Padding)
13051319
// These algorithms are always tied to a key operation algorithm
13061320
TModeOfOperationAlgorithm(ModeOfOperationAlgorithmInstance e) or
@@ -1547,6 +1561,20 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
15471561
override LocatableElement asElement() { result = instance }
15481562
}
15491563

1564+
/**
1565+
* A signature input. This may represent a signature, or a signature component
1566+
* such as the scalar values r and s in ECDSA.
1567+
*/
1568+
final class SignatureArtifactNode extends ArtifactNode, TSignatureInput {
1569+
SignatureArtifactConsumer instance;
1570+
1571+
SignatureArtifactNode() { this = TSignatureInput(instance) }
1572+
1573+
final override string getInternalType() { result = "SignatureInput" }
1574+
1575+
override LocatableElement asElement() { result = instance }
1576+
}
1577+
15501578
/**
15511579
* A salt input.
15521580
*/

0 commit comments

Comments
 (0)