Skip to content

Add CodeQL Quantum models and queries (Java, C++) to experimental #19469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 133 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
395d54b
Create Base.qll
nicolaswill Jan 23, 2025
1a7d8cb
WIP
nicolaswill Jan 24, 2025
7836234
WIP: hash types example and documentation
nicolaswill Jan 24, 2025
e027b0e
WIP: add properties
nicolaswill Jan 28, 2025
0cd3df9
Concepts for elliptic cureve and misc. updates.
bdrodes Jan 29, 2025
9af18bc
WIP: add dgml/dot output/remove test code
nicolaswill Jan 29, 2025
69a6385
Update CBOMGraph.ql
nicolaswill Jan 29, 2025
5f355c7
Add first sample JCA encryption model
knewbury01 Feb 4, 2025
86e51da
Improve JCA aes alg model, add test
knewbury01 Feb 5, 2025
efcf7ea
Add broken crypto query
knewbury01 Feb 5, 2025
cd70acd
Merge pull request #1 from nicolaswill/brodes/experiments
nicolaswill Feb 6, 2025
2e12bb5
Merge branch 'nic/crypto-test' into knewbury01/JCA-sample
knewbury01 Feb 6, 2025
3dc28c2
Move language-agnostic model to shared library
nicolaswill Feb 6, 2025
7a96f56
Merge pull request #3 from nicolaswill/nicolaswill/shared-crypto-library
nicolaswill Feb 6, 2025
60d931a
Update progress on JCA
knewbury01 Feb 7, 2025
6005437
Update JCA model with flow to call as AESuse and format JCA model
knewbury01 Feb 10, 2025
9c8ade7
Merge branch 'nic/crypto-test' into knewbury01/JCA-sample
knewbury01 Feb 10, 2025
59208bd
Update JCA model to use shared lib
knewbury01 Feb 10, 2025
1a12fb3
Update JCA model, refactor modes
knewbury01 Feb 10, 2025
4d44755
Refactor Model and CBOM print queries
nicolaswill Feb 11, 2025
874e3b5
Modify model to use newtypes, expand modeling
nicolaswill Feb 12, 2025
b777a22
Expand model and specialize newtype relations
nicolaswill Feb 14, 2025
df01fa7
Expand model and JCA modeling
nicolaswill Feb 16, 2025
8707e4d
Continue Artifact data-flow WIP
nicolaswill Feb 18, 2025
3871c6a
Adding support for encryption operation detection.
bdrodes Feb 18, 2025
9ee4a7a
Adding a sketch for a CipherOperation concept to model encryption/dec…
bdrodes Feb 20, 2025
83dc5b9
Fixing type bug
bdrodes Feb 20, 2025
011ed3f
Simplifying additional flow step logic.
bdrodes Feb 20, 2025
9ac9252
Adding a todo
bdrodes Feb 20, 2025
86cab46
Misc. updates to support all JCA cipher operations, including wrap, u…
bdrodes Feb 21, 2025
2b0b927
Add Nonce association to Operation, update graph
nicolaswill Feb 24, 2025
eb91ecf
Add generic artifact data-flow
nicolaswill Feb 25, 2025
f55f27b
Expand handling of generic artifact sources
nicolaswill Feb 25, 2025
04f4683
Rewrite handling of known unknowns and data-flow
nicolaswill Feb 27, 2025
ef0614a
Restore removed node location output
nicolaswill Feb 27, 2025
0354afc
Make ArtifactConsumers instances of some Artifacts
nicolaswill Feb 27, 2025
cf33cf7
Add input and output nodes and fix cross product
nicolaswill Feb 28, 2025
627790f
Clean up consumer and instance interfaces
nicolaswill Mar 3, 2025
076f531
Proof-of-concept query for InsecureOrUnknownNonceAtOperation
bdrodes Mar 3, 2025
14cb2bb
Updates to insecure or unknown nonce at operation.
bdrodes Mar 3, 2025
2ee1681
Adding a proof-of-concept PossibleReusedNonce query.
bdrodes Mar 3, 2025
8865d89
Removing old ReusedNonce query.
bdrodes Mar 3, 2025
cce5f24
Initial OpenSSL modeling work.
bdrodes Mar 4, 2025
de3ff45
Misc updates for OpenSSL modeling to trace algorithm literals to know…
bdrodes Mar 5, 2025
6083df2
Completed tying algorithm instances to consumers. Now the model shoul…
bdrodes Mar 5, 2025
b9bd199
Regression fixes for JCA
bdrodes Mar 6, 2025
32d29ff
Changed casing on TCipherType, Added some initial fixes for hash supp…
bdrodes Mar 7, 2025
cf72fde
Fixing cross product in getPropertyAsGraphString (parameter `root` no…
bdrodes Mar 7, 2025
47affa0
Restore location output for nodes
nicolaswill Mar 7, 2025
bac0a63
Initial hash models for openssl.
bdrodes Mar 7, 2025
64241ca
Merge branch 'brodes/cipher_operation' of https://github.com/nicolasw…
bdrodes Mar 7, 2025
d99812a
Adding GOSTHash to THashType.
bdrodes Mar 10, 2025
3316d61
Ctx flow comments.
bdrodes Mar 10, 2025
6a4659f
Updating known constants for OpenSSL to handle direct algorithm gette…
bdrodes Mar 10, 2025
bd07b8a
Making getter flow through 'copy' more general (copy can appear in an…
bdrodes Mar 10, 2025
4518086
Getting rid of commented out code.
bdrodes Mar 10, 2025
0672027
Tracing new notion of known getters, which now includes direct getter…
bdrodes Mar 10, 2025
73368ea
Adding hashes to openssl library import
bdrodes Mar 10, 2025
fe52351
Stubbing out hash operation node, borrowing from cipher operaiton node
bdrodes Mar 10, 2025
036035b
Adding modeling for OpenSSL random number generation.
bdrodes Mar 10, 2025
c83cb53
Adding an instantiation of the additional flow step class to automati…
bdrodes Mar 10, 2025
f72efa6
Uncommenting out generic dataflow
bdrodes Mar 10, 2025
ae574f7
Resolving hash and cipher types for openssl not using literals but Kn…
bdrodes Mar 11, 2025
f69b057
Updating OpenSSLKnownAlgorithmConstants.qll (a few bugs) and also enf…
bdrodes Mar 11, 2025
085e8d4
Hash nodes have instances.
bdrodes Mar 11, 2025
44b1e92
commenting out hash size for now, TODO
bdrodes Mar 11, 2025
7757279
Adding a KDF algorithm getter.
bdrodes Mar 11, 2025
d988afd
Adding an EVP_AASYM_CIPHER_fetch getter.
bdrodes Mar 11, 2025
a9458ba
Formatting, removing dead comments,
bdrodes Mar 11, 2025
c98e6d7
Adding a stub EVP_CIpher_Operation for EVP_PKEY, this probably should…
bdrodes Mar 11, 2025
71eae39
Adding missing block modes.
bdrodes Mar 11, 2025
8a7671d
Adding block mode models to openssl.
bdrodes Mar 11, 2025
95607c5
Refactor instances and consumers + add JCA hashes
nicolaswill Mar 18, 2025
63aaebb
.
bdrodes Mar 19, 2025
d18dac0
Add JCA key (generation) modelling
nicolaswill Mar 20, 2025
b695641
Add signature to cipher operation
bdrodes Mar 20, 2025
9278a41
Merge branch 'brodes/cipher_operation' of https://github.com/nicolasw…
bdrodes Mar 20, 2025
fb7c003
Add initial MAC support for JCA, refactor hashes
nicolaswill Mar 22, 2025
e9c3e14
Merge branch 'brodes/cipher_operation' of https://github.com/nicolasw…
nicolaswill Mar 22, 2025
9cd0340
Remove rankdir=LR; from DOT output
nicolaswill Mar 26, 2025
bec69ca
Refactor consumer and generic source model
nicolaswill Mar 26, 2025
ac96649
Misc. modifications to support elliptic curves and hooking them up to…
bdrodes Apr 1, 2025
5050758
Refactor output artifact type
nicolaswill Apr 2, 2025
66a6029
Merge branch 'brodes/cipher_operation' into brodes/elliptic_curves
bdrodes Apr 2, 2025
697c9f0
Elliptic curve AVCs are incorrect, but I'm not sure how to fix them g…
bdrodes Apr 4, 2025
69429a3
Merge pull request #9 from nicolaswill/brodes/elliptic_curves
bdrodes Apr 4, 2025
a2fe19a
Initial progress on key agreement.
bdrodes Apr 4, 2025
b9d0abd
Move CipherOperation into KeyOperation, refactor
nicolaswill Apr 9, 2025
1958c19
Reimplement EC, MAC, key creation logic + consumer
nicolaswill Apr 16, 2025
28ccc83
Adding a means to distinguish asymmetric algorithms.
bdrodes Apr 28, 2025
fdd09a4
Adding a new means for determining if there is nonce reuse.
bdrodes Apr 28, 2025
7b7ed61
Adding an asymmetric algorithm slice.
bdrodes Apr 28, 2025
1fd7643
Adding example slicing queries.
bdrodes Apr 28, 2025
5a8bffa
Removing old asymmetric algorithm slice
bdrodes Apr 28, 2025
ce3eabf
Updating model to support slicing.
bdrodes Apr 28, 2025
219476c
Adding KDF iteration count inventory filters.
bdrodes Apr 28, 2025
ac3675b
Typo fix
bdrodes Apr 28, 2025
ac798f2
Cipher Algorithm Slices
bdrodes Apr 28, 2025
7f24a25
Add modelling for JCA key gen cipher algorithm
nicolaswill Apr 30, 2025
9c87ad8
Merge branch 'brodes/key_agreement' of https://github.com/nicolaswill…
nicolaswill Apr 30, 2025
dd2f53f
Merge pull request #10 from nicolaswill/brodes/key_agreement
nicolaswill Apr 30, 2025
2b1b90c
Merge pull request #4 from nicolaswill/brodes/cipher_operation
nicolaswill Apr 30, 2025
27c7bf3
Merge branch 'github:main' into crypto-test
nicolaswill Apr 30, 2025
83617e0
Merge pull request #2 from nicolaswill/knewbury01/JCA-sample
nicolaswill Apr 30, 2025
c80588c
Adding content to KnownSymmetricCipherAlgorithmql.
bdrodes Apr 30, 2025
5694f02
Misc. cleanup
bdrodes May 2, 2025
c08525a
Additional cleanup
bdrodes May 2, 2025
7481de7
Updating the model to infer implicit cipher key sizes.
bdrodes May 2, 2025
09d4736
Working refactor for cipher, padding, block mode. Still haven't compl…
bdrodes May 2, 2025
9463293
Clean up
bdrodes May 2, 2025
0a0be41
Intermediate progress towards getting hashing upgraded. Still need to…
bdrodes May 2, 2025
4042081
Missing files, should have been part of last commit.
bdrodes May 2, 2025
f5a3656
Merge pull request #11 from nicolaswill/brodes/openssl_refactor
nicolaswill May 7, 2025
56670c6
Revert Python changes and delete implementation
nicolaswill May 7, 2025
314f1ff
Refactor Java directory structure
nicolaswill May 7, 2025
c19291b
Refactor 'cryptography' and 'Quantum' to 'quantum'
nicolaswill May 7, 2025
ac72abd
Refactor directory structure (shared experimental)
nicolaswill May 8, 2025
7339dd0
Rename "Quantum" to "quantum" in dir structure
nicolaswill May 8, 2025
0066f74
Delete development scripts
nicolaswill May 8, 2025
a7ebe4a
Fix typo in asymmetric inventory slice query id
nicolaswill May 8, 2025
e956d04
Format LibraryDetector.qll
nicolaswill May 8, 2025
1d8a57e
Fix EVP Cipher class, predicate, and comment typos
nicolaswill May 8, 2025
1135fbe
Fix EVP_Hash_Initializer typo
nicolaswill May 8, 2025
0c6e124
Delete development test query
nicolaswill May 8, 2025
986c8e1
Change Java inventory slices to @kind table
nicolaswill May 8, 2025
b558e84
Update slice query metadata and output tables
nicolaswill May 8, 2025
b8c3b43
Fix KnownAsymmetricAlgorithm query id
nicolaswill May 8, 2025
e03f57d
Update type name in experimental BrokenCrypto.ql
nicolaswill May 8, 2025
a57f4a1
Update Java analysis query metadata
nicolaswill May 8, 2025
529128c
Add problem.severity for java analysis queries
nicolaswill May 8, 2025
d0510bc
Merge branch 'main' into quantum-experimental
nicolaswill May 8, 2025
c607794
Update cpp and java not_included_in_qls.expected
nicolaswill May 8, 2025
64e4071
Merge branch 'quantum-experimental' of https://github.com/nicolaswill…
nicolaswill May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ ql/cpp/ql/src/experimental/cryptography/inventory/new_models/SigningAlgorithms.q
ql/cpp/ql/src/experimental/cryptography/inventory/new_models/SymmetricEncryptionAlgorithms.ql
ql/cpp/ql/src/experimental/cryptography/inventory/new_models/SymmetricPaddingAlgorithms.ql
ql/cpp/ql/src/experimental/cryptography/inventory/new_models/UnknownAsymmetricKeyGeneration.ql
ql/cpp/ql/src/experimental/quantum/PrintCBOMGraph.ql
ql/cpp/ql/src/external/examples/filters/BumpMetricBy10.ql
ql/cpp/ql/src/external/examples/filters/EditDefectMessage.ql
ql/cpp/ql/src/external/examples/filters/ExcludeGeneratedCode.ql
Expand Down
113 changes: 113 additions & 0 deletions cpp/ql/lib/experimental/quantum/Language.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import codeql.experimental.quantum.Model
import semmle.code.cpp.dataflow.new.DataFlow

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
OpenSSL.OpenSSL
.
private import cpp as Lang

module CryptoInput implements InputSig<Lang::Location> {
class DataFlowNode = DataFlow::Node;

class LocatableElement = Lang::Locatable;

class UnknownLocation = Lang::UnknownDefaultLocation;

LocatableElement dfn_to_element(DataFlow::Node node) {
result = node.asExpr() or
result = node.asParameter() or
result = node.asVariable()
}

string locationToFileBaseNameAndLineNumberString(Location location) {
result = location.getFile().getBaseName() + ":" + location.getStartLine()
}

predicate artifactOutputFlowsToGenericInput(
DataFlow::Node artifactOutput, DataFlow::Node otherInput
) {
ArtifactFlow::flow(artifactOutput, otherInput)
}
}

module Crypto = CryptographyBase<Lang::Location, CryptoInput>;

module ArtifactFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
}

predicate isSink(DataFlow::Node sink) {
sink = any(Crypto::FlowAwareElement other).getInputNode()
}

predicate isBarrierOut(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getInputNode()
}

predicate isBarrierIn(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getOutputNode()
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
node1.(AdditionalFlowInputStep).getOutput() = node2
}
}

module ArtifactFlow = DataFlow::Global<ArtifactFlowConfig>;

/**
* Artifact output to node input configuration
*/

Check warning

Code scanning / CodeQL

Class QLDoc style. Warning

The QLDoc for a class should start with 'A', 'An', or 'The'.
abstract class AdditionalFlowInputStep extends DataFlow::Node {
abstract DataFlow::Node getOutput();

final DataFlow::Node getInput() { result = this }
}

/**
* Generic data source to node input configuration
*/
module GenericDataSourceFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source = any(Crypto::GenericSourceInstance i).getOutputNode()
}

predicate isSink(DataFlow::Node sink) {
sink = any(Crypto::FlowAwareElement other).getInputNode()
}

predicate isBarrierOut(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getInputNode()
}

predicate isBarrierIn(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getOutputNode()
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
node1.(AdditionalFlowInputStep).getOutput() = node2
}
}

module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
}

predicate isSink(DataFlow::Node sink) {
sink = any(Crypto::FlowAwareElement other).getInputNode()
}

predicate isBarrierOut(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getInputNode()
}

predicate isBarrierIn(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getOutputNode()
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
node1.(AdditionalFlowInputStep).getOutput() = node2
}
}

module ArtifactUniversalFlow = DataFlow::Global<ArtifactUniversalFlowConfig>;

import OpenSSL.OpenSSL
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import cpp
import semmle.code.cpp.dataflow.new.DataFlow
import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers

/**
* Traces 'known algorithms' to AVCs, specifically
* algorithms that are in the set of known algorithm constants.
* Padding-specific consumers exist that have their own values that
* overlap with the known algorithm constants.
* Padding consumers (specific padding consumers) are excluded from the set of sinks.
*/
module KnownOpenSSLAlgorithmToAlgorithmValueConsumerConfig implements DataFlow::ConfigSig {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLAlgorithmToAlgorithmValueConsumerConfig should be PascalCase/camelCase.
predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof KnownOpenSSLAlgorithmConstant
}

predicate isSink(DataFlow::Node sink) {
exists(OpenSSLAlgorithmValueConsumer c |
c.getInputNode() = sink and
not c instanceof PaddingAlgorithmValueConsumer
)
}

predicate isBarrier(DataFlow::Node node) {
// False positive reducer, don't flow out through argv
exists(VariableAccess va, Variable v |
v.getAnAccess() = va and va = node.asExpr()
or
va = node.asIndirectExpr()
|
v.getName().matches("%argv")
)
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
knownPassThroughStep(node1, node2)
}
}

module KnownOpenSSLAlgorithmToAlgorithmValueConsumerFlow =

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLAlgorithmToAlgorithmValueConsumerFlow should be PascalCase/camelCase.
DataFlow::Global<KnownOpenSSLAlgorithmToAlgorithmValueConsumerConfig>;

module RSAPaddingAlgorithmToPaddingAlgorithmValueConsumerConfig implements DataFlow::ConfigSig {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in RSAPaddingAlgorithmToPaddingAlgorithmValueConsumerConfig should be PascalCase/camelCase.
predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof KnownOpenSSLAlgorithmConstant
}

predicate isSink(DataFlow::Node sink) {
exists(PaddingAlgorithmValueConsumer c | c.getInputNode() = sink)
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
knownPassThroughStep(node1, node2)
}
}

module RSAPaddingAlgorithmToPaddingAlgorithmValueConsumerFlow =

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in RSAPaddingAlgorithmToPaddingAlgorithmValueConsumerFlow should be PascalCase/camelCase.
DataFlow::Global<RSAPaddingAlgorithmToPaddingAlgorithmValueConsumerConfig>;

class OpenSSLAlgorithmAdditionalFlowStep extends AdditionalFlowInputStep {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in OpenSSLAlgorithmAdditionalFlowStep should be PascalCase/camelCase.
OpenSSLAlgorithmAdditionalFlowStep() { exists(AlgorithmPassthroughCall c | c.getInNode() = this) }

override DataFlow::Node getOutput() {
exists(AlgorithmPassthroughCall c | c.getInNode() = this and c.getOutNode() = result)
}
}

abstract class AlgorithmPassthroughCall extends Call {
abstract DataFlow::Node getInNode();

abstract DataFlow::Node getOutNode();
}

class CopyAndDupAlgorithmPassthroughCall extends AlgorithmPassthroughCall {
DataFlow::Node inNode;
DataFlow::Node outNode;

CopyAndDupAlgorithmPassthroughCall() {
// Flow out through any return or other argument of the same type
// Assume flow in and out is asIndirectExpr or asDefinitingArgument since a pointer is assumed
// to be involved
// NOTE: not attempting to detect openssl specific copy/dup functions, but anything suspected to be copy/dup
this.getTarget().getName().toLowerCase().matches(["%_dup%", "%_copy%"]) and
exists(Expr inArg, Type t |
inArg = this.getAnArgument() and t = inArg.getUnspecifiedType().stripType()
|
inNode.asIndirectExpr() = inArg and
(
// Case 1: flow through another argument as an out arg of the same type
exists(Expr outArg |
outArg = this.getAnArgument() and
outArg != inArg and
outArg.getUnspecifiedType().stripType() = t
|
outNode.asDefiningArgument() = outArg
)
or
// Case 2: flow through the return value if the result is the same as the intput type
exists(Expr outArg | outArg = this and outArg.getUnspecifiedType().stripType() = t |
outNode.asIndirectExpr() = outArg
)
)
)
}

override DataFlow::Node getInNode() { result = inNode }

override DataFlow::Node getOutNode() { result = outNode }
}

class NIDToPointerPassthroughCall extends AlgorithmPassthroughCall {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in NIDToPointerPassthroughCall should be PascalCase/camelCase.
DataFlow::Node inNode;
DataFlow::Node outNode;

NIDToPointerPassthroughCall() {
this.getTarget().getName() in ["OBJ_nid2obj", "OBJ_nid2ln", "OBJ_nid2sn"] and
inNode.asExpr() = this.getArgument(0) and
outNode.asExpr() = this
//outNode.asIndirectExpr() = this
}

override DataFlow::Node getInNode() { result = inNode }

override DataFlow::Node getOutNode() { result = outNode }
}

class PointerToPointerPassthroughCall extends AlgorithmPassthroughCall {
DataFlow::Node inNode;
DataFlow::Node outNode;

PointerToPointerPassthroughCall() {
this.getTarget().getName() = "OBJ_txt2obj" and
inNode.asIndirectExpr() = this.getArgument(0) and
outNode.asIndirectExpr() = this
or
//outNode.asExpr() = this
this.getTarget().getName() in ["OBJ_obj2txt", "i2t_ASN1_OBJECT"] and
inNode.asIndirectExpr() = this.getArgument(2) and
outNode.asDefiningArgument() = this.getArgument(0)
}

override DataFlow::Node getInNode() { result = inNode }

override DataFlow::Node getOutNode() { result = outNode }
}

class PointerToNIDPassthroughCall extends AlgorithmPassthroughCall {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in PointerToNIDPassthroughCall should be PascalCase/camelCase.
DataFlow::Node inNode;
DataFlow::Node outNode;

PointerToNIDPassthroughCall() {
this.getTarget().getName() in ["OBJ_obj2nid", "OBJ_ln2nid", "OBJ_sn2nid", "OBJ_txt2nid"] and
(
inNode.asIndirectExpr() = this.getArgument(0)
or
inNode.asExpr() = this.getArgument(0)
) and
outNode.asExpr() = this
}

override DataFlow::Node getInNode() { result = inNode }

override DataFlow::Node getOutNode() { result = outNode }
}

// TODO: pkeys pass through EVP_PKEY_CTX_new and any similar variant
predicate knownPassThroughStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(AlgorithmPassthroughCall c | c.getInNode() = node1 and c.getOutNode() = node2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import cpp
import experimental.quantum.Language

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
OpenSSLAlgorithmInstanceBase
.
Redundant import, the module is already imported inside
experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer
.
import OpenSSLAlgorithmInstanceBase
import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer
.
Redundant import, the module is already imported inside
AlgToAVCFlow
.
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer
import AlgToAVCFlow

/**
* Given a `KnownOpenSSLBlockModeAlgorithmConstant`, converts this to a block family type.
* Does not bind if there is know mapping (no mapping to 'unknown' or 'other').
*/
predicate knownOpenSSLConstantToBlockModeFamilyType(

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in knownOpenSSLConstantToBlockModeFamilyType should be PascalCase/camelCase.
KnownOpenSSLBlockModeAlgorithmConstant e, Crypto::TBlockCipherModeOfOperationType type
) {
exists(string name |
name = e.getNormalizedName() and
(
name.matches("CBC") and type instanceof Crypto::CBC

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("CFB%") and type instanceof Crypto::CFB
or
name.matches("CTR") and type instanceof Crypto::CTR

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("GCM") and type instanceof Crypto::GCM

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("OFB") and type instanceof Crypto::OFB

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("XTS") and type instanceof Crypto::XTS

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("CCM") and type instanceof Crypto::CCM

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("GCM") and type instanceof Crypto::GCM

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("CCM") and type instanceof Crypto::CCM

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
or
name.matches("ECB") and type instanceof Crypto::ECB

Check notice

Code scanning / CodeQL

Use of regexp to match a set of constant string Note

Use string comparison instead of regexp to compare against a constant set of string.
)
)
}

class KnownOpenSSLBlockModeConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLBlockModeConstantAlgorithmInstance should be PascalCase/camelCase.
Crypto::ModeOfOperationAlgorithmInstance instanceof KnownOpenSSLBlockModeAlgorithmConstant
{
OpenSSLAlgorithmValueConsumer getterCall;

KnownOpenSSLBlockModeConstantAlgorithmInstance() {
// Two possibilities:
// 1) The source is a literal and flows to a getter, then we know we have an instance
// 2) The source is a KnownOpenSSLAlgorithm is call, and we know we have an instance immediately from that
// Possibility 1:
this instanceof Literal and
exists(DataFlow::Node src, DataFlow::Node sink |
// Sink is an argument to a CipherGetterCall
sink = getterCall.(OpenSSLAlgorithmValueConsumer).getInputNode() and

Check warning

Code scanning / CodeQL

Redundant cast Warning

Redundant cast to
OpenSSLAlgorithmValueConsumer
.
// Source is `this`
src.asExpr() = this and
// This traces to a getter
KnownOpenSSLAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
)
or
// Possibility 2:
this instanceof DirectAlgorithmValueConsumer and getterCall = this
}

override Crypto::TBlockCipherModeOfOperationType getModeType() {
knownOpenSSLConstantToBlockModeFamilyType(this, result)
or
not knownOpenSSLConstantToBlockModeFamilyType(this, _) and result = Crypto::OtherMode()
}

// NOTE: I'm not going to attempt to parse out the mode specific part, so returning
// the same as the raw name for now.
override string getRawModeAlgorithmName() { result = this.(Literal).getValue().toString() }

override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall }

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in getAVC should be PascalCase/camelCase.
}
Loading
Loading