Repository navigation
Add standalone Rust native primitives under native/ - #982
Gladwin Johnson VR (gladjohn) wants to merge 6 commits into
Conversation
Host the native workspace separately from Python runtime and packaging. Clarify compatible dependency ranges without changing the lockfile. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
There was a problem hiding this comment.
🟡 Changes recommended
Public-only RSA key duplication incorrectly returns null when private material is absent, and the documented relative provider path fails ABI validation.
2 open issues
What changed in this PR
Adds the pre-release Microsoft.Identity.Native.Primitives project under native/, independently of MSAL Python’s runtime, packaging, and releases.
Changes:
- Imports Rust CNG/OpenSSL primitives, bounded mTLS transport, a C ABI, and native tests and examples.
- Adds Windows CI, Cargo dependency monitoring, and independent build tooling.
- Documents native architecture, security, contribution requirements, and release governance.
| File | Description |
|---|---|
| README.md | Introduces the standalone native project. |
| native/vcpkg.json | Pins the native OpenSSL dependency baseline. |
| native/THIRD-PARTY-NOTICES.md | Documents dependency notice obligations. |
| native/tests/native/support/cng_key.h | Declares CNG test-support functions. |
| native/tests/native/cng_test_pki.c | Generates local certificates and test keys. |
| native/tests/native/cng_provider_test.c | Tests provider signing and export restrictions. |
| native/tests/native/cng_mtls_test_server.c | Supplies loopback mTLS response scenarios. |
| native/SUPPORT.md | Defines pre-release support scope. |
| native/SECURITY.md | Documents vulnerability reporting and review areas. |
| native/scripts/test.ps1 | Runs Debug/Release validation and key auditing. |
| native/scripts/loc.ps1 | Reports production Rust line counts. |
| native/scripts/build.ps1 | Builds and stages native artifacts. |
| native/rustfmt.toml | Configures Rust formatting. |
| native/README.md | Explains native functionality, setup, and usage. |
| native/LICENSE | Supplies the native MIT license. |
| native/include/microsoft_identity_native_primitives.h | Defines the public C ABI and ownership contract. |
| native/include/cng_provider_params.h | Defines provider parameters and limits. |
| native/examples/c/mtls_request.c | Demonstrates a certificate-bound request. |
| native/docs/versioning.md | Defines product, ABI, and dependency versioning. |
| native/docs/security-review.md | Specifies security-review evidence. |
| native/docs/security-model.md | Documents enforced properties and trust boundaries. |
| native/docs/releasing.md | Defines independent native release requirements. |
| native/docs/development.md | Documents contributor setup and engineering practices. |
| native/docs/building-and-testing.md | Describes validation and OpenSSL servicing plans. |
| native/docs/architecture.md | Explains component responsibilities and request flow. |
| native/docs/abi.md | Documents ABI usage, ownership, and errors. |
| native/deny.toml | Configures dependency and license checks. |
| native/crates/rust-tests/tests/key_creation_race.rs | Tests cross-process key-creation convergence. |
| native/crates/rust-tests/src/lib.rs | Adds an ABI-version smoke test. |
| native/crates/rust-tests/src/bin/key-race-helper.rs | Supports concurrent key-creation testing. |
| native/crates/rust-tests/src/bin/key-audit.rs | Detects leftover project test keys. |
| native/crates/rust-tests/Cargo.toml | Defines the Rust conformance-test crate. |
| native/crates/openssl-provider-sys/src/lib.rs | Defines OpenSSL provider and TLS bindings. |
| native/crates/openssl-provider-sys/Cargo.toml | Configures the OpenSSL bindings crate. |
| native/crates/mtls-bridge/src/lib.rs | Exports request and response-management functions. |
| native/crates/mtls-bridge/src/abi.rs | Defines ABI layouts, limits, and errors. |
| native/crates/mtls-bridge/Cargo.toml | Configures the transport library and DLL. |
| native/crates/cng-provider/src/uri.rs | Parses bounded CNG key URIs. |
| native/crates/cng-provider/src/store.rs | Implements OpenSSL STORE key loading. |
| native/crates/cng-provider/src/params.rs | Handles OpenSSL parameter conversion. |
| native/crates/cng-provider/src/lib.rs | Registers provider algorithms and callbacks. |
| native/crates/cng-provider/src/keymgmt.rs | Implements provider key-management operations. |
| native/crates/cng-provider/src/key.rs | Manages opaque keys and public parameters. |
| native/crates/cng-provider/src/error.rs | Produces bounded provider diagnostics. |
| native/crates/cng-provider/src/allocation.rs | Adds fallible allocation helpers and tests. |
| native/crates/cng-provider/Cargo.toml | Configures the CNG provider DLL. |
| native/crates/cng-core/Cargo.toml | Configures the Windows CNG core crate. |
| native/CONTRIBUTING.md | Defines native contribution and validation requirements. |
| native/CMakeLists.txt | Builds external C tests and the example. |
| native/CHANGELOG.md | Records native history and repository migration. |
| native/Cargo.toml | Defines workspace metadata and compatible dependency ranges. |
| native/Cargo.lock | Records exact native dependency versions. |
| native/AGENTS.md | Documents native coding and review guidance. |
| native/.gitignore | Excludes generated native outputs. |
| native/.gitattributes | Sets native text and binary handling. |
| native/.editorconfig | Establishes native editor formatting. |
| .github/workflows/native-primitives.yml | Adds independent Windows validation and dependency checks. |
| .github/dependabot.yml | Adds Cargo monitoring for /native. |
Review effort: Balanced
Duplicate selected public material when no private material exists. Add an external OpenSSL regression and correct the example DLL path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical issues can produce RSA-PSS signatures inconsistent with advertised MGF1 parameters and undercount IPv6 request headers, risking unwiped sensitive plaintext during reallocation.
2 open issues
2 resolved since last review
Review effort: Balanced
Reject retained explicit MGF1 mismatches before signature state updates. Account for IPv6 brackets before reserving the plaintext request buffer. Add sequential-update and exact wire-limit regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because an unpublished documentation finding indicates the quick-start build command fails on a clean checkout before its required configuration step is introduced.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
Move CMake/vcpkg setup ahead of the first quick-start build and reuse the quick-start configuration steps from the build/test section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
|
Confirmed the quick-start documentation finding against the build script: build.ps1 requires build/vcpkg_installed/x64-windows/include/openssl/ssl.h before it can build, but the README previously showed the build command before CMake/vcpkg configuration. Fixed in c7a1931: configuration now precedes the first build, the starting directory is explicit, and the later build/test section reuses those steps. This is documentation-only; the configuration-first sequence was already used during the clean-checkout native validation. |
Guard sensitive copies before validation can fail. Accept HTTP token field names and surrounding Content-Length whitespace while preserving strict framing. Add allocation-observer and protocol regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to weigh unpublished findings involving sensitive-data cleanup gaps on failure paths and insufficient bounds on caller-controlled RSA allocations.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
Permit secure delayed TLS client authentication under the existing I/O deadline. Preserve key and signing configuration during null-key context reuse. Bound RSA encodings before conversion and zeroize transient URI/name copies. Add Windows/CNG regressions, with 67 Rust tests per Debug/Release configuration and the complete native matrix passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
|
Addressed the four detailed review findings in 10b146a: secure delayed TLS 1.2 client authentication under the existing total I/O deadline; null-key EVP signing-context reuse with retained key/digest/PSS/MGF1/salt and fresh hashing; RSA encoding bounds before BIGNUM conversion (2056 modulus bytes, 8 exponent bytes, mathematical limits preserved); and zeroizing NUL-terminated URI/module-name, decoded-name, STORE-description and UTF-16 identifier storage. The external regressions reproduced the reuse and delayed-authentication failures against the preceding Windows DLLs. The full pinned Windows/OpenSSL 3.6.3 Debug/Release matrix now passes: 67 Rust tests per configuration, external provider/ABI/mTLS tests, key cleanup, formatting/checks/Clippy, audit and dependency policy. The delayed-authentication server forces a full secure handshake after receiving token-bound headers, and the deadline regression remains enforced. No unsafe legacy renegotiation, relaxed peer/hostname verification, private-key policy, ABI, or Python-package changes. Only an existing internal crate was added as a test dependency. This validates the loopback flow, not a live Key Vault request or production security approval. |



Summary
Host the pre-release Microsoft.Identity.Native.Primitives project under top-level
native/, separate from themsal/Python package./native.Review feedback addressed
The source review noted that hardcoded crate versions could make future updates less flexible. Workspace dependencies now show explicit lower and upper compatible bounds, matching this repository's library dependency guidance.
The original Cargo requirements were already compatible caret ranges; this is a clarification, not a widening of compatibility or an unreviewed dependency upgrade. Locked external versions and checksums are unchanged. The latest follow-up adds only the existing internal
cng-corecrate as anmtls-bridgetest dependency, with one corresponding lockfile graph entry. All native crates continue to inherit product-version and external-dependency metadata from the workspace. The native versioning guide documents targeted updates, lockfile review, complete validation, and compatibility review before changing upper bounds.Follow-up PR review fixes
Correct
keymgmt_dupwhen OpenSSL requests all components for a public-only RSA key: duplicate the available selected public material rather than fail because private material is absent. Private-only requests still fail when no private key exists; opaque private-key duplication and private-export restrictions remain intact.Add an external C regression through
EVP_PKEY_dup, including validation after freeing the original public key and rejection of private-key validation/export. It reproduced the failure before the fix and passes in Debug and Release afterward.Resolve the README example's provider DLL to an absolute path before passing it to the native ABI; do not weaken the ABI's absolute-path validation.
Put CMake/vcpkg configuration before the first quick-start build command so a clean checkout creates the project-local OpenSSL installation and native test harness before running the build script.
Reject a digest update that conflicts with retained explicit PSS MGF1 state before committing any signature-context changes; use the same validation as initial digest/MGF1 setup. A sequential-update regression verifies rejection without state mutation and acceptance when both digests change together.
Count IPv6 Host brackets in generated-header and total-request limits and the fallible reservation made before copying plaintext. A boundary regression covers ports 443/8443, exact/one-byte-over limits, and empty/maximum-sized bodies.
Wrap copied request paths, STORE URIs, header values, and bodies in zeroizing storage immediately, before further validation can fail. Allocation-observer regressions inspect initialized bytes before deallocation for duplicate/rejected headers, excessive connection/I/O timeouts, and a later failure after copying a STORE URI. The observer exists only in Rust tests.
Accept HTTP token punctuation in response field names and surrounding SP/HTAB in Content-Length. Regressions retain rejection of whitespace in field names, duplicate framing, empty/nondecimal lengths, internal whitespace, and comma-separated lengths. Request header allowlisting, response bounds, transfer-encoding rejection, and TLS verification remain unchanged.
Permit secure server-initiated TLS 1.2 renegotiation for delayed client authentication. The native loopback server now requires the token-bound HTTP header before requesting the client certificate, forces a full rather than resumed handshake, and verifies the certificate after renegotiation. A delayed-response case verifies that renegotiation does not reset the total I/O deadline. No unsafe legacy-renegotiation options, relaxed peer/hostname verification, or new TLS versions are enabled.
Support null-key
EVP_DigestSignInit_exreuse by retaining the existing CNG key, digest, padding, explicit MGF1, and salt configuration while rebuilding the message hash. Initialization is staged before replacing the previous context. External EVP tests sign independent messages, reuse without updates, apply paired digest/MGF1 updates, and reuse again; the default provider verifies every signature, including SHA384/PSS with explicit 20-byte salt.Check RSA parameter type, data presence, and finite encoding budgets before any BIGNUM conversion. The modulus permits 2,056 bytes and the exponent eight bytes for bounded native-word padding; mathematical 16,384-bit/32-bit limits and oddness checks remain enforced. A test-only conversion observer verifies oversized significant and zero-padded encodings never reach conversion; boundary/padding/math regressions cover accepted and rejected values.
Keep NUL-terminated STORE URI/module-name copies, decoded provider/key names, STORE descriptions, and temporary UTF-16 identifiers in zeroizing storage. Allocation observers cover successful and failing real CNG STORE loads, plus failed decoded-name parsing. The successful-load fixture creates and deletes only a process-owned test key.
The detailed review supplied actionable findings in the previously unspecified OpenSSL/provider area; the four issues above have been assessed and fixed. This is not a claim of remote exploitability, live Key Vault validation, or human security approval.
Scope and compatibility
This remains a Windows x64, pre-release native project. The existing OpenSSL 3.6.3 development baseline and documented requirement to move to a reviewed supported baseline before production release are unchanged.
Provenance
Imported from
AzureAD/microsoft.identity.native.primitivescommit8c54819f52d9d18ff12f69b3c79ee18f630569b6(the project introduced in source PR #1). Source Git history is not imported.The initial import verified all 40 implementation, ABI, native test/example, build/test script, lockfile, CMake, and vcpkg files byte-identical to the source checkout. Follow-up review fixes change the duplication callback, signature initialization/parameter validation, RSA import bounds, HTTP request-size accounting, sensitive-copy cleanup, response-header parsing, TLS renegotiation policy, and corresponding tests. The ABI, scripts, external dependency versions/checksums, and CMake/vcpkg baseline remain unchanged; the internal test-dependency graph change is described above.
Validation
Passed locally on Windows x64 with Rust 1.97.1 MSVC, Visual Studio 2022, and the pinned OpenSSL 3.6.3 baseline:
native\scripts\test.ps1Debug/Release matrix: formatting, locked workspace/all-target checks, warnings-denied Clippy, 67 Rust tests per configuration, external native provider and ABI/mTLS integration tests, and project-owned CNG test-key cleanup audit.cargo auditandcargo deny check.twine check.The external dependency set and native ABI are unchanged; this PR does not claim a new production security approval or release.