Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down