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
0934a004
Commit
0934a004
authored
Jul 07, 2015
by
justcoding121
Committed by
justcoding121
Jul 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge cleanup
Remove outdated files. Don't install certificate if not using HTTPS
parent
9dc9db4e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
197 additions
and
278 deletions
+197
-278
Certificate.cs
Titanium.Web.Proxy/Helpers/Certificate.cs
+0
-80
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+197
-197
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+0
-1
No files found.
Titanium.Web.Proxy/Helpers/Certificate.cs
deleted
100644 → 0
View file @
9dc9db4e
using
System
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Diagnostics
;
using
System.Threading
;
namespace
Titanium.Web.Proxy.Helpers
{
public
class
CertificateHelper
{
private
static
X509Store
store
;
public
static
X509Certificate2
GetCertificate
(
string
RootCertificateName
,
string
Hostname
)
{
if
(
store
==
null
)
{
store
=
new
X509Store
(
StoreName
.
My
,
StoreLocation
.
CurrentUser
);
store
.
Open
(
OpenFlags
.
ReadOnly
);
}
var
CachedCertificate
=
GetCertifiateFromStore
(
RootCertificateName
,
Hostname
);
if
(
CachedCertificate
==
null
)
CreateClientCertificate
(
RootCertificateName
,
Hostname
);
return
GetCertifiateFromStore
(
RootCertificateName
,
Hostname
);
}
private
static
X509Certificate2
GetCertifiateFromStore
(
string
RootCertificateName
,
string
Hostname
)
{
X509Certificate2Collection
certificateCollection
=
store
.
Certificates
.
Find
(
X509FindType
.
FindBySubjectName
,
Hostname
,
true
);
foreach
(
var
certificate
in
certificateCollection
)
{
if
(
certificate
.
SubjectName
.
Name
.
StartsWith
(
"CN="
+
Hostname
)
&&
certificate
.
IssuerName
.
Name
.
StartsWith
(
"CN="
+
RootCertificateName
))
return
certificate
;
}
return
null
;
}
private
static
void
CreateClientCertificate
(
string
RootCertificateName
,
string
Hostname
)
{
Process
process
=
new
Process
();
// Stop the process from opening a new window
process
.
StartInfo
.
RedirectStandardOutput
=
true
;
process
.
StartInfo
.
UseShellExecute
=
false
;
process
.
StartInfo
.
CreateNoWindow
=
true
;
// Setup executable and parameters
process
.
StartInfo
.
FileName
=
@"makecert.exe"
;
process
.
StartInfo
.
Arguments
=
@" -pe -ss my -n ""CN="
+
Hostname
+
@", O=DO_NOT_TRUST, OU=Created by http://www.fiddler2.com"" -sky exchange -in "
+
RootCertificateName
+
" -is my -eku 1.3.6.1.5.5.7.3.1 -cy end -a sha1 -m 132 -b 06/26/2014"
;
// Go
process
.
Start
();
process
.
WaitForExit
();
}
public
static
void
InstallCertificate
(
string
certificatePath
)
{
X509Certificate2
certificate
=
new
X509Certificate2
(
certificatePath
);
X509Store
store
=
new
X509Store
(
StoreName
.
Root
,
StoreLocation
.
CurrentUser
);
store
.
Open
(
OpenFlags
.
ReadWrite
);
store
.
Add
(
certificate
);
store
.
Close
();
X509Store
store1
=
new
X509Store
(
StoreName
.
My
,
StoreLocation
.
CurrentUser
);
store1
.
Open
(
OpenFlags
.
ReadWrite
);
store1
.
Add
(
certificate
);
store1
.
Close
();
}
}
}
Titanium.Web.Proxy/ProxyServer.cs
View file @
0934a004
using
System
;
using
System.Collections.Generic
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.IO
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Net.Security
;
using
System.Security.Authentication
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Helpers
;
namespace
Titanium.Web.Proxy
{
/// <summary>
/// Proxy Server Main class
/// </summary>
public
partial
class
ProxyServer
{
private
static
readonly
int
BUFFER_SIZE
=
8192
;
private
static
readonly
char
[]
semiSplit
=
new
char
[]
{
';'
};
private
static
readonly
String
[]
colonSpaceSplit
=
new
string
[]
{
": "
};
private
static
readonly
char
[]
spaceSplit
=
new
char
[]
{
' '
};
private
static
readonly
Regex
cookieSplitRegEx
=
new
Regex
(
@",(?! )"
);
private
static
object
certificateAccessLock
=
new
object
();
private
static
List
<
string
>
pinnedCertificateClients
=
new
List
<
string
>();
private
static
ManualResetEvent
tcpClientConnected
=
new
ManualResetEvent
(
false
);
private
static
TcpListener
listener
;
private
static
Thread
listenerThread
;
public
static
event
EventHandler
<
SessionEventArgs
>
BeforeRequest
;
public
static
event
EventHandler
<
SessionEventArgs
>
BeforeResponse
;
public
static
IPAddress
ListeningIPInterface
{
get
;
set
;
}
public
static
string
RootCertificateName
{
get
;
set
;
}
public
static
Int32
ListeningPort
{
get
{
return
((
IPEndPoint
)
listener
.
LocalEndpoint
).
Port
;
}
using
System
;
using
System.Collections.Generic
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.IO
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Net.Security
;
using
System.Security.Authentication
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Helpers
;
namespace
Titanium.Web.Proxy
{
/// <summary>
/// Proxy Server Main class
/// </summary>
public
partial
class
ProxyServer
{
private
static
readonly
int
BUFFER_SIZE
=
8192
;
private
static
readonly
char
[]
semiSplit
=
new
char
[]
{
';'
};
private
static
readonly
String
[]
colonSpaceSplit
=
new
string
[]
{
": "
};
private
static
readonly
char
[]
spaceSplit
=
new
char
[]
{
' '
};
private
static
readonly
Regex
cookieSplitRegEx
=
new
Regex
(
@",(?! )"
);
private
static
object
certificateAccessLock
=
new
object
();
private
static
List
<
string
>
pinnedCertificateClients
=
new
List
<
string
>();
private
static
ManualResetEvent
tcpClientConnected
=
new
ManualResetEvent
(
false
);
private
static
TcpListener
listener
;
private
static
Thread
listenerThread
;
public
static
event
EventHandler
<
SessionEventArgs
>
BeforeRequest
;
public
static
event
EventHandler
<
SessionEventArgs
>
BeforeResponse
;
public
static
IPAddress
ListeningIPInterface
{
get
;
set
;
}
public
static
string
RootCertificateName
{
get
;
set
;
}
public
static
Int32
ListeningPort
{
get
{
return
((
IPEndPoint
)
listener
.
LocalEndpoint
).
Port
;
}
}
public
static
CertificateManager
CertManager
{
get
;
set
;
}
...
...
@@ -60,146 +60,146 @@ namespace Titanium.Web.Proxy
static
ProxyServer
()
{
CertManager
=
new
CertificateManager
(
"Titanium"
,
"Titanium Root Certificate Authority"
);
}
public
ProxyServer
()
{
System
.
Net
.
ServicePointManager
.
Expect100Continue
=
false
;
System
.
Net
.
WebRequest
.
DefaultWebProxy
=
null
;
System
.
Net
.
ServicePointManager
.
DefaultConnectionLimit
=
10
;
ServicePointManager
.
DnsRefreshTimeout
=
3
*
60
*
1000
;
//3 minutes
ServicePointManager
.
MaxServicePointIdleTime
=
3
*
60
*
1000
;
ServicePointManager
.
ServerCertificateValidationCallback
=
delegate
(
object
s
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
{
if
(
sslPolicyErrors
==
SslPolicyErrors
.
None
)
return
true
;
else
return
false
;
};
NetFrameworkHelper
.
URLPeriodFix
();
}
private
static
bool
ShouldListen
{
get
;
set
;
}
public
static
bool
Start
()
{
listener
=
new
TcpListener
(
IPAddress
.
Any
,
0
);
listener
.
Start
();
listenerThread
=
new
Thread
(
new
ParameterizedThreadStart
(
Listen
));
listenerThread
.
IsBackground
=
true
;
ShouldListen
=
true
;
listenerThread
.
Start
(
listener
);
if
(
SetAsSystemProxy
)
{
SystemProxyHelper
.
EnableProxyHTTP
(
"localhost"
,
ListeningPort
);
FireFoxHelper
.
AddFirefox
();
RootCertificateName
=
RootCertificateName
==
null
?
"DO_NOT_TRUST_FiddlerRoot"
:
RootCertificateName
;
bool
certTrusted
=
CertManager
.
CreateTrustedRootCertificate
();
if
(!
certTrusted
)
{
// The user didn't want to install the self-signed certificate to the root store.
}
//CertificateHelper.InstallCertificate(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), string.Concat(RootCertificateName, ".cer")));
if
(
EnableSSL
)
{
SystemProxyHelper
.
EnableProxyHTTPS
(
"localhost"
,
ListeningPort
);
}
}
return
true
;
}
public
static
void
Stop
()
{
if
(
SetAsSystemProxy
)
{
SystemProxyHelper
.
DisableAllProxy
();
FireFoxHelper
.
RemoveFirefox
();
}
ShouldListen
=
false
;
listener
.
Stop
();
listenerThread
.
Interrupt
();
}
private
static
void
Listen
(
Object
obj
)
{
TcpListener
listener
=
(
TcpListener
)
obj
;
try
{
while
(
ShouldListen
)
{
// Set the event to nonsignaled state.
tcpClientConnected
.
Reset
();
listener
.
BeginAcceptTcpClient
(
new
AsyncCallback
(
AcceptTcpClientCallback
),
listener
);
// Wait until a connection is made and processed before
// continuing.
tcpClientConnected
.
WaitOne
();
}
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
SocketException
ex
)
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
public
static
void
AcceptTcpClientCallback
(
IAsyncResult
ar
)
{
try
{
// Get the listener that handles the client request.
TcpListener
listener
=
(
TcpListener
)
ar
.
AsyncState
;
TcpClient
client
=
null
;
// End the operation and display the received data on
// the console.
client
=
listener
.
EndAcceptTcpClient
(
ar
);
Task
.
Factory
.
StartNew
(()
=>
ProcessClient
(
client
));
// Signal the calling thread to continue.
tcpClientConnected
.
Set
();
}
catch
(
ObjectDisposedException
)
{
}
}
private
static
void
ProcessClient
(
Object
param
)
{
try
{
TcpClient
client
=
param
as
TcpClient
;
HandleClientRequest
(
client
);
client
.
Close
();
}
catch
(
Exception
ex
)
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
public
static
bool
EnableSSL
{
get
;
set
;
}
public
static
bool
SetAsSystemProxy
{
get
;
set
;
}
}
"Titanium Root Certificate Authority"
);
}
public
ProxyServer
()
{
System
.
Net
.
ServicePointManager
.
Expect100Continue
=
false
;
System
.
Net
.
WebRequest
.
DefaultWebProxy
=
null
;
System
.
Net
.
ServicePointManager
.
DefaultConnectionLimit
=
10
;
ServicePointManager
.
DnsRefreshTimeout
=
3
*
60
*
1000
;
//3 minutes
ServicePointManager
.
MaxServicePointIdleTime
=
3
*
60
*
1000
;
ServicePointManager
.
ServerCertificateValidationCallback
=
delegate
(
object
s
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
{
if
(
sslPolicyErrors
==
SslPolicyErrors
.
None
)
return
true
;
else
return
false
;
};
NetFrameworkHelper
.
URLPeriodFix
();
}
private
static
bool
ShouldListen
{
get
;
set
;
}
public
static
bool
Start
()
{
listener
=
new
TcpListener
(
IPAddress
.
Any
,
0
);
listener
.
Start
();
listenerThread
=
new
Thread
(
new
ParameterizedThreadStart
(
Listen
));
listenerThread
.
IsBackground
=
true
;
ShouldListen
=
true
;
listenerThread
.
Start
(
listener
);
if
(
SetAsSystemProxy
)
{
SystemProxyHelper
.
EnableProxyHTTP
(
"localhost"
,
ListeningPort
);
FireFoxHelper
.
AddFirefox
();
if
(
EnableSSL
)
{
RootCertificateName
=
RootCertificateName
==
null
?
"DO_NOT_TRUST_FiddlerRoot"
:
RootCertificateName
;
bool
certTrusted
=
CertManager
.
CreateTrustedRootCertificate
();
if
(!
certTrusted
)
{
// The user didn't want to install the self-signed certificate to the root store.
}
SystemProxyHelper
.
EnableProxyHTTPS
(
"localhost"
,
ListeningPort
);
}
}
return
true
;
}
public
static
void
Stop
()
{
if
(
SetAsSystemProxy
)
{
SystemProxyHelper
.
DisableAllProxy
();
FireFoxHelper
.
RemoveFirefox
();
}
ShouldListen
=
false
;
listener
.
Stop
();
listenerThread
.
Interrupt
();
}
private
static
void
Listen
(
Object
obj
)
{
TcpListener
listener
=
(
TcpListener
)
obj
;
try
{
while
(
ShouldListen
)
{
// Set the event to nonsignaled state.
tcpClientConnected
.
Reset
();
listener
.
BeginAcceptTcpClient
(
new
AsyncCallback
(
AcceptTcpClientCallback
),
listener
);
// Wait until a connection is made and processed before
// continuing.
tcpClientConnected
.
WaitOne
();
}
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
SocketException
ex
)
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
public
static
void
AcceptTcpClientCallback
(
IAsyncResult
ar
)
{
try
{
// Get the listener that handles the client request.
TcpListener
listener
=
(
TcpListener
)
ar
.
AsyncState
;
TcpClient
client
=
null
;
// End the operation and display the received data on
// the console.
client
=
listener
.
EndAcceptTcpClient
(
ar
);
Task
.
Factory
.
StartNew
(()
=>
ProcessClient
(
client
));
// Signal the calling thread to continue.
tcpClientConnected
.
Set
();
}
catch
(
ObjectDisposedException
)
{
}
}
private
static
void
ProcessClient
(
Object
param
)
{
try
{
TcpClient
client
=
param
as
TcpClient
;
HandleClientRequest
(
client
);
client
.
Close
();
}
catch
(
Exception
ex
)
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
public
static
bool
EnableSSL
{
get
;
set
;
}
public
static
bool
SetAsSystemProxy
{
get
;
set
;
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
0934a004
...
...
@@ -81,7 +81,6 @@
<Compile
Include=
"Helpers\SystemProxy.cs"
/>
<Compile
Include=
"RequestHandler.cs"
/>
<Compile
Include=
"ResponseHandler.cs"
/>
<Compile
Include=
"Helpers\Certificate.cs"
/>
<Compile
Include=
"Helpers\CustomBinaryReader.cs"
/>
<Compile
Include=
"Helpers\NetFramework.cs"
/>
<Compile
Include=
"Helpers\Compression.cs"
/>
...
...
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