-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Crypto: Add OpenSSL elliptic curve algorithm instances and consumers #19528
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
Crypto: Add OpenSSL elliptic curve algorithm instances and consumers #19528
Conversation
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show resolved
Hide resolved
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show fixed
Hide fixed
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show fixed
Hide fixed
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show resolved
Hide resolved
this instanceof DirectAlgorithmValueConsumer and getterCall = this | ||
} | ||
|
||
override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall } |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll
Fixed
Show fixed
Hide fixed
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll
Fixed
Show fixed
Hide fixed
...experimental/quantum/OpenSSL/AlgorithmValueConsumers/EllipticCurveAlgorithmValueConsumer.qll
Fixed
Show fixed
Hide fixed
...experimental/quantum/OpenSSL/AlgorithmValueConsumers/EllipticCurveAlgorithmValueConsumer.qll
Fixed
Show fixed
Hide fixed
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.
Pull Request Overview
This PR introduces support for OpenSSL elliptic curve algorithms by changing key size handling and adding new consumer/instance classes.
- Changed
getKeySize
return type from string to int in the common model and Java QL. - Added
EllipticCurveAlgorithmValueConsumer
and its registration in the OpenSSL consumer list. - Added
KnownOpenSSLEllipticCurveAlgorithmConstant
andKnownOpenSSLEllipticCurveConstantAlgorithmInstance
to the OpenSSL instance list.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
shared/quantum/codeql/quantum/experimental/Model.qll | Changed getKeySize signature to return int and updated string conversion |
java/ql/lib/experimental/quantum/JCA.qll | Updated getKeySize override to return int |
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/OpenSSLAlgorithmValueConsumers.qll | Imported EllipticCurveAlgorithmValueConsumer |
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/EllipticCurveAlgorithmValueConsumer.qll | Added consumer for EVP-based elliptic curve calls |
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/OpenSSLAlgorithmInstances.qll | Imported EllipticCurveAlgorithmInstance |
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll | Added KnownOpenSSLEllipticCurveAlgorithmConstant |
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll | Added constant-based elliptic curve instance resolver |
Comments suppressed due to low confidence (1)
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/EllipticCurveAlgorithmValueConsumer.qll:1
- No tests found for the new EllipticCurveAlgorithmValueConsumer; consider adding unit tests to verify consumer detection logic with different curve name calls.
import cpp
abstract class EllipticCurveValueConsumer extends OpenSSLAlgorithmValueConsumer { } | ||
|
||
//https://docs.openssl.org/3.0/man3/EC_KEY_new/#name | ||
class EVPEllipticCurveALgorithmConsumer extends EllipticCurveValueConsumer { |
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.
There's a typo in the class name: 'EVPEllipticCurveALgorithmConsumer' should be 'EVPEllipticCurveAlgorithmConsumer'.
class EVPEllipticCurveALgorithmConsumer extends EllipticCurveValueConsumer { | |
class EVPEllipticCurveAlgorithmConsumer extends EllipticCurveValueConsumer { |
Copilot uses AI. Check for mistakes.
class KnownOpenSSLEllitpicCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | ||
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant | ||
{ | ||
OpenSSLAlgorithmValueConsumer getterCall; | ||
|
||
KnownOpenSSLEllitpicCurveConstantAlgorithmInstance() { |
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.
Class name has a typo: 'KnownOpenSSLEllitpicCurveConstantAlgorithmInstance' should be 'KnownOpenSSLEllipticCurveConstantAlgorithmInstance'.
class KnownOpenSSLEllitpicCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | |
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant | |
{ | |
OpenSSLAlgorithmValueConsumer getterCall; | |
KnownOpenSSLEllitpicCurveConstantAlgorithmInstance() { | |
class KnownOpenSSLEllipticCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | |
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant | |
{ | |
OpenSSLAlgorithmValueConsumer getterCall; | |
KnownOpenSSLEllipticCurveConstantAlgorithmInstance() { |
Copilot uses AI. Check for mistakes.
import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants | ||
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase | ||
import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstances | ||
|
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.
[nitpick] Add a doc comment explaining the purpose and usage of EllipticCurveValueConsumer
to improve maintainability.
/** | |
* An abstract base class for consumers of elliptic curve algorithm values. | |
* | |
* This class is designed to be extended by specific implementations that | |
* handle elliptic curve-related cryptographic operations in OpenSSL. | |
* It provides a common interface and shared functionality for such consumers. | |
* | |
* Subclasses should implement the necessary methods to process elliptic curve | |
* algorithm values and integrate with the OpenSSL cryptographic library. | |
*/ |
Copilot uses AI. Check for mistakes.
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show fixed
Hide fixed
import AlgToAVCFlow | ||
|
||
class KnownOpenSSLEllipticCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | ||
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
@@ -67,6 +67,15 @@ | |||
} | |||
} | |||
|
|||
class KnownOpenSSLEllipticCurveAlgorithmConstant extends KnownOpenSSLAlgorithmConstant { |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
abstract class EllipticCurveValueConsumer extends OpenSSLAlgorithmValueConsumer { } | ||
|
||
//https://docs.openssl.org/3.0/man3/EC_KEY_new/#name | ||
class EVPEllipticCurveAlgorithmConsumer extends EllipticCurveValueConsumer { |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show resolved
Hide resolved
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show resolved
Hide resolved
cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll
Fixed
Show resolved
Hide resolved
@@ -3,3 +3,4 @@ import CipherAlgorithmInstance | |||
import PaddingAlgorithmInstance | |||
import BlockAlgorithmInstance | |||
import HashAlgorithmInstance | |||
import EllipticCurveAlgorithmInstance |
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.
Recommend going through all of these and doing a private import
of OpenSSLAlgorithmInstanceBase (and other modules where possible).
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.
Pushed
} | ||
|
||
override Crypto::AlgorithmInstance getAKnownAlgorithmSource() { | ||
exists(OpenSSLAlgorithmInstance i | i.getAVC() = this and result = i) |
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.
Why is there a generic algorithm class here, and why does the algorithm itself bind itself to the AVC as opposed to what is actually using/related to the algorithm consumed?
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.
Am I correct in my reasoning below?
"An algorithm instance exists if and only if it is a string literal that flows to a consumer. Consequently, the definition of an algorithm instance is inherently constrained by the consumer to which it flows, establishing a dependent relationship between the instance and its consuming context."
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.
basically a literal must flow to something that consumes it, if not, we aren't calling it an algorithm.
There is a flip side, the direct algorithms (functions like AES()), these... well we could say are algorithms in their own right, but I didn't model it that way. So if these don't flow to something, they also don't exist as an algorithm. We may need to re-address that.
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.
Those are indeed algorithms -- the instance where you define them would be be modeled by extending an algorithm, operation, and AVC (assuming AES() also performs some sort of operation using AES).
import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants | ||
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers | ||
private import experimental.quantum.Language | ||
private import semmle.code.cpp.dataflow.new.DataFlow |
Check warning
Code scanning / CodeQL
Redundant import Warning
experimental.quantum.Language
import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstances | ||
import experimental.quantum.OpenSSL.LibraryDetector | ||
private import experimental.quantum.Language | ||
private import semmle.code.cpp.dataflow.new.DataFlow |
Check warning
Code scanning / CodeQL
Redundant import Warning
experimental.quantum.Language
import experimental.quantum.Language | ||
import semmle.code.cpp.dataflow.new.DataFlow | ||
private import experimental.quantum.Language | ||
private import semmle.code.cpp.dataflow.new.DataFlow |
Check warning
Code scanning / CodeQL
Redundant import Warning
experimental.quantum.Language
import experimental.quantum.Language | ||
import experimental.quantum.OpenSSL.CtxFlow as CTXFlow | ||
private import experimental.quantum.Language | ||
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
import OpenSSLOperationBase | ||
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers | ||
private import experimental.quantum.Language | ||
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
import EVPHashInitializer | ||
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers | ||
private import experimental.quantum.Language | ||
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
Adds algorithm instance and consumers for openssl elliptic curves.