-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Quantum: Add OpenSSL PKEY algorithm value consumers. #19547
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
nicolaswill
merged 2 commits into
github:main
from
bdrodes:openssl_pkey_alg_value_consumers
May 21, 2025
Merged
Changes from all commits
Commits
Show all changes
2 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
57 changes: 57 additions & 0 deletions
57
...l/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/PKeyAlgorithmValueConsumer.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,57 @@ | ||
import cpp | ||
private import experimental.quantum.Language | ||
private import experimental.quantum.OpenSSL.LibraryDetector | ||
private import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants | ||
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase | ||
private import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstances | ||
|
||
abstract class PKeyValueConsumer extends OpenSSLAlgorithmValueConsumer { } | ||
|
||
class EVPPKeyAlgorithmConsumer extends PKeyValueConsumer { | ||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in EVPPKeyAlgorithmConsumer should be PascalCase/camelCase.
|
||
DataFlow::Node valueArgNode; | ||
DataFlow::Node resultNode; | ||
|
||
EVPPKeyAlgorithmConsumer() { | ||
resultNode.asExpr() = this.(Call) and // in all cases the result is the return | ||
isPossibleOpenSSLFunction(this.(Call).getTarget()) and | ||
( | ||
// NOTE: some of these consumers are themselves key gen operations, | ||
// in these cases, the operation will be created separately for the same function. | ||
this.(Call).getTarget().getName() in [ | ||
"EVP_PKEY_CTX_new_id", "EVP_PKEY_new_raw_private_key", "EVP_PKEY_new_raw_public_key", | ||
"EVP_PKEY_new_mac_key" | ||
] and | ||
valueArgNode.asExpr() = this.(Call).getArgument(0) | ||
or | ||
this.(Call).getTarget().getName() in [ | ||
"EVP_PKEY_CTX_new_from_name", "EVP_PKEY_new_raw_private_key_ex", | ||
"EVP_PKEY_new_raw_public_key_ex", "EVP_PKEY_CTX_ctrl", "EVP_PKEY_CTX_set_group_name" | ||
] and | ||
valueArgNode.asExpr() = this.(Call).getArgument(1) | ||
or | ||
// argInd 2 is 'type' which can be RSA, or EC | ||
// if RSA argInd 3 is the key size, else if EC argInd 3 is the curve name | ||
// In all other cases there is no argInd 3, and argInd 2 is the algorithm. | ||
// Since this is a key gen operation, handling the key size should be handled | ||
// when the operation is again modeled as a key gen operation. | ||
this.(Call).getTarget().getName() = "EVP_PKEY_Q_keygen" and | ||
( | ||
// Elliptic curve case | ||
// If the argInd 3 is a derived type (pointer or array) then assume it is a curve name | ||
if this.(Call).getArgument(3).getType().getUnderlyingType() instanceof DerivedType | ||
then valueArgNode.asExpr() = this.(Call).getArgument(3) | ||
else | ||
// All other cases | ||
valueArgNode.asExpr() = this.(Call).getArgument(2) | ||
) | ||
) | ||
} | ||
|
||
override Crypto::AlgorithmInstance getAKnownAlgorithmSource() { | ||
exists(OpenSSLAlgorithmInstance i | i.getAVC() = this and result = i) | ||
} | ||
|
||
override DataFlow::Node getResultNode() { result = resultNode } | ||
|
||
override Crypto::ConsumerInputDataFlowNode getInputNode() { result = valueArgNode } | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test this with MRVA or DCA before merging? I worry the performance impact will be severe from this.