-
Notifications
You must be signed in to change notification settings - Fork 2k
Quantum: Add base classes for OpenSSL EVP methods #19607
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d1b1d1
refactor EVP common classes
GrosQuildu af8702d
fix openssl outputs
GrosQuildu f103e8b
Update cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOper…
GrosQuildu 328cf79
Apply docs suggestions
GrosQuildu f04fa58
rm one-shot class
GrosQuildu eff6eb3
remove redundant if/none
GrosQuildu 60d9b6e
update docs
GrosQuildu 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
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
7 changes: 2 additions & 5 deletions
7
cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPHashInitializer.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
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 |
|---|---|---|
|
|
@@ -8,118 +8,78 @@ private import OpenSSLOperationBase | |
| private import EVPHashInitializer | ||
| private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers | ||
|
|
||
| // import EVPHashConsumers | ||
| abstract class EVP_Hash_Operation extends OpenSSLOperation, Crypto::HashOperationInstance { | ||
| Expr getContextArg() { result = this.(Call).getArgument(0) } | ||
| class EVP_Digest_Update_Call extends EVPUpdate { | ||
| EVP_Digest_Update_Call() { this.(Call).getTarget().getName() = "EVP_DigestUpdate" } | ||
|
|
||
| Expr getAlgorithmArg() { result = this.getInitCall().getAlgorithmArg() } | ||
|
|
||
| EVP_Hash_Initializer getInitCall() { | ||
| CTXFlow::ctxArgFlowsToCtxArg(result.getContextArg(), this.getContextArg()) | ||
| } | ||
|
|
||
| /** | ||
| * By default, the algorithm value comes from the init call. | ||
| * There are variants where this isn't true, in which case the | ||
| * subclass should override this method. | ||
| */ | ||
| override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { | ||
| AlgGetterToAlgConsumerFlow::flow(result.(OpenSSLAlgorithmValueConsumer).getResultNode(), | ||
| DataFlow::exprNode(this.getAlgorithmArg())) | ||
| } | ||
| } | ||
|
|
||
| private module AlgGetterToAlgConsumerConfig implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node source) { | ||
| exists(OpenSSLAlgorithmValueConsumer c | c.getResultNode() = source) | ||
| } | ||
|
|
||
| predicate isSink(DataFlow::Node sink) { | ||
| exists(EVP_Hash_Operation c | c.getAlgorithmArg() = sink.asExpr()) | ||
| } | ||
| override Expr getInputArg() { result = this.(Call).getArgument(1) } | ||
| } | ||
|
|
||
| private module AlgGetterToAlgConsumerFlow = DataFlow::Global<AlgGetterToAlgConsumerConfig>; | ||
|
|
||
| //https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis | ||
| class EVP_Q_Digest_Operation extends EVP_Hash_Operation { | ||
| class EVP_Q_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance { | ||
| EVP_Q_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Q_digest" } | ||
|
|
||
| //override Crypto::AlgorithmConsumer getAlgorithmConsumer() { } | ||
| override Expr getAlgorithmArg() { result = this.(Call).getArgument(1) } | ||
|
|
||
| override EVP_Hash_Initializer getInitCall() { | ||
| // This variant of digest does not use an init | ||
| // and even if it were used, the init would be ignored/undefined | ||
| none() | ||
| } | ||
|
|
||
| override Expr getOutputArg() { result = this.(Call).getArgument(5) } | ||
|
|
||
| override Expr getInputArg() { result = this.(Call).getArgument(3) } | ||
|
|
||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { result = this.getOutputNode() } | ||
|
|
||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { result = this.getInputNode() } | ||
| override Expr getOutputArg() { result = this.(Call).getArgument(5) } | ||
|
|
||
| override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { | ||
| // The operation is a direct algorithm consumer | ||
| // NOTE: the operation itself is already modeld as a value consumer, so we can | ||
| // simply return 'this', see modeled hash algorithm consuers for EVP_Q_Digest | ||
| this = result | ||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { | ||
|
||
| result = EVPOperation.super.getOutputArtifact() | ||
| } | ||
|
|
||
| override Expr getAlgorithmArg() { result = this.(Call).getArgument(1) } | ||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { | ||
| result = EVPOperation.super.getInputConsumer() | ||
| } | ||
| } | ||
|
|
||
| class EVP_Digest_Operation extends EVP_Hash_Operation { | ||
| class EVP_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance { | ||
| EVP_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Digest" } | ||
|
|
||
| // There is no context argument for this function | ||
| override Expr getContextArg() { none() } | ||
|
|
||
| override Expr getAlgorithmArg() { result = this.(Call).getArgument(4) } | ||
|
|
||
| override EVP_Hash_Initializer getInitCall() { | ||
| // This variant of digest does not use an init | ||
| // and even if it were used, the init would be ignored/undefined | ||
| none() | ||
| } | ||
|
|
||
| override Expr getAlgorithmArg() { result = this.(Call).getArgument(4) } | ||
|
|
||
| override Expr getOutputArg() { result = this.(Call).getArgument(2) } | ||
|
|
||
| override Expr getInputArg() { result = this.(Call).getArgument(0) } | ||
|
|
||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { result = this.getOutputNode() } | ||
|
|
||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { result = this.getInputNode() } | ||
| } | ||
|
|
||
| // NOTE: not modeled as hash operations, these are intermediate calls | ||
| class EVP_Digest_Update_Call extends Call { | ||
| EVP_Digest_Update_Call() { this.(Call).getTarget().getName() in ["EVP_DigestUpdate"] } | ||
|
|
||
| Expr getInputArg() { result = this.(Call).getArgument(1) } | ||
| override Expr getOutputArg() { result = this.(Call).getArgument(2) } | ||
|
|
||
| DataFlow::Node getInputNode() { result.asExpr() = this.getInputArg() } | ||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { | ||
| result = EVPOperation.super.getOutputArtifact() | ||
| } | ||
|
|
||
| Expr getContextArg() { result = this.(Call).getArgument(0) } | ||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { | ||
| result = EVPOperation.super.getInputConsumer() | ||
| } | ||
| } | ||
|
|
||
| class EVP_Digest_Final_Call extends EVP_Hash_Operation { | ||
| class EVP_Digest_Final_Call extends EVPFinal, Crypto::HashOperationInstance { | ||
| EVP_Digest_Final_Call() { | ||
| this.(Call).getTarget().getName() in [ | ||
| "EVP_DigestFinal", "EVP_DigestFinal_ex", "EVP_DigestFinalXOF" | ||
| ] | ||
| } | ||
|
|
||
| EVP_Digest_Update_Call getUpdateCalls() { | ||
| CTXFlow::ctxArgFlowsToCtxArg(result.getContextArg(), this.getContextArg()) | ||
| } | ||
|
|
||
| override Expr getInputArg() { result = this.getUpdateCalls().getInputArg() } | ||
|
|
||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { result = this.getInputNode() } | ||
|
|
||
| override Expr getOutputArg() { result = this.(Call).getArgument(1) } | ||
|
|
||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { result = this.getOutputNode() } | ||
| override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() { | ||
| result = EVPFinal.super.getOutputArtifact() | ||
| } | ||
|
|
||
| override Crypto::ConsumerInputDataFlowNode getInputConsumer() { | ||
| result = EVPFinal.super.getInputConsumer() | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.