Skip to content

Quantum: Add initial qltests for OpenSSL modeling #19564

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bdrodes
Copy link
Contributor

@bdrodes bdrodes commented May 22, 2025

No description provided.

@github-actions github-actions bot added the C++ label May 22, 2025
}
}

class KnownOpenSSLSignatureAlgorithmConstant extends KnownOpenSSLAlgorithmConstant {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in KnownOpenSSLSignatureAlgorithmConstant should be PascalCase/camelCase.
//Heuristics for distinguishing int literals from other literals
exists(this.getValue().toInt()) and
not this instanceof CharLiteral and
not this instanceof StringLiteral

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in isOpenSSLStringLiteralGenericSourceCandidate should be PascalCase/camelCase.
* Note: this predicate should only consider restrictions with respect to integers only.
* General restrictions are in the OpenSSLGenericSourceCandidateLiteral class.
*/
private predicate isOpenSSLIntLiteralGenericSourceCandidate(IntLiteral l) {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in isOpenSSLIntLiteralGenericSourceCandidate should be PascalCase/camelCase.
* Literals are filtered, for example, if they are used in a way no indicative of an algorithm use
* such as in an array index, bitwise operation, or logical operation.
* Note a case like this:
* if(algVal == "AES")

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in OpenSSLGenericSourceCandidateLiteral should be PascalCase/camelCase.
@bdrodes bdrodes marked this pull request as ready for review May 22, 2025 20:15
@bdrodes bdrodes requested review from a team as code owners May 22, 2025 20:15
@jketema
Copy link
Contributor

jketema commented May 22, 2025

Just a quick drive-by comment: the tests should preferably go into the tests/experimental/library-tests sub-directory to match what is being done for the library itself.

@nicolaswill nicolaswill requested review from nicolaswill and removed request for a team May 22, 2025 22:14
@nicolaswill
Copy link
Contributor

Just a quick drive-by comment: the tests should preferably go into the tests/experimental/library-tests sub-directory to match what is being done for the library itself.

@jketema Would tests/library-tests/experimental/quantum/* also work? I do not have any preference, but we will need to update CODEOWNERS to specify whatever directory the tests eventually live in. If we use the structure I suggest, the existing CODEOWNERS entries should cover those test directories already.

@nicolaswill nicolaswill changed the title Initial openssl tests Quantum: Add initial qltests for OpenSSL modeling May 22, 2025
@jketema
Copy link
Contributor

jketema commented May 23, 2025

@nicolaswill How about changing the pattern in the code owners file to **/experimental/**/quantum/ @github/ps-codeql. I believe that should work?

@bdrodes bdrodes force-pushed the initial_openssl_tests branch 2 times, most recently from 3fc48eb to 5ab05cd Compare May 27, 2025 18:18
…ound through tests, and updating CODEOWNERS for quantum tests
@bdrodes bdrodes force-pushed the initial_openssl_tests branch from 5ab05cd to 41f008d Compare May 27, 2025 19:24
@nicolaswill
Copy link
Contributor

@jketema Ready for your review.

CtxType() {
// It is possible for users to use the underlying type of the CTX variables
// these have a name matching 'evp_%ctx_%st
this.getUnspecifiedType().stripType().getName().matches("evp_%ctx_%st")
Copy link
Contributor

@nicolaswill nicolaswill May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a C team reviewer: I am curious about necessity of the logic in this charpred (see comment about "build mode none issues" on the lines below).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you just being defensive here, or have you seen these issues on real world databases? To me it looks very unlikely that the case below can actually occur, because everything here is coming from the OpenSSL headers, and if it could not find one of them, it probably would not have been able to find any of them.

In general we have only been introducing workarounds like the below when we saw many issues arising from a missing definition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is in fact only needed for your test to work, then I would strongly suggest to rewrite the test.

Copy link
Contributor Author

@bdrodes bdrodes May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a defensive move. The build mode none work has me very nervous now with respect to tying anything to resolution of library headers (perhaps I'm wrong). The combination of the two approaches in this CTX type class should handle all cases (e.g., the user uses the underlying _st type, the user uses the typedef, the header is found, the header isn't). The entire modeling approach is very brittle if the CTX underlying type isn't detected (the entire inventory for openSSL will fail if CTX isn't located correctly), so I'm inclined to be very very robust here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion in the comment. This is not a hypothetical case but a real-world one observed on Microsoft DBs, and the test-case reflects that pattern. With a cryptography inventory, one small failure in determining the existence of an asset will damage the credibility of the inventory we produce, so we want to be exhaustive in addressing known shortcomings proactively.

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to pull in significant parts of what looks to be derived from the OpenSSL headers into our test directories. OpenSSL has a different license from ours (Apache vs. MIT). Is this legally ok?

@nicolaswill
Copy link
Contributor

This is starting to pull in significant parts of what looks to be derived from the OpenSSL headers into our test directories. OpenSSL has a different license from ours (Apache vs. MIT). Is this legally ok?

@jketema We stub out other libraries with the Apache license. An example is Spring.
@bdrodes We do, however, need OpenSSL's LICENSE.txt for the stubs (see the Spring example here).

Copy link
Contributor

@nicolaswill nicolaswill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above regarding CtxType and licensing.

@jketema
Copy link
Contributor

jketema commented May 28, 2025

@nicolaswill Thanks for pointing our the prior art in the Java QL tests. I think we want a similar kind of set up where the stubs are isolated in their own directory, we have a top-level readme like https://github.com/github/codeql/blob/main/java/ql/test/stubs/README.md, and have a license file in the directory with the OpenSSL stubs.

…l apache license and a readme for future stub creation. Modify existing test case to reference stubs location.
@bdrodes
Copy link
Contributor Author

bdrodes commented May 28, 2025

I added a stubs location and moved the openssl stubs accordingly, and added the openssl apache license.

@bdrodes
Copy link
Contributor Author

bdrodes commented May 28, 2025

Do we need to update codeowners for the stubs?

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.

3 participants