mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Support for PEM certificates when using ssl #433
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 @kriebb on GitHub (Aug 11, 2022).
Originally assigned to: @StefH on GitHub.
Is your feature request related to a problem? Please describe.
When running dotnet test on a builderserver using systemtests with Wiremock ssl custom certificates, a pfx can be specified, but gives problems when loading the pfx on a build server:
I can replay this on a buildserver creating a test just running this code
However when using the PEM format, this works.
Describe the solution you'd like
In the CertificateLoader you have the code
You can modify the if statements to look at the extension.
If(filepath.Endswith(pem)return
X509.LoadFromPem(filepath,password)where the password is the filepath to the keyOther solution can be to use a
IX509Certificate2Factorythat you can supply using the services or to the add it to the settings and when that is available, use the factory... any suggestions?
Describe alternatives you've considered
Try to persude the devops people to give access to the certification store
google, and try to convert the pfx to other supported pfx`s formats like DER.
Is your feature request supported by WireMock (java version)? Please provide details.
PEM doesnt seem to be supported. Only jwks on wiremock.org
Additional context
@StefH commented on GitHub (Aug 11, 2022):
The easiest is to use
If(filepath.Endswith(pem).Please note that this is only supported for netcoreapp3.1 ; .NET 5.0 and higher.
You can try preview version
1.5.3-ci-16350
@kriebb commented on GitHub (Aug 11, 2022):
Thx for your fast response!
tried it, but somehow got this message:
Use it like this:
this is also more helpfull
Seems like something is not working with Kestrel en Pem x509Certificate2.
According to this post: https://stackoverflow.com/questions/67147703/get-the-server-mode-ssl-must-use-a-certificate-with-the-associated-private-key
The pfx needs to be created inmemory from the pem file and exported with a random key then.
Something to tryout tough. sigh
Don't know if you want o include something like this, so I can try it out? (copy paste from the stackoverflow tough.
If however, you'd rather have me test it in a personal project to mimic it, let me know.
@StefH commented on GitHub (Aug 11, 2022):
Can you try
1.5.3-ci-16353
@kriebb commented on GitHub (Aug 11, 2022):
Yes,
Same result:
settings are used like this:
other stacktraces that be usefull
I did see you, you didnt do the "trick" with the line
certificate.Export(X509ContentType.Pfx, pass), passwich I can understand. I guess it will also try to have some rights again for accessing the cert store. But I didnt try it out yet.@StefH commented on GitHub (Aug 11, 2022):
Code updated with:
return new X509Certificate2(certificate.Export(X509ContentType.Pfx, pass), pass);
New preview will be available within few minutes.
@kriebb commented on GitHub (Aug 11, 2022):
blush what is the preview? cant seem to find it on actions ?
will try it tomorrow :)
@StefH commented on GitHub (Aug 11, 2022):
@kriebb
See this wiki:
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Also if you can send me test PEM = password (or tell me how to generate it), I can also test on my machine.
@StefH commented on GitHub (Aug 11, 2022):
Latest preview (1.5.3-ci-16357) should work fine.
I based my example + logic on https://www.scottbrady91.com/c-sharp/pem-loading-in-dotnet-core-and-dotnet
See https://github.com/WireMock-Net/WireMock.Net/pull/787/files#diff-721297a29d1cb2c8d0ca5463eea9738306dd5416115e04711d2c7bf20576d71b
@kriebb commented on GitHub (Aug 12, 2022):
Sorry, the same behavior occurs.
However, intresting read that you mention.
When I read at the end:
So you cant pass an x509Certificate to Kestrel, because it fucks something up in windows when opening an SSLStream ( as designed it seems)
The CI pipeline at the company dont give any access to the system keyset. So the current solution that is built in ( works fine on my machine tough)
However, when I read further more on:
So just passing filepaths to the KestrelEndPointOptions should be able to work.
Are you in for a final try? after then, I give up. But that article that you mentioned, really confirms what I was thinking, You dont need access to the store using PEM ( or am I misreading it?)
You asked on how I was creating the PEM
Using the following:
https://www.cryptool.org/en/cto/openssl
@StefH commented on GitHub (Aug 12, 2022):
1
BTW : Yesterday I did quickly test creating an RSA Certificate using that website, however I found that only a EC Certificate did work in my example app.
So can you also try that?
2
The Kestrel options you mention:
This is already supported by WireMock.Net, see https://github.com/WireMock-Net/WireMock.Net/wiki/KestrelServerOptions
@StefH commented on GitHub (Aug 12, 2022):
@kriebb RSA does also work when I follow https://www.scottbrady91.com/openssl/creating-rsa-keys-using-openssl
See my PR for details.
@kriebb commented on GitHub (Aug 16, 2022):
Seems to work 👍
What also a good way of having a valid certificate (if you work with local host is using the dotnet dev-certs https -v -ep $(HOME).aspnet\https --format pem"
@StefH commented on GitHub (Aug 16, 2022):
OK, I'll merge the code to master and close this issue.