Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
14087ba5
Commit
14087ba5
authored
Nov 26, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add timeout to WinCert maker, too. Try-catch added
parent
aa3a0147
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
18 deletions
+47
-18
BCCertificateMaker.cs
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
+16
-2
WinCertificateMaker.cs
...nium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
+31
-16
No files found.
Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs
View file @
14087ba5
...
@@ -32,6 +32,13 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -32,6 +32,13 @@ namespace Titanium.Web.Proxy.Network.Certificate
// Set this flag to true when exception detected to avoid further exceptions
// Set this flag to true when exception detected to avoid further exceptions
private
static
bool
doNotSetFriendlyName
;
private
static
bool
doNotSetFriendlyName
;
private
readonly
Action
<
Exception
>
exceptionFunc
;
internal
BCCertificateMaker
(
Action
<
Exception
>
exceptionFunc
)
{
this
.
exceptionFunc
=
exceptionFunc
;
}
/// <summary>
/// <summary>
/// Makes the certificate.
/// Makes the certificate.
/// </summary>
/// </summary>
...
@@ -198,11 +205,18 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -198,11 +205,18 @@ namespace Titanium.Web.Proxy.Network.Certificate
{
{
ThreadPool
.
QueueUserWorkItem
(
o
=>
ThreadPool
.
QueueUserWorkItem
(
o
=>
{
{
certificate
=
MakeCertificateInternal
(
subject
,
isRoot
,
false
,
signingCert
);
try
{
certificate
=
MakeCertificateInternal
(
subject
,
isRoot
,
false
,
signingCert
);
}
catch
(
Exception
ex
)
{
exceptionFunc
.
Invoke
(
new
Exception
(
"Failed to create BC certificate"
,
ex
));
}
if
(!
cancellationToken
.
IsCancellationRequested
)
if
(!
cancellationToken
.
IsCancellationRequested
)
{
{
manualResetEvent
?
.
Set
();
manualResetEvent
.
Set
();
}
}
});
});
...
...
Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
View file @
14087ba5
...
@@ -43,11 +43,14 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -43,11 +43,14 @@ namespace Titanium.Web.Proxy.Network.Certificate
private
object
sharedPrivateKey
;
private
object
sharedPrivateKey
;
private
readonly
Action
<
Exception
>
exceptionFunc
;
/// <summary>
/// <summary>
/// Constructor.
/// Constructor.
/// </summary>
/// </summary>
internal
WinCertificateMaker
()
internal
WinCertificateMaker
(
Action
<
Exception
>
exceptionFunc
)
{
{
this
.
exceptionFunc
=
exceptionFunc
;
typeX500DN
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CX500DistinguishedName"
,
true
);
typeX500DN
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CX500DistinguishedName"
,
true
);
typeX509PrivateKey
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CX509PrivateKey"
,
true
);
typeX509PrivateKey
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CX509PrivateKey"
,
true
);
typeOID
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CObjectId"
,
true
);
typeOID
=
Type
.
GetTypeFromProgID
(
"X509Enrollment.CObjectId"
,
true
);
...
@@ -261,24 +264,36 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -261,24 +264,36 @@ namespace Titanium.Web.Proxy.Network.Certificate
}
}
private
X509Certificate2
MakeCertificateInternal
(
string
sSubjectCN
,
bool
isRoot
,
private
X509Certificate2
MakeCertificateInternal
(
string
sSubjectCN
,
bool
isRoot
,
bool
switchToMTAIfNeeded
,
bool
switchToMTAIfNeeded
,
X509Certificate2
signingCert
=
null
,
X509Certificate2
signingCert
=
null
)
CancellationToken
cancellationToken
=
default
(
CancellationToken
)
)
{
{
X509Certificate2
rCert
=
null
;
X509Certificate2
certificate
=
null
;
#if NET45
if
(
switchToMTAIfNeeded
&&
Thread
.
CurrentThread
.
GetApartmentState
()
!=
ApartmentState
.
MTA
)
if
(
switchToMTAIfNeeded
&&
Thread
.
CurrentThread
.
GetApartmentState
()
!=
ApartmentState
.
MTA
)
{
{
var
manualResetEvent
=
new
ManualResetEvent
(
false
);
using
(
var
manualResetEvent
=
new
ManualResetEventSlim
(
false
))
ThreadPool
.
QueueUserWorkItem
(
o
=>
{
{
rCert
=
MakeCertificateInternal
(
sSubjectCN
,
isRoot
,
false
,
signingCert
);
ThreadPool
.
QueueUserWorkItem
(
o
=>
manualResetEvent
.
Set
();
{
});
try
manualResetEvent
.
WaitOne
();
{
manualResetEvent
.
Close
();
certificate
=
MakeCertificateInternal
(
sSubjectCN
,
isRoot
,
false
,
signingCert
);
return
rCert
;
}
catch
(
Exception
ex
)
{
exceptionFunc
.
Invoke
(
new
Exception
(
"Failed to create Win certificate"
,
ex
));
}
if
(!
cancellationToken
.
IsCancellationRequested
)
{
manualResetEvent
.
Set
();
}
});
manualResetEvent
.
Wait
(
TimeSpan
.
FromMinutes
(
1
),
cancellationToken
);
}
return
certificate
;
}
}
#endif
//Subject
//Subject
string
fullSubject
=
$"CN=
{
sSubjectCN
}
"
;
string
fullSubject
=
$"CN=
{
sSubjectCN
}
"
;
...
@@ -293,8 +308,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -293,8 +308,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
var
graceTime
=
DateTime
.
Now
.
AddDays
(
GraceDays
);
var
graceTime
=
DateTime
.
Now
.
AddDays
(
GraceDays
);
var
now
=
DateTime
.
Now
;
var
now
=
DateTime
.
Now
;
rCert
=
MakeCertificate
(
isRoot
,
sSubjectCN
,
fullSubject
,
keyLength
,
HashAlgo
,
graceTime
,
now
.
AddDays
(
ValidDays
),
isRoot
?
null
:
signingCert
);
certificate
=
MakeCertificate
(
isRoot
,
sSubjectCN
,
fullSubject
,
keyLength
,
HashAlgo
,
graceTime
,
now
.
AddDays
(
ValidDays
),
isRoot
?
null
:
signingCert
);
return
rCert
;
return
certificate
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment