Commit bbd3f765 authored by justcoding121's avatar justcoding121

#782 use 825 valid days to accomodate iOS 13

parent bf8dd66b
...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// </summary> /// </summary>
internal class BCCertificateMaker : ICertificateMaker internal class BCCertificateMaker : ICertificateMaker
{ {
private const int certificateValidDays = 1825; private readonly int certificateValidDays;
private const int certificateGraceDays = 366; private const int certificateGraceDays = 366;
// The FriendlyName value cannot be set on Unix. // The FriendlyName value cannot be set on Unix.
...@@ -35,8 +35,9 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -35,8 +35,9 @@ namespace Titanium.Web.Proxy.Network.Certificate
private readonly ExceptionHandler exceptionFunc; private readonly ExceptionHandler exceptionFunc;
internal BCCertificateMaker(ExceptionHandler exceptionFunc) internal BCCertificateMaker(ExceptionHandler exceptionFunc, int certificateValidDays)
{ {
this.certificateValidDays = certificateValidDays;
this.exceptionFunc = exceptionFunc; this.exceptionFunc = exceptionFunc;
} }
......
...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// </summary> /// </summary>
internal class BCCertificateMakerFast : ICertificateMaker internal class BCCertificateMakerFast : ICertificateMaker
{ {
private const int certificateValidDays = 1825; private int certificateValidDays;
private const int certificateGraceDays = 366; private const int certificateGraceDays = 366;
// The FriendlyName value cannot be set on Unix. // The FriendlyName value cannot be set on Unix.
...@@ -37,8 +37,9 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -37,8 +37,9 @@ namespace Titanium.Web.Proxy.Network.Certificate
public AsymmetricCipherKeyPair KeyPair { get; set; } public AsymmetricCipherKeyPair KeyPair { get; set; }
internal BCCertificateMakerFast(ExceptionHandler exceptionFunc) internal BCCertificateMakerFast(ExceptionHandler exceptionFunc, int certificateValidDays)
{ {
this.certificateValidDays = certificateValidDays;
this.exceptionFunc = exceptionFunc; this.exceptionFunc = exceptionFunc;
KeyPair = GenerateKeyPair(); KeyPair = GenerateKeyPair();
} }
......
...@@ -73,14 +73,14 @@ namespace Titanium.Web.Proxy.Network ...@@ -73,14 +73,14 @@ namespace Titanium.Web.Proxy.Network
switch (engine) switch (engine)
{ {
case CertificateEngine.BouncyCastle: case CertificateEngine.BouncyCastle:
certEngineValue = new BCCertificateMaker(ExceptionFunc); certEngineValue = new BCCertificateMaker(ExceptionFunc, CertificateValidDays);
break; break;
case CertificateEngine.BouncyCastleFast: case CertificateEngine.BouncyCastleFast:
certEngineValue = new BCCertificateMakerFast(ExceptionFunc); certEngineValue = new BCCertificateMakerFast(ExceptionFunc, CertificateValidDays);
break; break;
case CertificateEngine.DefaultWindows: case CertificateEngine.DefaultWindows:
default: default:
certEngineValue = new WinCertificateMaker(ExceptionFunc); certEngineValue = new WinCertificateMaker(ExceptionFunc, CertificateValidDays);
break; break;
} }
} }
...@@ -204,6 +204,12 @@ namespace Titanium.Web.Proxy.Network ...@@ -204,6 +204,12 @@ namespace Titanium.Web.Proxy.Network
/// </summary> /// </summary>
public string PfxFilePath { get; set; } = string.Empty; public string PfxFilePath { get; set; } = string.Empty;
/// <summary>
/// Number of Days generated HTTPS certificates are valid for.
/// Maximum allowed on iOS 13 is 825 days and it is the default.
/// </summary>
public int CertificateValidDays { get; set; } = 825;
/// <summary> /// <summary>
/// Name of the root certificate issuer. /// Name of the root certificate issuer.
/// (This is valid only when RootCertificate property is not set.) /// (This is valid only when RootCertificate property is not set.)
......
...@@ -13,6 +13,9 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -13,6 +13,9 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// </summary> /// </summary>
internal class WinCertificateMaker : ICertificateMaker internal class WinCertificateMaker : ICertificateMaker
{ {
// Validity Days for Root Certificates Generated.
private int certificateValidDays;
private readonly ExceptionHandler exceptionFunc; private readonly ExceptionHandler exceptionFunc;
private readonly string sProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"; private readonly string sProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";
...@@ -49,8 +52,9 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -49,8 +52,9 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
internal WinCertificateMaker(ExceptionHandler exceptionFunc) internal WinCertificateMaker(ExceptionHandler exceptionFunc, int certificateValidDays)
{ {
this.certificateValidDays = certificateValidDays;
this.exceptionFunc = exceptionFunc; this.exceptionFunc = exceptionFunc;
typeX500DN = Type.GetTypeFromProgID("X509Enrollment.CX500DistinguishedName", true); typeX500DN = Type.GetTypeFromProgID("X509Enrollment.CX500DistinguishedName", true);
...@@ -99,16 +103,13 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -99,16 +103,13 @@ namespace Titanium.Web.Proxy.Network.Certificate
// Grace Days // Grace Days
const int graceDays = -366; const int graceDays = -366;
// ValiDays
const int validDays = 1825;
// KeyLength // KeyLength
const int keyLength = 2048; const int keyLength = 2048;
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var graceTime = now.AddDays(graceDays); var graceTime = now.AddDays(graceDays);
var certificate = makeCertificate(sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime, var certificate = makeCertificate(sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), signingCertificate); now.AddDays(certificateValidDays), signingCertificate);
return certificate; return certificate;
} }
......
...@@ -88,7 +88,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -88,7 +88,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
// get the currently running framework name and version (EX: .NETFramework,Version=v4.5.1) (Ex: .NETCoreApp,Version=v2.0) // get the currently running framework name and version (EX: .NETFramework,Version=v4.5.1) (Ex: .NETCoreApp,Version=v2.0)
string ver = Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName; string? ver = Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
if (ver == null) if (ver == null)
return false; // play it safe if we can not figure out what the framework is return false; // play it safe if we can not figure out what the framework is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment