From 0096f2902d0d2ddd77edd7cb799dc08244bcb090 Mon Sep 17 00:00:00 2001 From: Lukasz Marszal Date: Wed, 30 May 2018 21:31:04 +0200 Subject: [PATCH] Fix PlatformNotSupportedException when running in docker on Linux --- .../Network/Certificate/BCCertificateMaker.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs b/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs index f861bfec0..f25b59608 100644 --- a/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs +++ b/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; @@ -29,10 +30,6 @@ internal class BCCertificateMaker : ICertificateMaker private const int certificateValidDays = 1825; private const int certificateGraceDays = 366; - // The FriendlyName value cannot be set on Unix. - // Set this flag to true when exception detected to avoid further exceptions - private static bool doNotSetFriendlyName; - private readonly ExceptionHandler exceptionFunc; internal BCCertificateMaker(ExceptionHandler exceptionFunc) @@ -146,19 +143,11 @@ private static X509Certificate2 generateCertificate(string hostName, x509Certificate.PrivateKey = DotNetUtilities.ToRSA(rsaparams); #else var x509Certificate = withPrivateKey(certificate, rsaparams); - x509Certificate.FriendlyName = subjectName; #endif - if (!doNotSetFriendlyName) + if (RunTime.IsWindows) { - try - { - x509Certificate.FriendlyName = ProxyConstants.CNRemoverRegex.Replace(subjectName, string.Empty); - } - catch (PlatformNotSupportedException) - { - doNotSetFriendlyName = true; - } + x509Certificate.FriendlyName = ProxyConstants.CNRemoverRegex.Replace(subjectName, string.Empty); } return x509Certificate;