From 5e2fdbb7f6745a9b0a9c9685189501ae2a161e1a Mon Sep 17 00:00:00 2001 From: Kent Friesen Date: Thu, 18 Oct 2018 11:33:04 -0400 Subject: [PATCH] Fixes #509 (BCCertificateMaker issue on Mono) --- .../Network/Certificate/BCCertificateMaker.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs b/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs index 0f04f8c9a..ad621492d 100644 --- a/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs +++ b/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs @@ -16,6 +16,7 @@ using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.X509; +using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Shared; using X509Certificate = Org.BouncyCastle.X509.X509Certificate; @@ -166,7 +167,19 @@ private static X509Certificate2 generateCertificate(string hostName, private static X509Certificate2 withPrivateKey(X509Certificate certificate, AsymmetricKeyParameter privateKey) { const string password = "password"; - var store = new Pkcs12Store(); + Pkcs12Store store = null; + + if(RunTime.IsRunningOnMono) + { + Pkcs12StoreBuilder builder = new Pkcs12StoreBuilder(); + builder.SetUseDerEncoding(true); + store = builder.Build(); + } + else + { + store = new Pkcs12Store(); + } + var entry = new X509CertificateEntry(certificate); store.SetCertificateEntry(certificate.SubjectDN.ToString(), entry);