-
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
Changes from all commits
e7535b3
bbbdf89
d05d38f
3e54e4d
e5641ef
03a6e13
4309499
55119cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import cpp | ||
private import experimental.quantum.Language | ||
private import KnownAlgorithmConstants | ||
private import OpenSSLAlgorithmInstanceBase | ||
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase | ||
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer | ||
private import AlgToAVCFlow | ||
|
||
class KnownOpenSSLEllipticCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | ||
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant | ||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in KnownOpenSSLEllipticCurveConstantAlgorithmInstance should be PascalCase/camelCase.
|
||
{ | ||
OpenSSLAlgorithmValueConsumer getterCall; | ||
|
||
KnownOpenSSLEllipticCurveConstantAlgorithmInstance() { | ||
// 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.getInputNode() and | ||
// 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 OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall } | ||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in getAVC should be PascalCase/camelCase.
|
||
|
||
override string getRawEllipticCurveName() { result = this.(Literal).getValue().toString() } | ||
|
||
override Crypto::TEllipticCurveType getEllipticCurveType() { | ||
Crypto::ellipticCurveNameToKeySizeAndFamilyMapping(this.(KnownOpenSSLEllipticCurveAlgorithmConstant) | ||
.getNormalizedName(), _, result) | ||
} | ||
|
||
override int getKeySize() { | ||
Crypto::ellipticCurveNameToKeySizeAndFamilyMapping(this.(KnownOpenSSLEllipticCurveAlgorithmConstant) | ||
.getNormalizedName(), result, _) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Recommend going through all of these and doing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Add a doc comment explaining the purpose and usage of
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||
abstract class EllipticCurveValueConsumer extends OpenSSLAlgorithmValueConsumer { } | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
//https://docs.openssl.org/3.0/man3/EC_KEY_new/#name | ||||||||||||||||||||||||||
class EVPEllipticCurveAlgorithmConsumer extends EllipticCurveValueConsumer { | ||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in EVPEllipticCurveAlgorithmConsumer should be PascalCase/camelCase.
|
||||||||||||||||||||||||||
DataFlow::Node valueArgNode; | ||||||||||||||||||||||||||
DataFlow::Node resultNode; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
EVPEllipticCurveAlgorithmConsumer() { | ||||||||||||||||||||||||||
resultNode.asExpr() = this.(Call) and // in all cases the result is the return | ||||||||||||||||||||||||||
isPossibleOpenSSLFunction(this.(Call).getTarget()) and | ||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||
this.(Call).getTarget().getName() in ["EVP_EC_gen", "EC_KEY_new_by_curve_name"] and | ||||||||||||||||||||||||||
valueArgNode.asExpr() = this.(Call).getArgument(0) | ||||||||||||||||||||||||||
or | ||||||||||||||||||||||||||
this.(Call).getTarget().getName() in [ | ||||||||||||||||||||||||||
"EC_KEY_new_by_curve_name_ex", "EVP_PKEY_CTX_set_ec_paramgen_curve_nid" | ||||||||||||||||||||||||||
] and | ||||||||||||||||||||||||||
valueArgNode.asExpr() = this.(Call).getArgument(2) | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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). |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
override DataFlow::Node getResultNode() { result = resultNode } | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
override Crypto::ConsumerInputDataFlowNode getInputNode() { result = valueArgNode } | ||||||||||||||||||||||||||
} |
Check warning
Code scanning / CodeQL
Redundant import Warning