Skip to content

Client certificate authentication works with .NET 8 and fails with .NET 9 #1365

Closed

Description

@drauch

Describe the bug

I'm using the following server settings:

    _mockSignPathApi = WireMockServer.Start(
        new WireMockServerSettings
        {
          Port = 8888,
          ClientCertificateMode = ClientCertificateMode.AllowCertificate,
          AcceptAnyClientCertificate = true,
          UseSSL = true
        });

and use your own client_cert.pfx from your test suite as client certificate. In .NET 8 this set up works, in .NET 9 this fails (i.e, the request fails, I don't even come to the point where I could assert whether it's there).

Expected behavior:

It should work with .NET 9 too.

Other related info

Newest WireMock.NET version.

Activity

  1. added
    bug
    on Oct 12, 2025
  2. drauch commented on Oct 12, 2025

    @drauch
    Author

    Ah the culprit seems to be your client_cert.pfx (https://github.com/wiremock/WireMock.Net/blob/master/test/WireMock.Net.Tests/client_cert.pfx) in the test suite.

    .NET 8:

    • new X509Certiifcate2(file, "1234") => X509Certificate2 incl. private key

    .NET 9:

    • new X509Certiifcate2(file, "1234") => Access denied exception
    • X509CertificateLoader.LoadPkcs12FromFile(file, "1234") => X509Certificate2 without private key
  3. drauch commented on Oct 12, 2025

    @drauch
    Author

    OK, by default it loads it with the flag EphemeralKeySet which doesn't work.
    Using the flags Exportable | UserKeySet when loading with X509CertificateLoader fixes the problem.

    May it help you when migrating the project to .NET9+ :-)

    Best regards,
    D.R.

  4. StefH commented on Oct 12, 2025

    @StefH
    Collaborator

    @drauch
    I keep this bug open as reminder.

  5. reopened this on Oct 12, 2025
  6. self-assigned this
    on Jan 3, 2026
  7. StefH commented on Nov 12, 2026

    @StefH
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions