-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Quantum: Model OpenSSL EC key generation #19541
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
cpp/ql/lib/experimental/quantum/OpenSSL/Operations/ECKeyGenOperation.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
private import experimental.quantum.Language | ||
private import experimental.quantum.OpenSSL.LibraryDetector | ||
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow | ||
private import OpenSSLOperationBase | ||
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers | ||
private import semmle.code.cpp.dataflow.new.DataFlow | ||
Check warningCode scanning / CodeQL Redundant import Warning
Redundant import, the module is already imported inside
experimental.quantum.Language Error loading related location Loading |
||
|
||
private module AlgGetterToAlgConsumerConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node source) { | ||
exists(OpenSSLAlgorithmValueConsumer c | c.getResultNode() = source) | ||
} | ||
|
||
predicate isSink(DataFlow::Node sink) { | ||
exists(ECKeyGenOperation c | c.getAlgorithmArg() = sink.asExpr()) | ||
} | ||
} | ||
|
||
private module AlgGetterToAlgConsumerFlow = DataFlow::Global<AlgGetterToAlgConsumerConfig>; | ||
|
||
class ECKeyGenOperation extends OpenSSLOperation, Crypto::KeyGenerationOperationInstance { | ||
ECKeyGenOperation() { | ||
this.(Call).getTarget().getName() = "EC_KEY_generate_key" and | ||
isPossibleOpenSSLFunction(this.(Call).getTarget()) | ||
} | ||
|
||
override Expr getOutputArg() { | ||
result = this.(Call) // return value of call | ||
} | ||
|
||
Expr getAlgorithmArg() { result = this.(Call).getArgument(0) } | ||
|
||
override Expr getInputArg() { | ||
// there is no 'input', in the sense that no data is being manipualted by the operation. | ||
bdrodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// There is an input of an algorithm, but that is not the intention of the operation input arg. | ||
none() | ||
} | ||
|
||
override Crypto::KeyArtifactType getOutputKeyType() { result = Crypto::TAsymmetricKeyType() } | ||
|
||
override Crypto::ArtifactOutputDataFlowNode getOutputKeyArtifact() { | ||
result = this.getOutputNode() | ||
} | ||
|
||
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { | ||
AlgGetterToAlgConsumerFlow::flow(result.(OpenSSLAlgorithmValueConsumer).getResultNode(), | ||
DataFlow::exprNode(this.getAlgorithmArg())) | ||
} | ||
|
||
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() { | ||
none() // no explicit key size, inferred from algorithm | ||
} | ||
|
||
override int getKeySizeFixed() { | ||
none() | ||
// TODO: marked as none as the operation itself has no key size, it | ||
// comes from the algorithm source, but note we could grab the | ||
// algorithm source and get the key size (see below). | ||
// We may need to reconsider what is the best approach here. | ||
// result = | ||
// this.getAnAlgorithmValueConsumer() | ||
// .getAKnownAlgorithmSource() | ||
// .(Crypto::EllipticCurveInstance) | ||
// .getKeySize() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperations.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import OpenSSLOperationBase | ||
import EVPCipherOperation | ||
import EVPHashOperation | ||
import ECKeyGenOperation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning