Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 377017f

Browse files
committed
rename cleanup
1 parent 042a3a0 commit 377017f

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,41 @@ internal WinCertificateMaker(ExceptionHandler exceptionFunc)
7474
/// <summary>
7575
/// Make certificate.
7676
/// </summary>
77-
/// <param name="sSubjectCN"></param>
78-
/// <param name="isRoot"></param>
79-
/// <param name="signingCert"></param>
80-
/// <returns></returns>
8177
public X509Certificate2 MakeCertificate(string sSubjectCN, bool isRoot, X509Certificate2 signingCert = null)
8278
{
83-
return makeCertificateInternal(sSubjectCN, isRoot, true, signingCert);
79+
return makeCertificate(sSubjectCN, isRoot, true, signingCert);
80+
}
81+
82+
private X509Certificate2 makeCertificate(string sSubjectCN, bool isRoot,
83+
bool switchToMTAIfNeeded, X509Certificate2 signingCert = null,
84+
CancellationToken cancellationToken = default)
85+
{
86+
if (switchToMTAIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
87+
{
88+
return Task.Run(() => makeCertificate(sSubjectCN, isRoot, false, signingCert),
89+
cancellationToken).Result;
90+
}
91+
92+
// Subject
93+
string fullSubject = $"CN={sSubjectCN}";
94+
95+
// Sig Algo
96+
const string hashAlgo = "SHA256";
97+
98+
// Grace Days
99+
const int graceDays = -366;
100+
101+
// ValiDays
102+
const int validDays = 1825;
103+
104+
// KeyLength
105+
const int keyLength = 2048;
106+
107+
var graceTime = DateTime.Now.AddDays(graceDays);
108+
var now = DateTime.Now;
109+
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
110+
now.AddDays(validDays), isRoot ? null : signingCert);
111+
return certificate;
84112
}
85113

86114
private X509Certificate2 makeCertificate(bool isRoot, string subject, string fullSubject,
@@ -271,39 +299,9 @@ private X509Certificate2 makeCertificate(bool isRoot, string subject, string ful
271299

272300
string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null,
273301
x509Enrollment, typeValue);
302+
274303
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
275304
}
276305

277-
private X509Certificate2 makeCertificateInternal(string sSubjectCN, bool isRoot,
278-
bool switchToMTAIfNeeded, X509Certificate2 signingCert = null,
279-
CancellationToken cancellationToken = default)
280-
{
281-
if (switchToMTAIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
282-
{
283-
return Task.Run(() => makeCertificateInternal(sSubjectCN, isRoot, false, signingCert),
284-
cancellationToken).Result;
285-
}
286-
287-
// Subject
288-
string fullSubject = $"CN={sSubjectCN}";
289-
290-
// Sig Algo
291-
const string hashAlgo = "SHA256";
292-
293-
// Grace Days
294-
const int graceDays = -366;
295-
296-
// ValiDays
297-
const int validDays = 1825;
298-
299-
// KeyLength
300-
const int keyLength = 2048;
301-
302-
var graceTime = DateTime.Now.AddDays(graceDays);
303-
var now = DateTime.Now;
304-
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
305-
now.AddDays(validDays), isRoot ? null : signingCert);
306-
return certificate;
307-
}
308306
}
309307
}

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ await handleWebSocketUpgrade(httpCmd, args, request,
228228
}
229229

230230
// construct the web request that we are going to issue on behalf of the client.
231-
await handleHttpSessionRequestInternal(serverConnection, args);
231+
await handleHttpSessionRequest(serverConnection, args);
232232
return true;
233233

234234
}, generator, connection);
@@ -312,7 +312,7 @@ await tcpConnectionFactory.Release(connection,
312312
/// <param name="serverConnection">The tcp connection.</param>
313313
/// <param name="args">The session event arguments.</param>
314314
/// <returns></returns>
315-
private async Task handleHttpSessionRequestInternal(TcpServerConnection serverConnection, SessionEventArgs args)
315+
private async Task handleHttpSessionRequest(TcpServerConnection serverConnection, SessionEventArgs args)
316316
{
317317
var cancellationToken = args.CancellationTokenSource.Token;
318318
var request = args.WebSession.Request;

Titanium.Web.Proxy/ResponseHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args)
8080
{
8181
// clear current response
8282
await args.ClearResponse(cancellationToken);
83-
await handleHttpSessionRequestInternal(args.WebSession.ServerConnection, args);
83+
await handleHttpSessionRequest(args.WebSession.ServerConnection, args);
8484
return;
8585
}
8686

0 commit comments

Comments
 (0)