Commit 377017f9 authored by justcoding121's avatar justcoding121

rename cleanup

parent 042a3a06
...@@ -74,13 +74,41 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -74,13 +74,41 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <summary> /// <summary>
/// Make certificate. /// Make certificate.
/// </summary> /// </summary>
/// <param name="sSubjectCN"></param>
/// <param name="isRoot"></param>
/// <param name="signingCert"></param>
/// <returns></returns>
public X509Certificate2 MakeCertificate(string sSubjectCN, bool isRoot, X509Certificate2 signingCert = null) public X509Certificate2 MakeCertificate(string sSubjectCN, bool isRoot, X509Certificate2 signingCert = null)
{ {
return makeCertificateInternal(sSubjectCN, isRoot, true, signingCert); return makeCertificate(sSubjectCN, isRoot, true, signingCert);
}
private X509Certificate2 makeCertificate(string sSubjectCN, bool isRoot,
bool switchToMTAIfNeeded, X509Certificate2 signingCert = null,
CancellationToken cancellationToken = default)
{
if (switchToMTAIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
{
return Task.Run(() => makeCertificate(sSubjectCN, isRoot, false, signingCert),
cancellationToken).Result;
}
// Subject
string fullSubject = $"CN={sSubjectCN}";
// Sig Algo
const string hashAlgo = "SHA256";
// Grace Days
const int graceDays = -366;
// ValiDays
const int validDays = 1825;
// KeyLength
const int keyLength = 2048;
var graceTime = DateTime.Now.AddDays(graceDays);
var now = DateTime.Now;
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), isRoot ? null : signingCert);
return certificate;
} }
private X509Certificate2 makeCertificate(bool isRoot, string subject, string fullSubject, private X509Certificate2 makeCertificate(bool isRoot, string subject, string fullSubject,
...@@ -271,39 +299,9 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -271,39 +299,9 @@ namespace Titanium.Web.Proxy.Network.Certificate
string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null,
x509Enrollment, typeValue); x509Enrollment, typeValue);
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable); return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
} }
private X509Certificate2 makeCertificateInternal(string sSubjectCN, bool isRoot,
bool switchToMTAIfNeeded, X509Certificate2 signingCert = null,
CancellationToken cancellationToken = default)
{
if (switchToMTAIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
{
return Task.Run(() => makeCertificateInternal(sSubjectCN, isRoot, false, signingCert),
cancellationToken).Result;
}
// Subject
string fullSubject = $"CN={sSubjectCN}";
// Sig Algo
const string hashAlgo = "SHA256";
// Grace Days
const int graceDays = -366;
// ValiDays
const int validDays = 1825;
// KeyLength
const int keyLength = 2048;
var graceTime = DateTime.Now.AddDays(graceDays);
var now = DateTime.Now;
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), isRoot ? null : signingCert);
return certificate;
}
} }
} }
...@@ -228,7 +228,7 @@ namespace Titanium.Web.Proxy ...@@ -228,7 +228,7 @@ namespace Titanium.Web.Proxy
} }
// construct the web request that we are going to issue on behalf of the client. // construct the web request that we are going to issue on behalf of the client.
await handleHttpSessionRequestInternal(serverConnection, args); await handleHttpSessionRequest(serverConnection, args);
return true; return true;
}, generator, connection); }, generator, connection);
...@@ -312,7 +312,7 @@ namespace Titanium.Web.Proxy ...@@ -312,7 +312,7 @@ namespace Titanium.Web.Proxy
/// <param name="serverConnection">The tcp connection.</param> /// <param name="serverConnection">The tcp connection.</param>
/// <param name="args">The session event arguments.</param> /// <param name="args">The session event arguments.</param>
/// <returns></returns> /// <returns></returns>
private async Task handleHttpSessionRequestInternal(TcpServerConnection serverConnection, SessionEventArgs args) private async Task handleHttpSessionRequest(TcpServerConnection serverConnection, SessionEventArgs args)
{ {
var cancellationToken = args.CancellationTokenSource.Token; var cancellationToken = args.CancellationTokenSource.Token;
var request = args.WebSession.Request; var request = args.WebSession.Request;
......
...@@ -80,7 +80,7 @@ namespace Titanium.Web.Proxy ...@@ -80,7 +80,7 @@ namespace Titanium.Web.Proxy
{ {
// clear current response // clear current response
await args.ClearResponse(cancellationToken); await args.ClearResponse(cancellationToken);
await handleHttpSessionRequestInternal(args.WebSession.ServerConnection, args); await handleHttpSessionRequest(args.WebSession.ServerConnection, args);
return; return;
} }
......
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