Content-Length: 608211 | pFad | http://github.com/github/codeql/pull/19528

7E Crypto: Add OpenSSL elliptic curve algorithm instances and consumers by bdrodes · Pull Request #19528 · github/codeql · GitHub
Skip to content

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

Conversation

bdrodes
Copy link
Contributor

@bdrodes bdrodes commented May 19, 2025

Adds algorithm instance and consumers for openssl elliptic curves.

@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 17:10
@bdrodes bdrodes requested a review from a team as a code owner May 19, 2025 17:10
this instanceof DirectAlgorithmValueConsumer and getterCall = this
}

override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall }

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in getAVC should be PascalCase/camelCase.
Copy link
Contributor

@Copilot Copilot AI left a 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 and KnownOpenSSLEllipticCurveConstantAlgorithmInstance 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 {
Copy link
Preview

Copilot AI May 19, 2025

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'.

Suggested change
class EVPEllipticCurveALgorithmConsumer extends EllipticCurveValueConsumer {
class EVPEllipticCurveAlgorithmConsumer extends EllipticCurveValueConsumer {

Copilot uses AI. Check for mistakes.

Comment on lines 8 to 13
class KnownOpenSSLEllitpicCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant
{
OpenSSLAlgorithmValueConsumer getterCall;

KnownOpenSSLEllitpicCurveConstantAlgorithmInstance() {
Copy link
Preview

Copilot AI May 19, 2025

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'.

Suggested change
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

Copy link
Preview

Copilot AI May 19, 2025

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.

Suggested change
/**
* 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.

import AlgToAVCFlow

class KnownOpenSSLEllipticCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,
Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLEllipticCurveConstantAlgorithmInstance should be PascalCase/camelCase.
@@ -67,6 +67,15 @@
}
}

class KnownOpenSSLEllipticCurveAlgorithmConstant extends KnownOpenSSLAlgorithmConstant {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLEllipticCurveAlgorithmConstant should be PascalCase/camelCase.
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

Acronyms in EVPEllipticCurveAlgorithmConsumer should be PascalCase/camelCase.
@nicolaswill nicolaswill changed the title Crypto: Openssl elliptic curve algorithm instances and consumers Crypto: Add OpenSSL elliptic curve algorithm instances and consumers May 19, 2025
@@ -3,3 +3,4 @@ import CipherAlgorithmInstance
import PaddingAlgorithmInstance
import BlockAlgorithmInstance
import HashAlgorithmInstance
import EllipticCurveAlgorithmInstance
Copy link
Contributor

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).

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor

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."

Copy link
Contributor Author

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.

Copy link
Contributor

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

Redundant import, the module is already imported inside
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

Redundant import, the module is already imported inside
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

Redundant import, the module is already imported inside
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

Acronyms in CTXFlow should be PascalCase/camelCase.
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

Acronyms in CTXFlow should be PascalCase/camelCase.
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

Acronyms in CTXFlow should be PascalCase/camelCase.
@nicolaswill nicolaswill merged commit a01d5e6 into github:main May 19, 2025
39 checks passed
@nicolaswill nicolaswill deleted the openssl_elliptic_curve_algorithm_instances_and_consumers branch May 20, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql/pull/19528

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy