-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add support for client certificate password and test with real services that require client certificate auth #32
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
98eed7f
Add support for client certificate password and test with some real s…
3c26f44
Add correct param
f3a11fa
Update to read certificate from store instead of file
4d9e928
Merge branch 'master' of https://github.com/StefH/WireMock.Net
3358e8e
Add support for client certificate password and test with some real s…
70668b2
Add correct param
7dc46a1
Merge branch 'master' of https://github.com/phillee007/WireMock.Net
699156a
Fixup PR issues
753522f
Merge branch 'master' of https://github.com/phillee007/WireMock.Net
1094af7
Add support for client certificate password and test with some real s…
2648034
Add correct param
a248991
Fixup PR issues
af2a035
Merge branch 'master' of https://github.com/phillee007/WireMock.Net
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace WireMock.Http | ||
{ | ||
internal static class CertificateUtil | ||
{ | ||
public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName) | ||
{ | ||
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine); | ||
try | ||
{ | ||
//Certificate must be in the local machine store | ||
certStore.Open(OpenFlags.ReadOnly); | ||
|
||
//Attempt to find by thumbprint first | ||
var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjectName, false); | ||
if (matchingCertificates.Count == 0) | ||
{ | ||
//Fallback to subject name | ||
matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubjectName, false); | ||
if (matchingCertificates.Count == 0) | ||
{ | ||
// No certificates matched the search criteria. | ||
throw new Exception($"No certificate found with Thumbprint or SubjectName '{thumbprintOrSubjectName}'"); | ||
} | ||
} | ||
// Use the first matching certificate. | ||
return matchingCertificates[0]; | ||
} | ||
finally | ||
{ | ||
if (certStore != null) | ||
{ | ||
#if NETSTANDARD || NET46 | ||
certStore.Dispose(); | ||
#else | ||
certStore.Close(); | ||
#endif | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,11 @@ private void InitProxyAndRecord(ProxyAndRecordSettings settings) | |
|
||
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, ProxyAndRecordSettings settings) | ||
{ | ||
var responseMessage = await HttpClientHelper.SendAsync(requestMessage, settings.Url); | ||
var requestUri = new Uri(requestMessage.Url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, please explain why this needed. |
||
var proxyUri = new Uri(settings.Url); | ||
var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery); | ||
|
||
var responseMessage = await HttpClientHelper.SendAsync(requestMessage, proxyUriWithRequestPathAndQuery.AbsoluteUri, settings.X509Certificate2ThumbprintOrSubjectName); | ||
|
||
if (settings.SaveMapping) | ||
{ | ||
|
@@ -158,7 +162,7 @@ private ResponseMessage SettingsGet(RequestMessage requestMessage) | |
var model = new SettingsModel | ||
{ | ||
AllowPartialMapping = _options.AllowPartialMapping, | ||
GlobalProcessingDelay = (int?) _options.RequestProcessingDelay?.TotalMilliseconds | ||
GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds | ||
}; | ||
|
||
return ToJson(model); | ||
|
@@ -513,7 +517,13 @@ private IResponseBuilder InitResponseBuilder(ResponseModel responseModel) | |
|
||
if (!string.IsNullOrEmpty(responseModel.ProxyUrl)) | ||
{ | ||
return responseBuilder.WithProxy(responseModel.ProxyUrl); | ||
if (string.IsNullOrEmpty(responseModel.X509Certificate2ThumbprintOrSubjectName)) | ||
{ | ||
return responseBuilder.WithProxy(responseModel.ProxyUrl); | ||
} | ||
|
||
return responseBuilder.WithProxy(responseModel.ProxyUrl, responseModel.X509Certificate2ThumbprintOrSubjectName); | ||
|
||
} | ||
|
||
if (responseModel.StatusCode.HasValue) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
Why not just add the new parameter (X509Certificate2Password) to the method?