Rig.TUnit.Security.Mtls
0.1.0-beta.2
dotnet add package Rig.TUnit.Security.Mtls --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Security.Mtls -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Security.Mtls" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Security.Mtls" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Security.Mtls" />
paket add Rig.TUnit.Security.Mtls --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Security.Mtls, 0.1.0-beta.2"
#:package Rig.TUnit.Security.Mtls@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Security.Mtls&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Security.Mtls&version=0.1.0-beta.2&prerelease
Rig.TUnit.Security.Mtls
Mutual-TLS fixture — ephemeral self-signed CA + matched client/server leaf certs for Kestrel mTLS tests. No production bypass.
What this package is
An mTLS integration-test fixture. MtlsFixture generates a self-signed
CA plus matched client + server leaf certificates in-memory at fixture
startup; the keys live only for the fixture lifetime and dispose
deterministically. The generated chain validates via the real X.509
stack — suitable for Kestrel mTLS endpoints and HttpClient peer
authentication. No ServerCertificateCustomValidationCallback bypass.
When to use it
- Integration tests for Kestrel endpoints configured with
RequireClientCertificate = true. - Verifying
CertificateAuthenticationmiddleware accepts / rejects chains correctly. - Regression-testing certificate-rotation code paths.
- Not for: unit tests — mTLS requires real TCP + TLS negotiation.
Prerequisites
- .NET 10 SDK
- Kestrel server under test configured for mTLS
- OpenSSL / .NET cert stack available (both are built-in on .NET 10).
Quick start
using Rig.TUnit.Security.Mtls.Fixtures;
await using var fx = new MtlsFixture();
await fx.InitializeAsync();
MtlsAssert.BothSidesAuthenticated(fx.ClientCertificate, fx.ServerCertificate);
Options
| Property | Type | Default | Description |
|---|---|---|---|
CaSubject |
string |
"CN=rigtunit-test-ca" |
CA subject DN |
ClientSubject |
string |
"CN=rigtunit-client" |
Client leaf DN |
ServerSubject |
string |
"CN=rigtunit-server" |
Server leaf DN |
ValidityDays |
int |
365 |
CA + leaf validity window |
Fixture + helper APIs
Rig.TUnit.Security.Mtls.Fixtures.MtlsFixtureRig.TUnit.Security.Mtls.Options.MtlsFixtureOptionsRig.TUnit.Security.Mtls.Builder.MtlsRigBuilderRig.TUnit.Security.Mtls.Assertions.MtlsAssert
Per-test isolation
Each MtlsFixture owns its own CA + leaf certs. Subjects include
IsolationKey when the test uses the default wiring, so parallel
tests produce distinct chains.
Parallelism + performance
- Certificate generation: ~15–25 ms per fixture (CA + 2 leaves + RSA 2048 keys).
- Memory-only — no disk writes, no registry.
- Parallelism: safe; each fixture is independent.
Troubleshooting
AuthenticationExceptionon handshake — client cert not trusted. Ensure the Kestrel config'sClientCertificateMode = RequireCertificateAND the server trusts the fixture's CA (add viafx.Ca).- Cert expired immediately —
ValidityDayswas set ≤ 0; default is 365, don't set it to 0.
See docs/troubleshooting.md#mtls.
Provider quirks + edge cases
- Keys are in-memory
X509Certificate2with exportable private key; do not persist them (the fixture deliberately scopes keys to the fixture lifetime). BothSidesAuthenticatedverifies both leaves chain to the fixture's CA; missing intermediates fail this check.- The generated chain does NOT populate CRL/OCSP; revocation checks must be turned off for these chains.
Benchmarks
See MtlsBenchmarks.cs;
baseline in benchmarks/baseline-005.json. Certificate generation is
the dominant cost and tracked closely.
Related docs
- Architecture diagram
- Glossary
- Family base:
Rig.TUnit.Security
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Bogus (>= 35.6.1)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Rig.TUnit.Security (>= 0.1.0-beta.2)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Security.Mtls:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 42 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 43 | 4/26/2026 |