Skip to content

Add Additional Host Based Testing#1714

Draft
Flickdm wants to merge 5 commits intomicrosoft:release/202511from
Flickdm:pr/add_host_based_tests
Draft

Add Additional Host Based Testing#1714
Flickdm wants to merge 5 commits intomicrosoft:release/202511from
Flickdm:pr/add_host_based_tests

Conversation

@Flickdm
Copy link
Copy Markdown
Member

@Flickdm Flickdm commented Mar 23, 2026

Description

Adds a number of Host Based Unit Tests that were previously not covered.

Only one bug found with these changes:

microsoft/mu_crypto_release#201

These can likely be brought upstream

For details on how to complete these options and their meaning refer to CONTRIBUTING.md.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Host Based Unit Tests

Integration Instructions

N/A

Flickdm added 5 commits March 22, 2026 20:28
EcTests.c: add tampered-message and cross-key ECDSA rejection tests
to confirm that EcDsaVerify rejects a modified hash and a signature
verified against a different key pair.

RsaPssTests.c: add SHA-384 and SHA-512 PSS round-trip tests and a
tampered-message rejection test to verify that RsaPssSign and
RsaPssVerify operate correctly across hash algorithms and reject
corrupted message digests.

RsaTests.c: add a cross-key PKCS#1 verify rejection test to confirm
that RsaPkcs1Verify fails when the public key does not match the
signing key.

X509Tests.c: add tests for X509GetSubjectName, GetCommonName,
GetOrganizationName (NOT_FOUND case), GetSignatureAlgorithm, and
GetTBSCert to improve X.509 parsing coverage.
…ist tests

Add TestVerifyPkcs7GetSigners to exercise the two previously untested
signer-extraction APIs:

- Pkcs7GetSigners: verify that signing certificates can be extracted
  from a freshly-signed PKCS#7 blob, and that Pkcs7FreeSigners
  correctly releases both CertStack and TrustedCert.

- Pkcs7GetCertificatesList: verify chained and unchained certificate
  list extraction from the same blob.

This test also served as the regression trigger that exposed a bug in
Pkcs7GetCertificatesList (passing &NewP7Data directly to d2i_PKCS7,
which advances the pointer past parsed bytes, causing free() to be
called on a non-base address).
Add two new test functions to X509Tests.c covering previously untested APIs:

TestVerifyX509ConstructFree:
- X509ConstructCertificate: wrap DER cert bytes into an opaque X509 object
- X509ConstructCertificateStack: build a multi-cert stack with variadic args
- X509Free / X509StackFree: release both object types without leaking

TestVerifyX509KeyUsage (uses mTestEndCert which has v3_end extensions):
- X509GetKeyUsage: verify Digital Signature, Non Repudiation, and Key
  Encipherment bits are set in the returned OpenSSL KU bitmask
- X509GetExtendedKeyUsage: size-query then full retrieval of EKU OID bytes
- X509GetExtendedBasicConstraints: size-query then full retrieval of the
  Basic Constraints extension (CA:FALSE on the end-entity cert)
…tests

Add TestVerifyPkcs7Encrypt to cover the two remaining untested PKCS#7 APIs:

Pkcs7Encrypt:
- Build a recipient X509 stack from TestCert using X509ConstructCertificateStack
- Encrypt a payload with AES-256-CBC and verify non-empty ContentInfo is produced
- Test NULL X509Stack argument rejection

Pkcs7GetAttachedContent:
- Call on a Pkcs7Sign-produced blob (which uses PKCS7_DETACHED)
- Verify the API returns TRUE with Content=NULL / ContentSize=0, confirming
  correct detached-content signalling without crashing
…g tests

Cover two previously untested BaseCryptLib APIs:
- EcPointGetAffineCoordinates: round-trip test generating a key pair and
  verifying the extracted affine coordinates match the original BIGNUMs
- Asn1GetTag: verify correct tag matching advances Ptr and returns length;
  verify tag mismatch restores Ptr to original position

Note: X509ConstructCertificateStack exercises X509ConstructCertificateStackV
internally (covered by commit 3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant