From 0de6647927705b1123bd10b657b7f3a40fc5f490 Mon Sep 17 00:00:00 2001 From: "REDMOND\\brodes" Date: Thu, 22 May 2025 14:35:14 -0400 Subject: [PATCH 1/4] Crypto: Adding initial openssl tests, fixing a bug in hash modeling found through tests, and updating CODEOWNERS for quantum tests --- CODEOWNERS | 2 +- .../experimental/quantum/OpenSSL/CtxFlow.qll | 14 +- .../OpenSSL/Operations/EVPCipherOperation.qll | 4 +- .../OpenSSL/Operations/EVPHashOperation.qll | 15 +- .../openssl/cipher_key_sources.expected | 2 + .../quantum/openssl/cipher_key_sources.ql | 6 + .../openssl/cipher_nonce_sources.expected | 2 + .../quantum/openssl/cipher_nonce_sources.ql | 6 + .../openssl/cipher_operations.expected | 8 + .../quantum/openssl/cipher_operations.ql | 6 + .../openssl/cipher_plaintext_sources.expected | 1 + .../openssl/cipher_plaintext_sources.ql | 6 + .../openssl/hash_input_sources.expected | 2 + .../quantum/openssl/hash_input_sources.ql | 6 + .../quantum/openssl/hash_operations.expected | 2 + .../quantum/openssl/hash_operations.ql | 5 + .../openssl/includes/alg_macro_stubs.h | 3741 +++++++++++++ .../quantum/openssl/includes/evp_stubs.h | 4986 +++++++++++++++++ .../quantum/openssl/includes/rand_stubs.h | 3 + .../quantum/openssl/openssl_basic.c | 221 + 20 files changed, 9028 insertions(+), 10 deletions(-) create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_key_sources.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_key_sources.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_nonce_sources.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_nonce_sources.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_operations.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_operations.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_plaintext_sources.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/cipher_plaintext_sources.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/hash_input_sources.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/hash_input_sources.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/hash_operations.expected create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/hash_operations.ql create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/includes/alg_macro_stubs.h create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/includes/evp_stubs.h create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/includes/rand_stubs.h create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/openssl_basic.c diff --git a/CODEOWNERS b/CODEOWNERS index 96aa46df9495..7233623d4528 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -16,7 +16,7 @@ /java/ql/test-kotlin2/ @github/codeql-kotlin # Experimental CodeQL cryptography -**/experimental/quantum/ @github/ps-codeql +**/experimental/**/quantum/ @github/ps-codeql /shared/quantum/ @github/ps-codeql # CodeQL tools and associated docs diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/CtxFlow.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/CtxFlow.qll index cbce19fb5dfe..38b49b8d9010 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/CtxFlow.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/CtxFlow.qll @@ -29,7 +29,19 @@ import semmle.code.cpp.dataflow.new.DataFlow * - EVP_PKEY_CTX */ private class CtxType extends Type { - CtxType() { this.getUnspecifiedType().stripType().getName().matches("evp_%ctx_%st") } + 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") + or + // In principal the above check should be sufficient, but in case of build mode none issues + // i.e., if a typedef cannot be resolved, + // or issues with properly stubbing test cases, we also explicitly check for the wrapping type defs + // i.e., patterns matching 'EVP_%_CTX' + exists(Type base | base = this or base = this.(DerivedType).getBaseType() | + base.getName().matches("EVP_%_CTX") + ) + } } /** diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll index bb884f6db530..233bfd504338 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll @@ -10,7 +10,7 @@ private module AlgGetterToAlgConsumerConfig implements DataFlow::ConfigSig { } predicate isSink(DataFlow::Node sink) { - exists(EVP_Cipher_Operation c | c.getInitCall().getAlgorithmArg() = sink.asExpr()) + exists(EVP_Cipher_Operation c | c.getAlgorithmArg() = sink.asExpr()) } } @@ -32,6 +32,8 @@ private module AlgGetterToAlgConsumerFlow = DataFlow::Global 0) { + // Success + plaintext_len += len; + return plaintext_len; + } else { + // Verification failed + return -1; + } +} + +// Function to calculate SHA-256 hash +int calculate_sha256(const unsigned char *message, size_t message_len, + unsigned char *digest) { + EVP_MD_CTX *mdctx; + unsigned int digest_len; + + // Create and initialize the context + if(!(mdctx = EVP_MD_CTX_new())) + return 0; + + // Initialize the hash operation + if(1 != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) + return 0; + + // Provide the message to be hashed + if(1 != EVP_DigestUpdate(mdctx, message, message_len)) + return 0; + + // Finalize the hash + if(1 != EVP_DigestFinal_ex(mdctx, digest, &digest_len)) + return 0; + + // Clean up + EVP_MD_CTX_free(mdctx); + + return 1; +} + +// Function to generate random bytes +int generate_random_bytes(unsigned char *buffer, size_t length) { + return RAND_bytes(buffer, length); +} + +// Function using direct EVP_Digest function (one-shot hash) +int calculate_md5_oneshot(const unsigned char *message, size_t message_len, + unsigned char *digest) { + unsigned int digest_len; + + // Calculate MD5 in a single call + if(1 != EVP_Digest(message, message_len, digest, &digest_len, EVP_md5(), NULL)) + return 0; + + return 1; +} + +// Function using HMAC +int calculate_hmac_sha256(const unsigned char *key, size_t key_len, + const unsigned char *message, size_t message_len, + unsigned char *mac) { + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_PKEY *pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, key_len); + + if (!ctx || !pkey) + return 0; + + if (EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, pkey) != 1) + return 0; + + if (EVP_DigestSignUpdate(ctx, message, message_len) != 1) + return 0; + + size_t mac_len = 32; // SHA-256 output size + if (EVP_DigestSignFinal(ctx, mac, &mac_len) != 1) + return 0; + + EVP_MD_CTX_free(ctx); + EVP_PKEY_free(pkey); + + return 1; +} + +// Test function +int test_main() { + // Test encryption and decryption + unsigned char *key = (unsigned char *)"01234567890123456789012345678901"; // 32 bytes + unsigned char *iv = (unsigned char *)"0123456789012345"; // 16 bytes + unsigned char *plaintext = (unsigned char *)"This is a test message for encryption"; + unsigned char ciphertext[1024]; + unsigned char tag[16]; + unsigned char decrypted[1024]; + int plaintext_len = strlen((char *)plaintext); + int ciphertext_len; + int decrypted_len; + + // Test SHA-256 hash + unsigned char hash[32]; + + // Test random generation + unsigned char random_bytes[32]; + + // // Initialize OpenSSL + // ERR_load_crypto_strings(); + + // Encrypt data + ciphertext_len = encrypt_aes_gcm(plaintext, plaintext_len, key, iv, 16, ciphertext, tag); + + // Decrypt data + decrypted_len = decrypt_aes_gcm(ciphertext, ciphertext_len, tag, key, iv, 16, decrypted); + + //printf("decrypted: %s\n", decrypted); + + // Calculate hash + calculate_sha256(plaintext, plaintext_len, hash); + + // Generate random bytes + generate_random_bytes(random_bytes, 32); + + // Calculate one-shot MD5 + unsigned char md5_hash[16]; + calculate_md5_oneshot(plaintext, plaintext_len, md5_hash); + + // Calculate HMAC + unsigned char hmac[32]; + calculate_hmac_sha256(key, 32, plaintext, plaintext_len, hmac); + + return 0; +} \ No newline at end of file From a9bdcc72eb6561ded3a18f249fb26a057ff1df93 Mon Sep 17 00:00:00 2001 From: "REDMOND\\brodes" Date: Wed, 28 May 2025 12:05:18 -0400 Subject: [PATCH 2/4] Crypto: Move openssl stubs to a shared stubs location. Include openssl apache license and a readme for future stub creation. Modify existing test case to reference stubs location. --- .../quantum/openssl/openssl_basic.c | 6 +- .../library-tests/quantum/openssl/options | 1 + cpp/ql/test/stubs/README.md | 4 + .../openssl}/alg_macro_stubs.h | 0 .../includes => stubs/openssl}/evp_stubs.h | 0 cpp/ql/test/stubs/openssl/license.txt | 177 ++++++++++++++++++ .../includes => stubs/openssl}/rand_stubs.h | 0 7 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 cpp/ql/test/experimental/library-tests/quantum/openssl/options create mode 100644 cpp/ql/test/stubs/README.md rename cpp/ql/test/{experimental/library-tests/quantum/openssl/includes => stubs/openssl}/alg_macro_stubs.h (100%) rename cpp/ql/test/{experimental/library-tests/quantum/openssl/includes => stubs/openssl}/evp_stubs.h (100%) create mode 100644 cpp/ql/test/stubs/openssl/license.txt rename cpp/ql/test/{experimental/library-tests/quantum/openssl/includes => stubs/openssl}/rand_stubs.h (100%) diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/openssl_basic.c b/cpp/ql/test/experimental/library-tests/quantum/openssl/openssl_basic.c index 5e3537064b5b..ba6aa805c0b3 100644 --- a/cpp/ql/test/experimental/library-tests/quantum/openssl/openssl_basic.c +++ b/cpp/ql/test/experimental/library-tests/quantum/openssl/openssl_basic.c @@ -1,6 +1,6 @@ -#include "includes/evp_stubs.h" -#include "includes/alg_macro_stubs.h" -#include "includes/rand_stubs.h" +#include "openssl/evp_stubs.h" +#include "openssl/alg_macro_stubs.h" +#include "openssl/rand_stubs.h" size_t strlen(const char* str); diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/options b/cpp/ql/test/experimental/library-tests/quantum/openssl/options new file mode 100644 index 000000000000..06306a3a46ad --- /dev/null +++ b/cpp/ql/test/experimental/library-tests/quantum/openssl/options @@ -0,0 +1 @@ +semmle-extractor-options: -I ../../../../stubs \ No newline at end of file diff --git a/cpp/ql/test/stubs/README.md b/cpp/ql/test/stubs/README.md new file mode 100644 index 000000000000..eacd316b95be --- /dev/null +++ b/cpp/ql/test/stubs/README.md @@ -0,0 +1,4 @@ +The stubs in this directory are derived from various open-source projects, and +used to test that the relevant APIs are correctly modelled. Where a disclaimer +or third-party-notice is required, this is included in the top-level directory +for each particular library. \ No newline at end of file diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/includes/alg_macro_stubs.h b/cpp/ql/test/stubs/openssl/alg_macro_stubs.h similarity index 100% rename from cpp/ql/test/experimental/library-tests/quantum/openssl/includes/alg_macro_stubs.h rename to cpp/ql/test/stubs/openssl/alg_macro_stubs.h diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/includes/evp_stubs.h b/cpp/ql/test/stubs/openssl/evp_stubs.h similarity index 100% rename from cpp/ql/test/experimental/library-tests/quantum/openssl/includes/evp_stubs.h rename to cpp/ql/test/stubs/openssl/evp_stubs.h diff --git a/cpp/ql/test/stubs/openssl/license.txt b/cpp/ql/test/stubs/openssl/license.txt new file mode 100644 index 000000000000..49cc83d2ee29 --- /dev/null +++ b/cpp/ql/test/stubs/openssl/license.txt @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/includes/rand_stubs.h b/cpp/ql/test/stubs/openssl/rand_stubs.h similarity index 100% rename from cpp/ql/test/experimental/library-tests/quantum/openssl/includes/rand_stubs.h rename to cpp/ql/test/stubs/openssl/rand_stubs.h From 6b267479beaf9aa8dbf79376278adf9dbe04ce2b Mon Sep 17 00:00:00 2001 From: "REDMOND\\brodes" Date: Fri, 30 May 2025 09:35:33 -0400 Subject: [PATCH 3/4] Crypto: Update crypto stubs location under 'crypto' and associate codeowners on any `test/stubs/crypto`. Minor fix to HashAlgorithmValueConsumer (remove library detector logic). --- CODEOWNERS | 1 + .../HashAlgorithmValueConsumer.qll | 11 +++-------- .../library-tests/quantum/openssl/options | 2 +- .../test/stubs/{ => crypto}/openssl/alg_macro_stubs.h | 0 cpp/ql/test/stubs/{ => crypto}/openssl/evp_stubs.h | 0 cpp/ql/test/stubs/{ => crypto}/openssl/license.txt | 0 cpp/ql/test/stubs/{ => crypto}/openssl/rand_stubs.h | 0 7 files changed, 5 insertions(+), 9 deletions(-) rename cpp/ql/test/stubs/{ => crypto}/openssl/alg_macro_stubs.h (100%) rename cpp/ql/test/stubs/{ => crypto}/openssl/evp_stubs.h (100%) rename cpp/ql/test/stubs/{ => crypto}/openssl/license.txt (100%) rename cpp/ql/test/stubs/{ => crypto}/openssl/rand_stubs.h (100%) diff --git a/CODEOWNERS b/CODEOWNERS index 7233623d4528..612a5e8a22ac 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -18,6 +18,7 @@ # Experimental CodeQL cryptography **/experimental/**/quantum/ @github/ps-codeql /shared/quantum/ @github/ps-codeql +**/test/stubs/crypto/ @github/ps-codeql # CodeQL tools and associated docs /docs/codeql/codeql-cli/ @github/codeql-cli-reviewers diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll index 52d7949561e8..6c4a9c9bd6cd 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll @@ -3,18 +3,14 @@ private import experimental.quantum.Language private import semmle.code.cpp.dataflow.new.DataFlow private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase private import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstances -private import experimental.quantum.OpenSSL.LibraryDetector abstract class HashAlgorithmValueConsumer extends OpenSSLAlgorithmValueConsumer { } /** * EVP_Q_Digest directly consumes algorithm constant values */ -class EVP_Q_Digest_Algorithm_Consumer extends OpenSSLAlgorithmValueConsumer { - EVP_Q_Digest_Algorithm_Consumer() { - isPossibleOpenSSLFunction(this.(Call).getTarget()) and - this.(Call).getTarget().getName() = "EVP_Q_digest" - } +class EVP_Q_Digest_Algorithm_Consumer extends HashAlgorithmValueConsumer { + EVP_Q_Digest_Algorithm_Consumer() { this.(Call).getTarget().getName() = "EVP_Q_digest" } override Crypto::ConsumerInputDataFlowNode getInputNode() { result.asExpr() = this.(Call).getArgument(1) @@ -35,13 +31,12 @@ class EVP_Q_Digest_Algorithm_Consumer extends OpenSSLAlgorithmValueConsumer { * The EVP digest algorithm getters * https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis */ -class EVPDigestAlgorithmValueConsumer extends OpenSSLAlgorithmValueConsumer { +class EVPDigestAlgorithmValueConsumer extends HashAlgorithmValueConsumer { DataFlow::Node valueArgNode; DataFlow::Node resultNode; EVPDigestAlgorithmValueConsumer() { resultNode.asExpr() = this and - isPossibleOpenSSLFunction(this.(Call).getTarget()) and ( this.(Call).getTarget().getName() in [ "EVP_get_digestbyname", "EVP_get_digestbynid", "EVP_get_digestbyobj" diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/options b/cpp/ql/test/experimental/library-tests/quantum/openssl/options index 06306a3a46ad..7ea00eb0bfba 100644 --- a/cpp/ql/test/experimental/library-tests/quantum/openssl/options +++ b/cpp/ql/test/experimental/library-tests/quantum/openssl/options @@ -1 +1 @@ -semmle-extractor-options: -I ../../../../stubs \ No newline at end of file +semmle-extractor-options: -I ../../../../stubs/crypto \ No newline at end of file diff --git a/cpp/ql/test/stubs/openssl/alg_macro_stubs.h b/cpp/ql/test/stubs/crypto/openssl/alg_macro_stubs.h similarity index 100% rename from cpp/ql/test/stubs/openssl/alg_macro_stubs.h rename to cpp/ql/test/stubs/crypto/openssl/alg_macro_stubs.h diff --git a/cpp/ql/test/stubs/openssl/evp_stubs.h b/cpp/ql/test/stubs/crypto/openssl/evp_stubs.h similarity index 100% rename from cpp/ql/test/stubs/openssl/evp_stubs.h rename to cpp/ql/test/stubs/crypto/openssl/evp_stubs.h diff --git a/cpp/ql/test/stubs/openssl/license.txt b/cpp/ql/test/stubs/crypto/openssl/license.txt similarity index 100% rename from cpp/ql/test/stubs/openssl/license.txt rename to cpp/ql/test/stubs/crypto/openssl/license.txt diff --git a/cpp/ql/test/stubs/openssl/rand_stubs.h b/cpp/ql/test/stubs/crypto/openssl/rand_stubs.h similarity index 100% rename from cpp/ql/test/stubs/openssl/rand_stubs.h rename to cpp/ql/test/stubs/crypto/openssl/rand_stubs.h From a473c96a9cd3fd569f68096ac5716c7cae58adb7 Mon Sep 17 00:00:00 2001 From: "REDMOND\\brodes" Date: Mon, 2 Jun 2025 09:14:15 -0400 Subject: [PATCH 4/4] Crypto: Move crypto test stubs under experimental/stubs and remove special CODEOWNERS assignments for crypto stubs. --- CODEOWNERS | 1 - cpp/ql/test/experimental/library-tests/quantum/openssl/options | 2 +- cpp/ql/test/{ => experimental}/stubs/README.md | 0 .../crypto => experimental/stubs}/openssl/alg_macro_stubs.h | 0 .../{stubs/crypto => experimental/stubs}/openssl/evp_stubs.h | 0 .../{stubs/crypto => experimental/stubs}/openssl/license.txt | 0 .../{stubs/crypto => experimental/stubs}/openssl/rand_stubs.h | 0 7 files changed, 1 insertion(+), 2 deletions(-) rename cpp/ql/test/{ => experimental}/stubs/README.md (100%) rename cpp/ql/test/{stubs/crypto => experimental/stubs}/openssl/alg_macro_stubs.h (100%) rename cpp/ql/test/{stubs/crypto => experimental/stubs}/openssl/evp_stubs.h (100%) rename cpp/ql/test/{stubs/crypto => experimental/stubs}/openssl/license.txt (100%) rename cpp/ql/test/{stubs/crypto => experimental/stubs}/openssl/rand_stubs.h (100%) diff --git a/CODEOWNERS b/CODEOWNERS index 612a5e8a22ac..7233623d4528 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -18,7 +18,6 @@ # Experimental CodeQL cryptography **/experimental/**/quantum/ @github/ps-codeql /shared/quantum/ @github/ps-codeql -**/test/stubs/crypto/ @github/ps-codeql # CodeQL tools and associated docs /docs/codeql/codeql-cli/ @github/codeql-cli-reviewers diff --git a/cpp/ql/test/experimental/library-tests/quantum/openssl/options b/cpp/ql/test/experimental/library-tests/quantum/openssl/options index 7ea00eb0bfba..eb3abc42d12c 100644 --- a/cpp/ql/test/experimental/library-tests/quantum/openssl/options +++ b/cpp/ql/test/experimental/library-tests/quantum/openssl/options @@ -1 +1 @@ -semmle-extractor-options: -I ../../../../stubs/crypto \ No newline at end of file +semmle-extractor-options: -I ../../../stubs \ No newline at end of file diff --git a/cpp/ql/test/stubs/README.md b/cpp/ql/test/experimental/stubs/README.md similarity index 100% rename from cpp/ql/test/stubs/README.md rename to cpp/ql/test/experimental/stubs/README.md diff --git a/cpp/ql/test/stubs/crypto/openssl/alg_macro_stubs.h b/cpp/ql/test/experimental/stubs/openssl/alg_macro_stubs.h similarity index 100% rename from cpp/ql/test/stubs/crypto/openssl/alg_macro_stubs.h rename to cpp/ql/test/experimental/stubs/openssl/alg_macro_stubs.h diff --git a/cpp/ql/test/stubs/crypto/openssl/evp_stubs.h b/cpp/ql/test/experimental/stubs/openssl/evp_stubs.h similarity index 100% rename from cpp/ql/test/stubs/crypto/openssl/evp_stubs.h rename to cpp/ql/test/experimental/stubs/openssl/evp_stubs.h diff --git a/cpp/ql/test/stubs/crypto/openssl/license.txt b/cpp/ql/test/experimental/stubs/openssl/license.txt similarity index 100% rename from cpp/ql/test/stubs/crypto/openssl/license.txt rename to cpp/ql/test/experimental/stubs/openssl/license.txt diff --git a/cpp/ql/test/stubs/crypto/openssl/rand_stubs.h b/cpp/ql/test/experimental/stubs/openssl/rand_stubs.h similarity index 100% rename from cpp/ql/test/stubs/crypto/openssl/rand_stubs.h rename to cpp/ql/test/experimental/stubs/openssl/rand_stubs.h