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
e4dfa442
Commit
e4dfa442
authored
Jun 03, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue #13 Fix
Mark items internal; keep only MRU certificates in cache
parent
dfc6d9a6
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
164 additions
and
104 deletions
+164
-104
DecompressionFactory.cs
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
+2
-2
DefaultDecompression.cs
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
+1
-1
DeflateDecompression.cs
Titanium.Web.Proxy/Decompression/DeflateDecompression.cs
+1
-1
GZipDecompression.cs
Titanium.Web.Proxy/Decompression/GZipDecompression.cs
+1
-1
IDecompression.cs
Titanium.Web.Proxy/Decompression/IDecompression.cs
+2
-2
ZlibDecompression.cs
Titanium.Web.Proxy/Decompression/ZlibDecompression.cs
+1
-1
HttpWebRequestExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
+2
-2
HttpWebResponseExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
+2
-2
StreamExtensions.cs
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+2
-2
TcpExtensions.cs
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
+1
-3
CertificateManager.cs
Titanium.Web.Proxy/Helpers/CertificateManager.cs
+103
-56
CustomBinaryReader.cs
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
+7
-9
SystemProxy.cs
Titanium.Web.Proxy/Helpers/SystemProxy.cs
+11
-11
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+2
-2
CustomSslStream.cs
Titanium.Web.Proxy/Network/CustomSslStream.cs
+1
-1
TcpConnectionManager.cs
Titanium.Web.Proxy/Network/TcpConnectionManager.cs
+9
-2
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+13
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-2
Constants.cs
Titanium.Web.Proxy/Shared/Constants.cs
+1
-1
No files found.
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
View file @
e4dfa442
namespace
Titanium.Web.Proxy.Decompression
{
class
DecompressionFactory
internal
class
DecompressionFactory
{
public
IDecompression
Create
(
string
type
)
internal
IDecompression
Create
(
string
type
)
{
switch
(
type
)
{
...
...
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
View file @
e4dfa442
...
...
@@ -2,7 +2,7 @@
namespace
Titanium.Web.Proxy.Decompression
{
class
DefaultDecompression
:
IDecompression
internal
class
DefaultDecompression
:
IDecompression
{
public
Task
<
byte
[
]>
Decompress
(
byte
[]
compressedArray
)
{
...
...
Titanium.Web.Proxy/Decompression/DeflateDecompression.cs
View file @
e4dfa442
...
...
@@ -5,7 +5,7 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Decompression
{
class
DeflateDecompression
:
IDecompression
internal
class
DeflateDecompression
:
IDecompression
{
public
async
Task
<
byte
[
]>
Decompress
(
byte
[]
compressedArray
)
{
...
...
Titanium.Web.Proxy/Decompression/GZipDecompression.cs
View file @
e4dfa442
...
...
@@ -5,7 +5,7 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Decompression
{
class
GZipDecompression
:
IDecompression
internal
class
GZipDecompression
:
IDecompression
{
public
async
Task
<
byte
[
]>
Decompress
(
byte
[]
compressedArray
)
{
...
...
Titanium.Web.Proxy/Decompression/IDecompression.cs
View file @
e4dfa442
...
...
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
namespace
Titanium.Web.Proxy.Decompression
{
interface
IDecompression
inter
nal
inter
face
IDecompression
{
Task
<
byte
[
]>
Decompress
(
byte
[]
compressedArray
);
}
...
...
Titanium.Web.Proxy/Decompression/ZlibDecompression.cs
View file @
e4dfa442
...
...
@@ -5,7 +5,7 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Decompression
{
class
ZlibDecompression
:
IDecompression
internal
class
ZlibDecompression
:
IDecompression
{
public
async
Task
<
byte
[
]>
Decompress
(
byte
[]
compressedArray
)
{
...
...
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
View file @
e4dfa442
...
...
@@ -7,10 +7,10 @@ namespace Titanium.Web.Proxy.Extensions
/// <summary>
/// Extensions on HttpWebSession object
/// </summary>
public
static
class
HttpWebRequestExtensions
internal
static
class
HttpWebRequestExtensions
{
//Get encoding of the HTTP request
public
static
Encoding
GetEncoding
(
this
Request
request
)
internal
static
Encoding
GetEncoding
(
this
Request
request
)
{
try
{
...
...
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
View file @
e4dfa442
...
...
@@ -4,9 +4,9 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Extensions
{
public
static
class
HttpWebResponseExtensions
internal
static
class
HttpWebResponseExtensions
{
public
static
Encoding
GetResponseCharacterEncoding
(
this
Response
response
)
internal
static
Encoding
GetResponseCharacterEncoding
(
this
Response
response
)
{
try
{
...
...
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
e4dfa442
...
...
@@ -8,9 +8,9 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Extensions
{
public
static
class
StreamHelper
internal
static
class
StreamHelper
{
public
static
async
Task
CopyToAsync
(
this
Stream
input
,
string
initialData
,
Stream
output
)
internal
static
async
Task
CopyToAsync
(
this
Stream
input
,
string
initialData
,
Stream
output
)
{
if
(!
string
.
IsNullOrEmpty
(
initialData
))
{
...
...
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
View file @
e4dfa442
using
System.Net.Sockets
;
namespace
Titanium.Web.Proxy.Extensions
{
internal
static
class
TcpExtensions
{
public
static
bool
IsConnected
(
this
Socket
client
)
internal
static
bool
IsConnected
(
this
Socket
client
)
{
// This is how you can determine whether a socket is still connected.
bool
blockingState
=
client
.
Blocking
;
...
...
Titanium.Web.Proxy/Helpers/CertificateManager.cs
View file @
e4dfa442
...
...
@@ -6,24 +6,37 @@ using System.Security.Cryptography.X509Certificates;
using
System.Reflection
;
using
System.Threading.Tasks
;
using
System.Threading
;
using
System.Linq
;
namespace
Titanium.Web.Proxy.Helpers
{
public
class
CertificateManager
:
IDisposable
internal
class
CachedCertificate
{
internal
X509Certificate2
Certificate
{
get
;
set
;
}
internal
DateTime
LastAccess
{
get
;
set
;
}
internal
CachedCertificate
()
{
LastAccess
=
DateTime
.
Now
;
}
}
internal
class
CertificateManager
:
IDisposable
{
private
const
string
CertCreateFormat
=
"-ss {0} -n \"CN={1}, O={2}\" -sky {3} -cy {4} -m 120 -a sha256 -eku 1.3.6.1.5.5.7.3.1 {5}"
;
private
readonly
IDictionary
<
string
,
X509Certificate2
>
_
certificateCache
;
private
readonly
IDictionary
<
string
,
CachedCertificate
>
certificateCache
;
private
static
SemaphoreSlim
semaphoreLock
=
new
SemaphoreSlim
(
1
);
public
string
Issuer
{
get
;
private
set
;
}
public
string
RootCertificateName
{
get
;
private
set
;
}
internal
string
Issuer
{
get
;
private
set
;
}
internal
string
RootCertificateName
{
get
;
private
set
;
}
public
X509Store
MyStore
{
get
;
private
set
;
}
public
X509Store
RootStore
{
get
;
private
set
;
}
internal
X509Store
MyStore
{
get
;
private
set
;
}
internal
X509Store
RootStore
{
get
;
private
set
;
}
public
CertificateManager
(
string
issuer
,
string
rootCertificateName
)
internal
CertificateManager
(
string
issuer
,
string
rootCertificateName
)
{
Issuer
=
issuer
;
RootCertificateName
=
rootCertificateName
;
...
...
@@ -31,17 +44,17 @@ namespace Titanium.Web.Proxy.Helpers
MyStore
=
new
X509Store
(
StoreName
.
My
,
StoreLocation
.
CurrentUser
);
RootStore
=
new
X509Store
(
StoreName
.
Root
,
StoreLocation
.
CurrentUser
);
_certificateCache
=
new
Dictionary
<
string
,
X509Certificate2
>();
certificateCache
=
new
Dictionary
<
string
,
CachedCertificate
>();
}
/// <summary>
/// Attempts to move a self-signed certificate to the root store.
/// </summary>
/// <returns>true if succeeded, else false</returns>
public
async
Task
<
bool
>
CreateTrustedRootCertificate
()
internal
async
Task
<
bool
>
CreateTrustedRootCertificate
()
{
X509Certificate2
rootCertificate
=
await
CreateCertificate
(
RootStore
,
RootCertificateName
);
await
CreateCertificate
(
RootStore
,
RootCertificateName
,
true
);
return
rootCertificate
!=
null
;
}
...
...
@@ -49,12 +62,12 @@ namespace Titanium.Web.Proxy.Helpers
/// Attempts to remove the self-signed certificate from the root store.
/// </summary>
/// <returns>true if succeeded, else false</returns>
public
async
Task
<
bool
>
DestroyTrustedRootCertificate
()
internal
bool
DestroyTrustedRootCertificate
()
{
return
await
DestroyCertificate
(
RootStore
,
RootCertificateNam
e
);
return
DestroyCertificate
(
RootStore
,
RootCertificateName
,
fals
e
);
}
public
X509Certificate2Collection
FindCertificates
(
string
certificateSubject
)
internal
X509Certificate2Collection
FindCertificates
(
string
certificateSubject
)
{
return
FindCertificates
(
MyStore
,
certificateSubject
);
}
...
...
@@ -67,29 +80,36 @@ namespace Titanium.Web.Proxy.Helpers
discoveredCertificates
:
null
;
}
public
async
Task
<
X509Certificate2
>
CreateCertificate
(
string
certificateNam
e
)
internal
async
Task
<
X509Certificate2
>
CreateCertificate
(
string
certificateName
,
bool
isRootCertificat
e
)
{
return
await
CreateCertificate
(
MyStore
,
certificateName
);
return
await
CreateCertificate
(
MyStore
,
certificateName
,
isRootCertificate
);
}
protected
async
virtual
Task
<
X509Certificate2
>
CreateCertificate
(
X509Store
store
,
string
certificateName
)
{
if
(
_certificateCache
.
ContainsKey
(
certificateName
))
return
_certificateCache
[
certificateName
];
protected
async
virtual
Task
<
X509Certificate2
>
CreateCertificate
(
X509Store
store
,
string
certificateName
,
bool
isRootCertificate
)
{
await
semaphoreLock
.
WaitAsync
();
X509Certificate2
certificate
=
null
;
try
{
if
(
certificateCache
.
ContainsKey
(
certificateName
))
{
var
cached
=
certificateCache
[
certificateName
];
cached
.
LastAccess
=
DateTime
.
Now
;
return
cached
.
Certificate
;
}
X509Certificate2
certificate
=
null
;
store
.
Open
(
OpenFlags
.
ReadWrite
);
string
certificateSubject
=
string
.
Format
(
"CN={0}, O={1}"
,
certificateName
,
Issuer
);
var
certificates
=
FindCertificates
(
store
,
certificateSubject
);
X509Certificate2Collection
certificates
;
if
(
isRootCertificate
)
{
certificates
=
FindCertificates
(
store
,
certificateSubject
);
if
(
certificates
!=
null
)
certificate
=
certificates
[
0
];
}
if
(
certificate
==
null
)
{
...
...
@@ -99,13 +119,17 @@ namespace Titanium.Web.Proxy.Helpers
await
CreateCertificate
(
args
);
certificates
=
FindCertificates
(
store
,
certificateSubject
);
return
certificates
!=
null
?
certificates
[
0
]
:
null
;
//remove it from store
if
(!
isRootCertificate
)
DestroyCertificate
(
certificateName
);
if
(
certificates
!=
null
)
certificate
=
certificates
[
0
];
}
store
.
Close
();
if
(
certificate
!=
null
&&
!
_
certificateCache
.
ContainsKey
(
certificateName
))
_certificateCache
.
Add
(
certificateName
,
certificate
);
if
(
certificate
!=
null
&&
!
certificateCache
.
ContainsKey
(
certificateName
))
certificateCache
.
Add
(
certificateName
,
new
CachedCertificate
()
{
Certificate
=
certificate
}
);
return
certificate
;
}
...
...
@@ -113,8 +137,8 @@ namespace Titanium.Web.Proxy.Helpers
{
semaphoreLock
.
Release
();
}
}
protected
virtual
Task
<
int
>
CreateCertificate
(
string
[]
args
)
{
...
...
@@ -153,17 +177,15 @@ namespace Titanium.Web.Proxy.Helpers
}
public
async
Task
<
bool
>
DestroyCertificate
(
string
certificateName
)
internal
bool
DestroyCertificate
(
string
certificateName
)
{
return
await
DestroyCertificate
(
MyStore
,
certificateNam
e
);
return
DestroyCertificate
(
MyStore
,
certificateName
,
fals
e
);
}
protected
virtual
async
Task
<
bool
>
DestroyCertificate
(
X509Store
store
,
string
certificateName
)
{
await
semaphoreLock
.
WaitAsync
();
X509Certificate2Collection
certificates
=
null
;
try
protected
virtual
bool
DestroyCertificate
(
X509Store
store
,
string
certificateName
,
bool
removeFromCache
)
{
X509Certificate2Collection
certificates
=
null
;
store
.
Open
(
OpenFlags
.
ReadWrite
);
string
certificateSubject
=
string
.
Format
(
"CN={0}, O={1}"
,
certificateName
,
Issuer
);
...
...
@@ -175,19 +197,13 @@ namespace Titanium.Web.Proxy.Helpers
}
store
.
Close
();
if
(
certificates
==
null
&&
_
certificateCache
.
ContainsKey
(
certificateName
))
if
(
removeFromCache
&&
certificateCache
.
ContainsKey
(
certificateName
))
{
_
certificateCache
.
Remove
(
certificateName
);
certificateCache
.
Remove
(
certificateName
);
}
return
certificates
==
null
;
}
finally
{
semaphoreLock
.
Release
();
}
}
protected
virtual
string
GetCertificateCreateArgs
(
X509Store
store
,
string
certificateName
)
{
...
...
@@ -203,6 +219,37 @@ namespace Titanium.Web.Proxy.Helpers
return
certCreatArgs
;
}
private
static
bool
clearCertificates
{
get
;
set
;
}
internal
void
StopClearIdleCertificates
()
{
clearCertificates
=
false
;
}
internal
async
void
ClearIdleCertificates
()
{
clearCertificates
=
true
;
while
(
clearCertificates
)
{
await
semaphoreLock
.
WaitAsync
();
try
{
var
cutOff
=
DateTime
.
Now
.
AddSeconds
(-
60
);
var
outdated
=
certificateCache
.
Where
(
x
=>
x
.
Value
.
LastAccess
<
cutOff
)
.
ToList
();
foreach
(
var
cache
in
outdated
)
certificateCache
.
Remove
(
cache
.
Key
);
}
finally
{
semaphoreLock
.
Release
();
}
await
Task
.
Delay
(
1000
*
60
*
3
).
ConfigureAwait
(
false
);
}
}
public
void
Dispose
()
{
if
(
MyStore
!=
null
)
...
...
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
e4dfa442
...
...
@@ -15,18 +15,16 @@ namespace Titanium.Web.Proxy.Helpers
/// using the specified encoding
/// as well as to read bytes as required
/// </summary>
public
class
CustomBinaryReader
:
IDisposable
internal
class
CustomBinaryReader
:
IDisposable
{
private
Stream
stream
;
internal
CustomBinaryReader
(
Stream
stream
)
{
this
.
stream
=
stream
;
}
public
Stream
BaseStream
=>
stream
;
internal
Stream
BaseStream
=>
stream
;
/// <summary>
/// Read a line from the byte stream
...
...
@@ -41,25 +39,25 @@ namespace Titanium.Web.Proxy.Helpers
var
lastChar
=
default
(
char
);
var
buffer
=
new
byte
[
1
];
while
(
await
this
.
stream
.
ReadAsync
(
buffer
,
0
,
1
).
ConfigureAwait
(
false
)
>
0
)
while
(
this
.
stream
.
Read
(
buffer
,
0
,
1
)
>
0
)
{
if
(
lastChar
==
'\r'
&&
buffer
[
0
]
==
'\n'
)
{
return
readBuffer
.
Remove
(
readBuffer
.
Length
-
1
,
1
).
ToString
(
);
return
await
Task
.
FromResult
(
readBuffer
.
Remove
(
readBuffer
.
Length
-
1
,
1
).
ToString
()
);
}
if
(
buffer
[
0
]
==
'\0'
)
{
return
readBuffer
.
ToString
(
);
return
await
Task
.
FromResult
(
readBuffer
.
ToString
()
);
}
readBuffer
.
Append
((
char
)
buffer
[
0
]);
lastChar
=
(
char
)
buffer
[
0
];
}
return
readBuffer
.
ToString
(
);
return
await
Task
.
FromResult
(
readBuffer
.
ToString
()
);
}
catch
(
IOException
)
{
return
readBuffer
.
ToString
(
);
return
await
Task
.
FromResult
(
readBuffer
.
ToString
()
);
}
}
...
...
Titanium.Web.Proxy/Helpers/SystemProxy.cs
View file @
e4dfa442
...
...
@@ -16,9 +16,9 @@ namespace Titanium.Web.Proxy.Helpers
internal
class
HttpSystemProxyValue
{
public
string
HostName
{
get
;
set
;
}
public
int
Port
{
get
;
set
;
}
public
bool
IsHttps
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
internal
int
Port
{
get
;
set
;
}
internal
bool
IsHttps
{
get
;
set
;
}
public
override
string
ToString
()
{
...
...
@@ -29,12 +29,12 @@ namespace Titanium.Web.Proxy.Helpers
}
}
public
static
class
SystemProxyHelper
internal
static
class
SystemProxyHelper
{
public
const
int
InternetOptionSettingsChanged
=
39
;
public
const
int
InternetOptionRefresh
=
37
;
internal
const
int
InternetOptionSettingsChanged
=
39
;
internal
const
int
InternetOptionRefresh
=
37
;
public
static
void
SetHttpProxy
(
string
hostname
,
int
port
)
internal
static
void
SetHttpProxy
(
string
hostname
,
int
port
)
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
...
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy.Helpers
}
public
static
void
RemoveHttpProxy
()
internal
static
void
RemoveHttpProxy
()
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
...
...
@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy.Helpers
Refresh
();
}
public
static
void
SetHttpsProxy
(
string
hostname
,
int
port
)
internal
static
void
SetHttpsProxy
(
string
hostname
,
int
port
)
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
...
...
@@ -116,7 +116,7 @@ namespace Titanium.Web.Proxy.Helpers
Refresh
();
}
public
static
void
RemoveHttpsProxy
()
internal
static
void
RemoveHttpsProxy
()
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
...
...
@@ -146,7 +146,7 @@ namespace Titanium.Web.Proxy.Helpers
Refresh
();
}
public
static
void
DisableAllProxy
()
internal
static
void
DisableAllProxy
()
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
e4dfa442
...
...
@@ -12,9 +12,9 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Helpers
{
public
class
TcpHelper
internal
class
TcpHelper
{
public
async
static
Task
SendRaw
(
Stream
clientStream
,
string
httpCmd
,
List
<
HttpHeader
>
requestHeaders
,
string
hostName
,
internal
async
static
Task
SendRaw
(
Stream
clientStream
,
string
httpCmd
,
List
<
HttpHeader
>
requestHeaders
,
string
hostName
,
int
tunnelPort
,
bool
isHttps
)
{
StringBuilder
sb
=
null
;
...
...
Titanium.Web.Proxy/Network/CustomSslStream.cs
View file @
e4dfa442
...
...
@@ -19,7 +19,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
internal
SessionEventArgs
Session
{
get
;
set
;
}
public
CustomSslStream
(
Stream
innerStream
,
bool
leaveInnerStreamOpen
,
RemoteCertificateValidationCallback
userCertificateValidationCallback
)
internal
CustomSslStream
(
Stream
innerStream
,
bool
leaveInnerStreamOpen
,
RemoteCertificateValidationCallback
userCertificateValidationCallback
)
:
base
(
innerStream
,
leaveInnerStreamOpen
,
userCertificateValidationCallback
)
{
...
...
Titanium.Web.Proxy/Network/TcpConnectionManager.cs
View file @
e4dfa442
...
...
@@ -28,7 +28,6 @@ namespace Titanium.Web.Proxy.Network
internal
DateTime
LastAccess
{
get
;
set
;
}
internal
TcpConnection
()
{
LastAccess
=
DateTime
.
Now
;
...
...
@@ -192,9 +191,17 @@ namespace Titanium.Web.Proxy.Network
finally
{
connectionAccessLock
.
Release
();
}
}
private
static
bool
clearConenctions
{
get
;
set
;
}
internal
static
void
StopClearIdleConnections
()
{
clearConenctions
=
false
;
}
internal
async
static
void
ClearIdleConnections
()
{
while
(
true
)
clearConenctions
=
true
;
while
(
clearConenctions
)
{
await
connectionAccessLock
.
WaitAsync
();
try
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
e4dfa442
...
...
@@ -22,7 +22,6 @@ namespace Titanium.Web.Proxy
static
ProxyServer
()
{
ProxyEndPoints
=
new
List
<
ProxyEndPoint
>();
Initialize
();
}
private
static
CertificateManager
CertManager
{
get
;
set
;
}
...
...
@@ -58,6 +57,13 @@ namespace Titanium.Web.Proxy
public
static
void
Initialize
()
{
TcpConnectionManager
.
ClearIdleConnections
();
CertManager
.
ClearIdleCertificates
();
}
public
static
void
Quit
()
{
TcpConnectionManager
.
StopClearIdleConnections
();
CertManager
.
StopClearIdleCertificates
();
}
public
static
void
AddEndPoint
(
ProxyEndPoint
endPoint
)
...
...
@@ -161,6 +167,8 @@ namespace Titanium.Web.Proxy
Listen
(
endPoint
);
}
Initialize
();
proxyRunning
=
true
;
}
...
...
@@ -186,6 +194,8 @@ namespace Titanium.Web.Proxy
CertManager
.
Dispose
();
Quit
();
proxyRunning
=
false
;
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
e4dfa442
...
...
@@ -74,7 +74,7 @@ namespace Titanium.Web.Proxy
await
WriteConnectResponse
(
clientStreamWriter
,
version
).
ConfigureAwait
(
false
);
var
certificate
=
await
CertManager
.
CreateCertificate
(
httpRemoteUri
.
Host
);
var
certificate
=
await
CertManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
SslStream
sslStream
=
null
;
...
...
@@ -146,7 +146,7 @@ namespace Titanium.Web.Proxy
// certificate = CertManager.CreateCertificate(hostName);
//}
//else
certificate
=
await
CertManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
);
certificate
=
await
CertManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
,
false
);
try
{
...
...
Titanium.Web.Proxy/Shared/Constants.cs
View file @
e4dfa442
...
...
@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.Shared
/// </summary>
internal
class
Constants
{
public
static
readonly
int
BUFFER_SIZE
=
8192
;
internal
static
readonly
int
BUFFER_SIZE
=
8192
;
internal
static
readonly
char
[]
SpaceSplit
=
{
' '
};
internal
static
readonly
char
[]
ColonSplit
=
{
':'
};
...
...
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