mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Support In-Memory SSL Certificate #692
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ranthalion on GitHub (May 22, 2025).
Originally assigned to: @StefH on GitHub.
Is your feature request related to a problem? Please describe.
WireMock.NET expects to explicitly and manually load the SSL certificate either from the file system, or from a Windows certificate store.
I need to load the SSL certificate from Azure KeyVault. I am not able to write the certificate to disk because the private key is not exportable and I don't have write access to a file system in the deployed environment.
Describe the solution you'd like
I'd like to provide the actual SSL certificate to the WireMock.Net server instead of relying on it to load a certficae. This could possibly be implemented in one of the following ways:
Describe alternatives you've considered
Is your feature request supported by WireMock (java version)? Please provide details.
I don't have experience with the java version. I don't think WireMock and WireMock.Net currently have parity in SSL certificate suppport. I only see support for java keystores.
Additional context
TLDR - I have the SSL cert in memory, but I can't seem to get WireMock.NET to use it.
@StefH commented on GitHub (May 24, 2025):
I think this can be added.
Is your certificate a .PEM or .PFX ? And you also have a password?
@StefH commented on GitHub (May 24, 2025):
@Ranthalion
Would this be your solution?
@StefH commented on GitHub (May 26, 2025):
@Ranthalion
If you like, you can test this preview version
1.8.8-ci-110112.See https://github.com/wiremock/WireMock.Net/wiki/MyGet-preview-versions for details.
@Ranthalion commented on GitHub (May 27, 2025):
Thanks @StefH. The certificate is downloaded from KeyVault as a full X509Certificate2. I've reviewed the changes and will try this today.
@Ranthalion commented on GitHub (May 27, 2025):
I'm encountering the same issue with the new implementation. I'm not able to convert the existing X509Certificate2 into a byte array since the private key is not exportable.
When I download the certificate from KeyVault, it already has the private key included, and it is already a X509Certificate2. X509Certificate2.Export fails since the key is not exportable.
X509Certificate2.GetRawCertData does not export the private key and results in a run time error "NotSupportedException: The server mode SSL must use a certificate with the associated private key."
Would you consider simply allowing an existing X509Certificate2 to be set on WireMockServerSettings so that an existing certificate in memory would not require any additional twiddling and transformations?
@Ranthalion commented on GitHub (May 27, 2025):
I've pulled the most recent preview build (1.8.8-ci-110115) and directly providing the X509 certificate works perfectly for me!
I don't personally see value in supporting a byte array version of the certificate, especially as that constructor is obsolete as of .NET 9 (see ctor and syslib0057).
@Ranthalion commented on GitHub (Jun 3, 2025):
@StefH Unfortunately, I can't seem to neither edit the wiki, nor push a branch and submit a PR to update the wiki. If you are interested, I was going to propose the following edits.
Using-HTTPS-(SSL).md replaced HTTPS and certifiates section starting on line 14.
Settings.md replaced CertificateSettings section starting on line 22
@StefH commented on GitHub (Jun 3, 2025):
@Ranthalion
Thanks. I've copied your proposal.