Add option to provide X509Certificate (#1303)

* Add option to provide X509CertificateRawData

* X509Certificate

* remove X509CertificateRawData
This commit is contained in:
Stef Heyenrath
2025-05-28 07:15:46 +02:00
committed by GitHub
parent 3438539138
commit 86d4717216
8 changed files with 138 additions and 123 deletions

View File

@@ -1,5 +1,6 @@
// Copyright © WireMock.Net
using System.Security.Cryptography.X509Certificates;
using JetBrains.Annotations;
namespace WireMock.Settings;
@@ -9,36 +10,44 @@ namespace WireMock.Settings;
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// X509CertificateFilePath should be defined
/// OR
/// X509Certificate should be defined
/// </summary>
public class WireMockCertificateSettings
{
/// <summary>
/// X509 StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
/// X.509 certificate StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
/// </summary>
[PublicAPI]
public string? X509StoreName { get; set; }
/// <summary>
/// X509 StoreLocation (CurrentUser or LocalMachine)
/// X.509 certificate StoreLocation (CurrentUser or LocalMachine)
/// </summary>
[PublicAPI]
public string? X509StoreLocation { get; set; }
/// <summary>
/// X509 Thumbprint or SubjectName (if not defined, the 'host' is used)
/// X.509 certificate Thumbprint or SubjectName (if not defined, the 'host' is used)
/// </summary>
[PublicAPI]
public string? X509StoreThumbprintOrSubjectName { get; set; }
/// <summary>
/// X509Certificate FilePath
/// X.509 certificate FilePath
/// </summary>
[PublicAPI]
public string? X509CertificateFilePath { get; set; }
/// <summary>
/// X509Certificate Password
/// A X.509 certificate instance.
/// </summary>
[PublicAPI]
public X509Certificate2? X509Certificate { get; set; }
/// <summary>
/// X.509 certificate Password
/// </summary>
[PublicAPI]
public string? X509CertificatePassword { get; set; }
@@ -46,10 +55,13 @@ public class WireMockCertificateSettings
/// <summary>
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// X509CertificateFilePath should be defined
/// OR
/// X509Certificate should be defined
/// </summary>
[PublicAPI]
public bool IsDefined =>
!string.IsNullOrEmpty(X509StoreName) && !string.IsNullOrEmpty(X509StoreLocation) ||
!string.IsNullOrEmpty(X509CertificateFilePath);
!string.IsNullOrEmpty(X509CertificateFilePath) ||
X509Certificate != null;
}

View File

@@ -235,7 +235,9 @@ public class WireMockServerSettings
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// X509CertificateFilePath should be defined
/// OR
/// X509Certificate should be defined
/// </summary>
[PublicAPI]
public WireMockCertificateSettings? CertificateSettings { get; set; }