Skip to content

Add standalone Rust native primitives under native/ - #981

Closed
Gladwin Johnson VR (gladjohn) wants to merge 1 commit into
AzureAD:devfrom
gladjohn:feature/native-primitives
Closed

Gladwin Johnson VR (gladjohn) wants to merge 1 commit into
AzureAD:devfrom
gladjohn:feature/native-primitives

Conversation

@gladjohn

Copy link
Copy Markdown
Contributor

Summary

Host the pre-release Microsoft.Identity.Native.Primitives project under top-level native/, separate from the msal/ Python package.

  • Import the Rust CNG core, OpenSSL provider, bounded mTLS/HTTP transport, stable C ABI, external C conformance tests, and native examples.
  • Preserve the native product/DLL names, ABI, implementation, scripts, dependency lockfile, and pinned vcpkg/OpenSSL baseline.
  • Add independent Windows native CI and Cargo Dependabot monitoring for /native.
  • Retain MSAL Python's existing repository ownership and governance; adapt native contribution, support, release, and development documentation to the new location.

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. Cargo.lock is unchanged. 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.

Scope and compatibility

  • No Python runtime/API, token acquisition, OBO, Managed Identity, or token-cache changes.
  • No Python binding or native DLL loading.
  • No Rust, CNG, CMake, or OpenSSL dependency added to the Python package.
  • No native sources or binaries included in MSAL Python's sdist or wheel.
  • No native ABI or cryptographic/TLS behavior change.
  • Native releases remain independent of MSAL Python package releases.

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.primitives commit 8c54819f52d9d18ff12f69b3c79ee18f630569b6 (the project introduced in source PR #1). Source Git history is not imported.

Verified all 40 implementation, ABI, native test/example, build/test script, lockfile, CMake, and vcpkg files byte-identical to the source checkout.

Validation

Passed locally on Windows x64 with Rust 1.97.1 MSVC, Visual Studio 2022, and the pinned OpenSSL 3.6.3 baseline:

  • Complete native\scripts\test.ps1 Debug/Release matrix: formatting, locked workspace/all-target checks, warnings-denied Clippy, 56 Rust tests per configuration, external native provider and ABI/mTLS integration tests, and project-owned CNG test-key cleanup audit.
  • cargo audit and cargo deny check.
  • Existing Python managed-identity and application tests: 229 passed, plus 652 subtests.
  • Python sdist and pure-Python wheel build; twine check.
  • Artifact inspection: all 24 Python modules unchanged; no native sources/binaries in either distribution; Python package/dependency configuration unchanged.
  • Migrated relative documentation links, native workflow/Dependabot YAML and paths, and staged whitespace checks.

The native implementation and dependency set are unchanged; this PR does not claim a new production security approval or release.

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
Copilot AI balanced review requested due to automatic review settings November 1, 2026 01:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The IPv6 request-sizing bug can exceed header limits and trigger buffer reallocation that leaves authorization-token data in an unwiped old allocation.

3 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 release process.

Changes:

  • Imports Rust CNG/OpenSSL primitives, bounded mTLS transport, a C ABI, and native tests and examples.
  • Adds standalone Windows CI, Cargo dependency monitoring, and build tooling.
  • Adapts native development, security, support, and release documentation to this repository.
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 signing requests.
native/​tests/​native/​cng_provider_test.c Tests provider signing and private-export restrictions.
native/​tests/​native/​cng_mtls_test_server.c Supplies local TLS and HTTP test scenarios.
native/​SUPPORT.md Defines pre-release support scope.
native/​SECURITY.md Documents vulnerability reporting and sensitive areas.
native/​scripts/​test.ps1 Runs Rust and native validation matrices.
native/​scripts/​loc.ps1 Counts production Rust source lines.
native/​scripts/​build.ps1 Builds and stages native artifacts.
native/​rustfmt.toml Configures Rust formatting.
native/​README.md Explains native capabilities and setup.
native/​LICENSE Supplies the native project’s MIT license.
native/​include/​microsoft_identity_native_primitives.h Declares 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 Defines security-review evidence requirements.
native/​docs/​security-model.md Describes enforced properties and trust boundaries.
native/​docs/​releasing.md Defines independent native release requirements.
native/​docs/​development.md Documents contributor setup and practices.
native/​docs/​building-and-testing.md Documents builds, tests, and OpenSSL servicing.
native/​docs/​architecture.md Explains native components and request flow.
native/​docs/​abi.md Documents ABI ownership and error handling.
native/​deny.toml Configures dependency and license policy checks.
native/​crates/​rust-tests/​tests/​key_creation_race.rs Tests concurrent persisted-key creation.
native/​crates/​rust-tests/​src/​lib.rs Adds an ABI-version smoke test.
native/​crates/​rust-tests/​src/​bin/​key-race-helper.rs Supports multiprocess key-creation tests.
native/​crates/​rust-tests/​src/​bin/​key-audit.rs Detects leftover project test keys.
native/​crates/​rust-tests/​Cargo.toml Configures cross-crate test utilities.
native/​crates/​openssl-provider-sys/​src/​lib.rs Defines OpenSSL FFI types and functions.
native/​crates/​openssl-provider-sys/​Cargo.toml Configures the OpenSSL FFI crate.
native/​crates/​mtls-bridge/​src/​lib.rs Exports request execution and response cleanup.
native/​crates/​mtls-bridge/​src/​abi.rs Defines Rust ABI layouts and structured errors.
native/​crates/​mtls-bridge/​Cargo.toml Configures the transport library and DLL.
native/​crates/​cng-provider/​src/​uri.rs Parses bounded CNG STORE URIs.
native/​crates/​cng-provider/​src/​store.rs Implements OpenSSL STORE callbacks.
native/​crates/​cng-provider/​src/​params.rs Handles OpenSSL parameter conversions.
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 Reports bounded provider errors.
native/​crates/​cng-provider/​src/​allocation.rs Supplies fallible allocation helpers.
native/​crates/​cng-provider/​Cargo.toml Configures the OpenSSL provider DLL.
native/​crates/​cng-core/​Cargo.toml Configures the Windows CNG core crate.
native/​CONTRIBUTING.md Adapts native contribution requirements.
native/​CMakeLists.txt Builds external C tests and examples.
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 Rust dependencies.
native/​AGENTS.md Documents native coding and review guidance.
native/​.gitignore Excludes generated native outputs.
native/​.gitattributes Defines native text and binary handling.
native/​.editorconfig Defines native editing conventions.
.github/​workflows/​native-primitives.yml Adds independent Windows validation and dependency checks.
.github/​dependabot.yml Adds Cargo monitoring for /native.

Review effort: Balanced

.checked_add(1)
.and_then(|value| value.checked_add(request.target.len()))
.and_then(|value| value.checked_add(b" HTTP/1.1\r\nHost: ".len()))
.and_then(|value| value.checked_add(request.host.len()))
Comment on lines +102 to +124
let material = if selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY != 0 {
let Some(key) = source.private_key() else {
return null_mut();
};
KeyMaterial::Private(key.clone())
} else {
let Some((modulus, exponent, bits)) = source.public_parts() else {
return null_mut();
};
let Some(modulus) = allocation::try_copy_bytes(modulus) else {
error::raise_memory_failure();
return null_mut();
};
let Some(exponent) = allocation::try_copy_bytes(exponent) else {
error::raise_memory_failure();
return null_mut();
};
KeyMaterial::Public {
modulus,
exponent,
bits,
}
};
Comment thread native/README.md
$env:NATIVE_PRIMITIVES_MTLS_POP_TOKEN = '<already-acquired-token>'

.\artifacts\Release\microsoft_identity_native_example.exe `
.\artifacts\Release\microsoft_identity_native_provider.dll `
@gladjohn

Copy link
Copy Markdown
Contributor Author

Superseded by #982, using feature/native-primitives directly in the AzureAD repository rather than a fork. The implementation and validated commit are unchanged.

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.

2 participants