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
126eed5e
Commit
126eed5e
authored
Jun 17, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using "var" for non builtin types everywhere, specify type for builtin types everywhere
parent
c706c9fa
Hide whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
169 additions
and
168 deletions
+169
-168
ConsoleHelper.cs
...itanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
+1
-1
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+2
-2
SslTests.cs
Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
+1
-1
CertificateManagerTests.cs
...s/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
+1
-1
WinAuthTests.cs
Tests/Titanium.Web.Proxy.UnitTests/WinAuthTests.cs
+3
-3
Titanium.Web.Proxy.sln.DotSettings
Titanium.Web.Proxy.sln.DotSettings
+2
-0
CertificateHandler.cs
Titanium.Web.Proxy/CertificateHandler.cs
+1
-1
FuncExtensions.cs
Titanium.Web.Proxy/Extensions/FuncExtensions.cs
+4
-4
StreamExtensions.cs
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+5
-5
TcpExtensions.cs
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
+1
-1
CustomBinaryReader.cs
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
+2
-2
Firefox.cs
Titanium.Web.Proxy/Helpers/Firefox.cs
+3
-3
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+2
-2
Network.cs
Titanium.Web.Proxy/Helpers/Network.cs
+3
-3
ProxyInfo.cs
Titanium.Web.Proxy/Helpers/ProxyInfo.cs
+3
-3
SystemProxy.cs
Titanium.Web.Proxy/Helpers/SystemProxy.cs
+2
-2
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+11
-11
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+4
-4
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+12
-12
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+8
-8
WinCertificateMaker.cs
...nium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
+6
-6
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+7
-7
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+1
-1
TcpTable.cs
Titanium.Web.Proxy/Network/Tcp/TcpTable.cs
+3
-5
Common.cs
Titanium.Web.Proxy/Network/WinAuth/Security/Common.cs
+10
-10
LittleEndian.cs
Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs
+26
-26
Message.cs
Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
+4
-4
State.cs
Titanium.Web.Proxy/Network/WinAuth/Security/State.cs
+3
-3
WinAuthEndPoint.cs
...ium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
+12
-11
WinAuthHandler.cs
Titanium.Web.Proxy/Network/WinAuth/WinAuthHandler.cs
+2
-2
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+4
-4
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+1
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+8
-8
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+6
-6
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+5
-5
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
View file @
126eed5e
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers
internal
static
bool
DisableQuickEditMode
()
internal
static
bool
DisableQuickEditMode
()
{
{
IntPt
r
consoleHandle
=
GetStdHandle
(
STD_INPUT_HANDLE
);
va
r
consoleHandle
=
GetStdHandle
(
STD_INPUT_HANDLE
);
// get current console mode
// get current console mode
uint
consoleMode
;
uint
consoleMode
;
...
...
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
126eed5e
...
@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
if
(
e
.
WebSession
.
Request
.
HasBody
)
if
(
e
.
WebSession
.
Request
.
HasBody
)
{
{
//Get/Set request body bytes
//Get/Set request body bytes
byte
[]
bodyBytes
=
await
e
.
GetRequestBody
();
var
bodyBytes
=
await
e
.
GetRequestBody
();
await
e
.
SetRequestBody
(
bodyBytes
);
await
e
.
SetRequestBody
(
bodyBytes
);
//Get/Set request body as string
//Get/Set request body as string
...
@@ -180,7 +180,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -180,7 +180,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
if
(
e
.
WebSession
.
Response
.
ContentType
!=
null
&&
e
.
WebSession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
if
(
e
.
WebSession
.
Response
.
ContentType
!=
null
&&
e
.
WebSession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
{
{
byte
[]
bodyBytes
=
await
e
.
GetResponseBody
();
var
bodyBytes
=
await
e
.
GetResponseBody
();
await
e
.
SetResponseBody
(
bodyBytes
);
await
e
.
SetResponseBody
(
bodyBytes
);
string
body
=
await
e
.
GetResponseBodyAsString
();
string
body
=
await
e
.
GetResponseBodyAsString
();
...
...
Tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
View file @
126eed5e
...
@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
...
@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
{
{
//expand this to stress test to find
//expand this to stress test to find
//why in long run proxy becomes unresponsive as per issue #184
//why in long run proxy becomes unresponsive as per issue #184
var
testUrl
=
"https://google.com"
;
string
testUrl
=
"https://google.com"
;
int
proxyPort
=
8086
;
int
proxyPort
=
8086
;
var
proxy
=
new
ProxyTestController
();
var
proxy
=
new
ProxyTestController
();
proxy
.
StartProxy
(
proxyPort
);
proxy
.
StartProxy
(
proxyPort
);
...
...
Tests/Titanium.Web.Proxy.UnitTests/CertificateManagerTests.cs
View file @
126eed5e
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.UnitTests
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.UnitTests
for
(
int
i
=
0
;
i
<
1000
;
i
++)
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
{
foreach
(
var
host
in
hostNames
)
foreach
(
string
host
in
hostNames
)
{
{
tasks
.
Add
(
Task
.
Run
(
async
()
=>
tasks
.
Add
(
Task
.
Run
(
async
()
=>
{
{
...
...
Tests/Titanium.Web.Proxy.UnitTests/WinAuthTests.cs
View file @
126eed5e
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System
;
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Titanium.Web.Proxy.Network.WinAuth
;
using
Titanium.Web.Proxy.Network.WinAuth
;
namespace
Titanium.Web.Proxy.UnitTests
namespace
Titanium.Web.Proxy.UnitTests
...
@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.UnitTests
...
@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.UnitTests
[
TestMethod
]
[
TestMethod
]
public
void
Test_Acquire_Client_Token
()
public
void
Test_Acquire_Client_Token
()
{
{
var
token
=
WinAuthHandler
.
GetInitialAuthToken
(
"mylocalserver.com"
,
"NTLM"
,
Guid
.
NewGuid
());
string
token
=
WinAuthHandler
.
GetInitialAuthToken
(
"mylocalserver.com"
,
"NTLM"
,
Guid
.
NewGuid
());
Assert
.
IsTrue
(
token
.
Length
>
1
);
Assert
.
IsTrue
(
token
.
Length
>
1
);
}
}
}
}
...
...
Titanium.Web.Proxy.sln.DotSettings
View file @
126eed5e
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">160</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">160</s:Int64>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVar</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DN/@EntryIndexedValue">DN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DN/@EntryIndexedValue">DN</s:String>
...
...
Titanium.Web.Proxy/CertificateHandler.cs
View file @
126eed5e
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy
if
(
acceptableIssuers
!=
null
&&
acceptableIssuers
.
Length
>
0
&&
localCertificates
!=
null
&&
localCertificates
.
Count
>
0
)
if
(
acceptableIssuers
!=
null
&&
acceptableIssuers
.
Length
>
0
&&
localCertificates
!=
null
&&
localCertificates
.
Count
>
0
)
{
{
// Use the first certificate that is from an acceptable issuer.
// Use the first certificate that is from an acceptable issuer.
foreach
(
X509Certificate
certificate
in
localCertificates
)
foreach
(
var
certificate
in
localCertificates
)
{
{
string
issuer
=
certificate
.
Issuer
;
string
issuer
=
certificate
.
Issuer
;
if
(
Array
.
IndexOf
(
acceptableIssuers
,
issuer
)
!=
-
1
)
if
(
Array
.
IndexOf
(
acceptableIssuers
,
issuer
)
!=
-
1
)
...
...
Titanium.Web.Proxy/Extensions/FuncExtensions.cs
View file @
126eed5e
...
@@ -7,8 +7,8 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -7,8 +7,8 @@ namespace Titanium.Web.Proxy.Extensions
{
{
public
static
void
InvokeParallel
<
T
>(
this
Func
<
object
,
T
,
Task
>
callback
,
object
sender
,
T
args
)
public
static
void
InvokeParallel
<
T
>(
this
Func
<
object
,
T
,
Task
>
callback
,
object
sender
,
T
args
)
{
{
Delegate
[]
invocationList
=
callback
.
GetInvocationList
();
var
invocationList
=
callback
.
GetInvocationList
();
Task
[]
handlerTasks
=
new
Task
[
invocationList
.
Length
];
var
handlerTasks
=
new
Task
[
invocationList
.
Length
];
for
(
int
i
=
0
;
i
<
invocationList
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
invocationList
.
Length
;
i
++)
{
{
...
@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.Extensions
public
static
async
Task
InvokeParallelAsync
<
T
>(
this
Func
<
object
,
T
,
Task
>
callback
,
object
sender
,
T
args
)
public
static
async
Task
InvokeParallelAsync
<
T
>(
this
Func
<
object
,
T
,
Task
>
callback
,
object
sender
,
T
args
)
{
{
Delegate
[]
invocationList
=
callback
.
GetInvocationList
();
var
invocationList
=
callback
.
GetInvocationList
();
Task
[]
handlerTasks
=
new
Task
[
invocationList
.
Length
];
var
handlerTasks
=
new
Task
[
invocationList
.
Length
];
for
(
int
i
=
0
;
i
<
invocationList
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
invocationList
.
Length
;
i
++)
{
{
...
...
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
126eed5e
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <returns></returns>
/// <returns></returns>
internal
static
async
Task
CopyBytesToStream
(
this
CustomBinaryReader
streamReader
,
Stream
stream
,
long
totalBytesToRead
)
internal
static
async
Task
CopyBytesToStream
(
this
CustomBinaryReader
streamReader
,
Stream
stream
,
long
totalBytesToRead
)
{
{
byte
[]
buffer
=
streamReader
.
Buffer
;
var
buffer
=
streamReader
.
Buffer
;
long
remainingBytes
=
totalBytesToRead
;
long
remainingBytes
=
totalBytesToRead
;
while
(
remainingBytes
>
0
)
while
(
remainingBytes
>
0
)
...
@@ -72,8 +72,8 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -72,8 +72,8 @@ namespace Titanium.Web.Proxy.Extensions
{
{
while
(
true
)
while
(
true
)
{
{
var
chuchkHead
=
await
clientStreamReader
.
ReadLineAsync
();
string
chuchkHead
=
await
clientStreamReader
.
ReadLineAsync
();
var
chunkSize
=
int
.
Parse
(
chuchkHead
,
NumberStyles
.
HexNumber
);
int
chunkSize
=
int
.
Parse
(
chuchkHead
,
NumberStyles
.
HexNumber
);
if
(
chunkSize
!=
0
)
if
(
chunkSize
!=
0
)
{
{
...
@@ -148,8 +148,8 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -148,8 +148,8 @@ namespace Titanium.Web.Proxy.Extensions
{
{
while
(
true
)
while
(
true
)
{
{
var
chunkHead
=
await
inStreamReader
.
ReadLineAsync
();
string
chunkHead
=
await
inStreamReader
.
ReadLineAsync
();
var
chunkSize
=
int
.
Parse
(
chunkHead
,
NumberStyles
.
HexNumber
);
int
chunkSize
=
int
.
Parse
(
chunkHead
,
NumberStyles
.
HexNumber
);
if
(
chunkSize
!=
0
)
if
(
chunkSize
!=
0
)
{
{
...
...
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
View file @
126eed5e
...
@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Extensions
internal
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.
// This is how you can determine whether a socket is still connected.
var
blockingState
=
client
.
Blocking
;
bool
blockingState
=
client
.
Blocking
;
try
try
{
{
...
...
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
126eed5e
...
@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
/// <returns></returns>
internal
async
Task
<
string
>
ReadLineAsync
()
internal
async
Task
<
string
>
ReadLineAsync
()
{
{
var
lastChar
=
default
(
byte
);
byte
lastChar
=
default
(
byte
);
int
bufferDataLength
=
0
;
int
bufferDataLength
=
0
;
...
@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
while
(
stream
.
DataAvailable
||
await
stream
.
FillBufferAsync
())
while
(
stream
.
DataAvailable
||
await
stream
.
FillBufferAsync
())
{
{
var
newChar
=
stream
.
ReadByteFromBuffer
();
byte
newChar
=
stream
.
ReadByteFromBuffer
();
buffer
[
bufferDataLength
]
=
newChar
;
buffer
[
bufferDataLength
]
=
newChar
;
//if new line
//if new line
...
...
Titanium.Web.Proxy/Helpers/Firefox.cs
View file @
126eed5e
...
@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy.Helpers
var
myProfileDirectory
=
var
myProfileDirectory
=
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
"\\Mozilla\\Firefox\\Profiles\\"
)
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
"\\Mozilla\\Firefox\\Profiles\\"
)
.
GetDirectories
(
"*.default"
);
.
GetDirectories
(
"*.default"
);
var
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
string
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
if
(!
File
.
Exists
(
myFfPrefFile
))
if
(!
File
.
Exists
(
myFfPrefFile
))
{
{
return
;
return
;
...
@@ -26,12 +26,12 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -26,12 +26,12 @@ namespace Titanium.Web.Proxy.Helpers
// We have a pref file so let''s make sure it has the proxy setting
// We have a pref file so let''s make sure it has the proxy setting
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
var
myPrefContents
=
myReader
.
ReadToEnd
();
string
myPrefContents
=
myReader
.
ReadToEnd
();
myReader
.
Close
();
myReader
.
Close
();
for
(
int
i
=
0
;
i
<=
4
;
i
++)
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
{
var
searchStr
=
$"user_pref(\"network.proxy.type\",
{
i
}
);"
;
string
searchStr
=
$"user_pref(\"network.proxy.type\",
{
i
}
);"
;
if
(
myPrefContents
.
Contains
(
searchStr
))
if
(
myPrefContents
.
Contains
(
searchStr
))
{
{
...
...
Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
126eed5e
...
@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Helpers
//extract the encoding by finding the charset
//extract the encoding by finding the charset
var
parameters
=
contentType
.
Split
(
ProxyConstants
.
SemiColonSplit
);
var
parameters
=
contentType
.
Split
(
ProxyConstants
.
SemiColonSplit
);
foreach
(
var
parameter
in
parameters
)
foreach
(
string
parameter
in
parameters
)
{
{
var
encodingSplit
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
var
encodingSplit
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
if
(
encodingSplit
.
Length
==
2
&&
encodingSplit
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
if
(
encodingSplit
.
Length
==
2
&&
encodingSplit
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
...
@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
if
(
hostname
.
Split
(
ProxyConstants
.
DotSplit
).
Length
>
2
)
if
(
hostname
.
Split
(
ProxyConstants
.
DotSplit
).
Length
>
2
)
{
{
int
idx
=
hostname
.
IndexOf
(
ProxyConstants
.
DotSplit
);
int
idx
=
hostname
.
IndexOf
(
ProxyConstants
.
DotSplit
);
var
rootDomain
=
hostname
.
Substring
(
idx
+
1
);
string
rootDomain
=
hostname
.
Substring
(
idx
+
1
);
return
"*."
+
rootDomain
;
return
"*."
+
rootDomain
;
}
}
...
...
Titanium.Web.Proxy/Helpers/Network.cs
View file @
126eed5e
...
@@ -15,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -15,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
internal
static
int
GetProcessIdFromPort
(
int
port
,
bool
ipV6Enabled
)
internal
static
int
GetProcessIdFromPort
(
int
port
,
bool
ipV6Enabled
)
{
{
var
processId
=
FindProcessIdFromLocalPort
(
port
,
IpVersion
.
Ipv4
);
int
processId
=
FindProcessIdFromLocalPort
(
port
,
IpVersion
.
Ipv4
);
if
(
processId
>
0
&&
!
ipV6Enabled
)
if
(
processId
>
0
&&
!
ipV6Enabled
)
{
{
...
@@ -43,10 +43,10 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -43,10 +43,10 @@ namespace Titanium.Web.Proxy.Helpers
{
{
bool
isLocalhost
=
false
;
bool
isLocalhost
=
false
;
IPHostEntry
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
var
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
if
(
hostName
==
localhost
.
HostName
)
if
(
hostName
==
localhost
.
HostName
)
{
{
IPHostEntry
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
}
}
...
...
Titanium.Web.Proxy/Helpers/ProxyInfo.cs
View file @
126eed5e
...
@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Helpers
{
{
var
overrides
=
proxyOverride
.
Split
(
';'
);
var
overrides
=
proxyOverride
.
Split
(
';'
);
var
overrides2
=
new
List
<
string
>();
var
overrides2
=
new
List
<
string
>();
foreach
(
var
overrideHost
in
overrides
)
foreach
(
string
overrideHost
in
overrides
)
{
{
if
(
overrideHost
==
"<-loopback>"
)
if
(
overrideHost
==
"<-loopback>"
)
{
{
...
@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers
private
static
string
BypassStringEscape
(
string
rawString
)
private
static
string
BypassStringEscape
(
string
rawString
)
{
{
Match
match
=
var
match
=
new
Regex
(
"^(?<scheme>.*://)?(?<host>[^:]*)(?<port>:[0-9]{1,5})?$"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
CultureInvariant
).
Match
(
rawString
);
new
Regex
(
"^(?<scheme>.*://)?(?<host>[^:]*)(?<port>:[0-9]{1,5})?$"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
CultureInvariant
).
Match
(
rawString
);
string
empty1
;
string
empty1
;
string
rawString1
;
string
rawString1
;
...
@@ -174,7 +174,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -174,7 +174,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
/// <returns></returns>
private
static
HttpSystemProxyValue
ParseProxyValue
(
string
value
)
private
static
HttpSystemProxyValue
ParseProxyValue
(
string
value
)
{
{
var
tmp
=
Regex
.
Replace
(
value
,
@"\s+"
,
" "
).
Trim
();
string
tmp
=
Regex
.
Replace
(
value
,
@"\s+"
,
" "
).
Trim
();
int
equalsIndex
=
tmp
.
IndexOf
(
"="
,
StringComparison
.
InvariantCulture
);
int
equalsIndex
=
tmp
.
IndexOf
(
"="
,
StringComparison
.
InvariantCulture
);
if
(
equalsIndex
>=
0
)
if
(
equalsIndex
>=
0
)
...
...
Titanium.Web.Proxy/Helpers/SystemProxy.cs
View file @
126eed5e
...
@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy.Helpers
SaveOriginalProxyConfiguration
(
reg
);
SaveOriginalProxyConfiguration
(
reg
);
PrepareRegistry
(
reg
);
PrepareRegistry
(
reg
);
var
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
string
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
var
existingSystemProxyValues
=
ProxyInfo
.
GetSystemProxyValues
(
exisitingContent
);
var
existingSystemProxyValues
=
ProxyInfo
.
GetSystemProxyValues
(
exisitingContent
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
if
((
protocolType
&
ProxyProtocolType
.
Http
)
!=
0
)
if
((
protocolType
&
ProxyProtocolType
.
Http
)
!=
0
)
...
@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Helpers
if
(
reg
.
GetValue
(
regProxyServer
)
!=
null
)
if
(
reg
.
GetValue
(
regProxyServer
)
!=
null
)
{
{
var
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
string
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
var
existingSystemProxyValues
=
ProxyInfo
.
GetSystemProxyValues
(
exisitingContent
);
var
existingSystemProxyValues
=
ProxyInfo
.
GetSystemProxyValues
(
exisitingContent
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
126eed5e
...
@@ -83,12 +83,12 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -83,12 +83,12 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns>Collection of <see cref="TcpRow"/>.</returns>
/// <returns>Collection of <see cref="TcpRow"/>.</returns>
internal
static
TcpTable
GetExtendedTcpTable
(
IpVersion
ipVersion
)
internal
static
TcpTable
GetExtendedTcpTable
(
IpVersion
ipVersion
)
{
{
List
<
TcpRow
>
tcpRows
=
new
List
<
TcpRow
>();
var
tcpRows
=
new
List
<
TcpRow
>();
IntPt
r
tcpTable
=
IntPtr
.
Zero
;
va
r
tcpTable
=
IntPtr
.
Zero
;
int
tcpTableLength
=
0
;
int
tcpTableLength
=
0
;
var
ipVersionValue
=
ipVersion
==
IpVersion
.
Ipv4
?
NativeMethods
.
AfInet
:
NativeMethods
.
AfInet6
;
int
ipVersionValue
=
ipVersion
==
IpVersion
.
Ipv4
?
NativeMethods
.
AfInet
:
NativeMethods
.
AfInet6
;
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
false
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
!=
0
)
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
false
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
!=
0
)
{
{
...
@@ -97,9 +97,9 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -97,9 +97,9 @@ namespace Titanium.Web.Proxy.Helpers
tcpTable
=
Marshal
.
AllocHGlobal
(
tcpTableLength
);
tcpTable
=
Marshal
.
AllocHGlobal
(
tcpTableLength
);
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
true
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
==
0
)
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
true
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
==
0
)
{
{
NativeMethods
.
TcpTable
table
=
(
NativeMethods
.
TcpTable
)
Marshal
.
PtrToStructure
(
tcpTable
,
typeof
(
NativeMethods
.
TcpTable
));
var
table
=
(
NativeMethods
.
TcpTable
)
Marshal
.
PtrToStructure
(
tcpTable
,
typeof
(
NativeMethods
.
TcpTable
));
IntPt
r
rowPtr
=
(
IntPtr
)((
long
)
tcpTable
+
Marshal
.
SizeOf
(
table
.
length
));
va
r
rowPtr
=
(
IntPtr
)((
long
)
tcpTable
+
Marshal
.
SizeOf
(
table
.
length
));
for
(
int
i
=
0
;
i
<
table
.
length
;
++
i
)
for
(
int
i
=
0
;
i
<
table
.
length
;
++
i
)
{
{
...
@@ -126,10 +126,10 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -126,10 +126,10 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns><see cref="TcpRow"/>.</returns>
/// <returns><see cref="TcpRow"/>.</returns>
internal
static
TcpRow
GetTcpRowByLocalPort
(
IpVersion
ipVersion
,
int
localPort
)
internal
static
TcpRow
GetTcpRowByLocalPort
(
IpVersion
ipVersion
,
int
localPort
)
{
{
IntPt
r
tcpTable
=
IntPtr
.
Zero
;
va
r
tcpTable
=
IntPtr
.
Zero
;
int
tcpTableLength
=
0
;
int
tcpTableLength
=
0
;
var
ipVersionValue
=
ipVersion
==
IpVersion
.
Ipv4
?
NativeMethods
.
AfInet
:
NativeMethods
.
AfInet6
;
int
ipVersionValue
=
ipVersion
==
IpVersion
.
Ipv4
?
NativeMethods
.
AfInet
:
NativeMethods
.
AfInet6
;
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
false
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
!=
0
)
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
false
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
!=
0
)
{
{
...
@@ -138,9 +138,9 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -138,9 +138,9 @@ namespace Titanium.Web.Proxy.Helpers
tcpTable
=
Marshal
.
AllocHGlobal
(
tcpTableLength
);
tcpTable
=
Marshal
.
AllocHGlobal
(
tcpTableLength
);
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
true
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
==
0
)
if
(
NativeMethods
.
GetExtendedTcpTable
(
tcpTable
,
ref
tcpTableLength
,
true
,
ipVersionValue
,
(
int
)
NativeMethods
.
TcpTableType
.
OwnerPidAll
,
0
)
==
0
)
{
{
NativeMethods
.
TcpTable
table
=
(
NativeMethods
.
TcpTable
)
Marshal
.
PtrToStructure
(
tcpTable
,
typeof
(
NativeMethods
.
TcpTable
));
var
table
=
(
NativeMethods
.
TcpTable
)
Marshal
.
PtrToStructure
(
tcpTable
,
typeof
(
NativeMethods
.
TcpTable
));
IntPt
r
rowPtr
=
(
IntPtr
)((
long
)
tcpTable
+
Marshal
.
SizeOf
(
table
.
length
));
va
r
rowPtr
=
(
IntPtr
)((
long
)
tcpTable
+
Marshal
.
SizeOf
(
table
.
length
));
for
(
int
i
=
0
;
i
<
table
.
length
;
++
i
)
for
(
int
i
=
0
;
i
<
table
.
length
;
++
i
)
{
{
...
@@ -199,7 +199,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -199,7 +199,7 @@ namespace Titanium.Web.Proxy.Helpers
if
(
requestHeaders
!=
null
)
if
(
requestHeaders
!=
null
)
{
{
foreach
(
var
header
in
requestHeaders
.
Select
(
t
=>
t
.
Value
.
ToString
()))
foreach
(
string
header
in
requestHeaders
.
Select
(
t
=>
t
.
Value
.
ToString
()))
{
{
sb
.
Append
(
header
);
sb
.
Append
(
header
);
sb
.
Append
(
ProxyConstants
.
NewLine
);
sb
.
Append
(
ProxyConstants
.
NewLine
);
...
@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy.Helpers
try
try
{
{
Stream
tunnelStream
=
tcpConnection
.
Stream
;
var
tunnelStream
=
tcpConnection
.
Stream
;
//Now async relay all server=>client & client=>server data
//Now async relay all server=>client & client=>server data
var
sendRelay
=
clientStream
.
CopyToAsync
(
sb
?.
ToString
()
??
string
.
Empty
,
tunnelStream
);
var
sendRelay
=
clientStream
.
CopyToAsync
(
sb
?.
ToString
()
??
string
.
Empty
,
tunnelStream
);
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
126eed5e
...
@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Http
requestLines
.
AppendLine
();
requestLines
.
AppendLine
();
var
request
=
requestLines
.
ToString
();
string
request
=
requestLines
.
ToString
();
var
requestBytes
=
Encoding
.
ASCII
.
GetBytes
(
request
);
var
requestBytes
=
Encoding
.
ASCII
.
GetBytes
(
request
);
await
stream
.
WriteAsync
(
requestBytes
,
0
,
requestBytes
.
Length
);
await
stream
.
WriteAsync
(
requestBytes
,
0
,
requestBytes
.
Length
);
...
@@ -129,8 +129,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -129,8 +129,8 @@ namespace Titanium.Web.Proxy.Http
if
(
Request
.
ExpectContinue
)
if
(
Request
.
ExpectContinue
)
{
{
var
httpResult
=
(
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()).
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
var
httpResult
=
(
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()).
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
var
responseStatusCode
=
httpResult
[
1
].
Trim
();
string
responseStatusCode
=
httpResult
[
1
].
Trim
();
var
responseStatusDescription
=
httpResult
[
2
].
Trim
();
string
responseStatusDescription
=
httpResult
[
2
].
Trim
();
//find if server is willing for expect continue
//find if server is willing for expect continue
if
(
responseStatusCode
.
Equals
(
"100"
)
if
(
responseStatusCode
.
Equals
(
"100"
)
...
@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.Http
httpResult
=
(
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()).
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
httpResult
=
(
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()).
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
}
}
var
httpVersion
=
httpResult
[
0
];
string
httpVersion
=
httpResult
[
0
];
var
version
=
HttpHeader
.
Version11
;
var
version
=
HttpHeader
.
Version11
;
if
(
string
.
Equals
(
httpVersion
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
if
(
string
.
Equals
(
httpVersion
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
126eed5e
using
System
;
using
System
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
...
@@ -41,12 +41,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -41,12 +41,12 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"host"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"host"
);
return
hasHeader
?
RequestHeaders
[
"host"
].
Value
:
null
;
return
hasHeader
?
RequestHeaders
[
"host"
].
Value
:
null
;
}
}
set
set
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"host"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"host"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
RequestHeaders
[
"host"
].
Value
=
value
;
RequestHeaders
[
"host"
].
Value
=
value
;
...
@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-encoding"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-encoding"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-length"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-length"
);
if
(
hasHeader
==
false
)
if
(
hasHeader
==
false
)
{
{
...
@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Http
}
}
set
set
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-length"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-length"
);
var
header
=
RequestHeaders
[
"content-length"
];
var
header
=
RequestHeaders
[
"content-length"
];
...
@@ -137,7 +137,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -137,7 +137,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-type"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-type"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Http
}
}
set
set
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-type"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"content-type"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"transfer-encoding"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"transfer-encoding"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -183,7 +183,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -183,7 +183,7 @@ namespace Titanium.Web.Proxy.Http
}
}
set
set
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"transfer-encoding"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"transfer-encoding"
);
if
(
value
)
if
(
value
)
{
{
...
@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"expect"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"expect"
);
if
(!
hasHeader
)
if
(!
hasHeader
)
return
false
;
return
false
;
...
@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
RequestHeaders
.
ContainsKey
(
"upgrade"
);
bool
hasHeader
=
RequestHeaders
.
ContainsKey
(
"upgrade"
);
if
(
hasHeader
==
false
)
if
(
hasHeader
==
false
)
{
{
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
126eed5e
using
System
;
using
System
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
...
@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-encoding"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-encoding"
);
if
(!
hasHeader
)
if
(!
hasHeader
)
return
null
;
return
null
;
...
@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"connection"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"connection"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-type"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-type"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-length"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-length"
);
if
(
hasHeader
==
false
)
if
(
hasHeader
==
false
)
{
{
...
@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Http
}
}
set
set
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-length"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"content-length"
);
if
(
value
>=
0
)
if
(
value
>=
0
)
{
{
...
@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"transfer-encoding"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"transfer-encoding"
);
if
(
hasHeader
)
if
(
hasHeader
)
{
{
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Http
}
}
set
set
{
{
var
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"transfer-encoding"
);
bool
hasHeader
=
ResponseHeaders
.
ContainsKey
(
"transfer-encoding"
);
if
(
value
)
if
(
value
)
{
{
...
...
Titanium.Web.Proxy/Network/Certificate/WinCertificateMaker.cs
View file @
126eed5e
...
@@ -249,7 +249,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -249,7 +249,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
try
try
{
{
var
empty
=
(
string
)
typeX509Enrollment
.
InvokeMember
(
"CreatePFX"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
string
empty
=
(
string
)
typeX509Enrollment
.
InvokeMember
(
"CreatePFX"
,
BindingFlags
.
InvokeMethod
,
null
,
x509Enrollment
,
typeValue
);
return
new
X509Certificate2
(
Convert
.
FromBase64String
(
empty
),
string
.
Empty
,
X509KeyStorageFlags
.
Exportable
);
return
new
X509Certificate2
(
Convert
.
FromBase64String
(
empty
),
string
.
Empty
,
X509KeyStorageFlags
.
Exportable
);
}
}
catch
(
Exception
)
catch
(
Exception
)
...
@@ -279,15 +279,15 @@ namespace Titanium.Web.Proxy.Network.Certificate
...
@@ -279,15 +279,15 @@ namespace Titanium.Web.Proxy.Network.Certificate
}
}
//Subject
//Subject
var
fullSubject
=
$"CN=
{
sSubjectCN
}
"
;
string
fullSubject
=
$"CN=
{
sSubjectCN
}
"
;
//Sig Algo
//Sig Algo
var
HashAlgo
=
"SHA256"
;
string
HashAlgo
=
"SHA256"
;
//Grace Days
//Grace Days
var
GraceDays
=
-
366
;
int
GraceDays
=
-
366
;
//ValiDays
//ValiDays
var
ValidDays
=
1825
;
int
ValidDays
=
1825
;
//KeyLength
//KeyLength
var
keyLength
=
2048
;
int
keyLength
=
2048
;
var
graceTime
=
DateTime
.
Now
.
AddDays
(
GraceDays
);
var
graceTime
=
DateTime
.
Now
.
AddDays
(
GraceDays
);
var
now
=
DateTime
.
Now
;
var
now
=
DateTime
.
Now
;
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
126eed5e
...
@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy.Network
private
string
GetRootCertificatePath
()
private
string
GetRootCertificatePath
()
{
{
var
assemblyLocation
=
Assembly
.
GetExecutingAssembly
().
Location
;
string
assemblyLocation
=
Assembly
.
GetExecutingAssembly
().
Location
;
// dynamically loaded assemblies returns string.Empty location
// dynamically loaded assemblies returns string.Empty location
if
(
assemblyLocation
==
string
.
Empty
)
if
(
assemblyLocation
==
string
.
Empty
)
...
@@ -140,16 +140,16 @@ namespace Titanium.Web.Proxy.Network
...
@@ -140,16 +140,16 @@ namespace Titanium.Web.Proxy.Network
assemblyLocation
=
Assembly
.
GetEntryAssembly
().
Location
;
assemblyLocation
=
Assembly
.
GetEntryAssembly
().
Location
;
}
}
var
path
=
Path
.
GetDirectoryName
(
assemblyLocation
);
string
path
=
Path
.
GetDirectoryName
(
assemblyLocation
);
if
(
null
==
path
)
if
(
null
==
path
)
throw
new
NullReferenceException
();
throw
new
NullReferenceException
();
var
fileName
=
Path
.
Combine
(
path
,
"rootCert.pfx"
);
string
fileName
=
Path
.
Combine
(
path
,
"rootCert.pfx"
);
return
fileName
;
return
fileName
;
}
}
private
X509Certificate2
LoadRootCertificate
()
private
X509Certificate2
LoadRootCertificate
()
{
{
var
fileName
=
GetRootCertificatePath
();
string
fileName
=
GetRootCertificatePath
();
if
(!
File
.
Exists
(
fileName
))
if
(!
File
.
Exists
(
fileName
))
return
null
;
return
null
;
try
try
...
@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network
{
{
try
try
{
{
var
fileName
=
GetRootCertificatePath
();
string
fileName
=
GetRootCertificatePath
();
File
.
WriteAllBytes
(
fileName
,
RootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
File
.
WriteAllBytes
(
fileName
,
RootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network
return
false
;
return
false
;
}
}
var
fileName
=
Path
.
GetTempFileName
();
string
fileName
=
Path
.
GetTempFileName
();
File
.
WriteAllBytes
(
fileName
,
RootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
File
.
WriteAllBytes
(
fileName
,
RootCertificate
.
Export
(
X509ContentType
.
Pkcs12
));
var
info
=
new
ProcessStartInfo
var
info
=
new
ProcessStartInfo
...
@@ -340,7 +340,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -340,7 +340,7 @@ namespace Titanium.Web.Proxy.Network
private
X509Certificate2Collection
FindCertificates
(
StoreName
storeName
,
StoreLocation
storeLocation
,
string
findValue
)
private
X509Certificate2Collection
FindCertificates
(
StoreName
storeName
,
StoreLocation
storeLocation
,
string
findValue
)
{
{
X509Store
x509Store
=
new
X509Store
(
storeName
,
storeLocation
);
var
x509Store
=
new
X509Store
(
storeName
,
storeLocation
);
try
try
{
{
x509Store
.
Open
(
OpenFlags
.
OpenExistingOnly
);
x509Store
.
Open
(
OpenFlags
.
OpenExistingOnly
);
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
126eed5e
...
@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
))
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
))
{
{
var
result
=
await
reader
.
ReadLineAsync
();
string
result
=
await
reader
.
ReadLineAsync
();
if
(!
new
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ContainsIgnoreCase
(
s
)))
if
(!
new
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ContainsIgnoreCase
(
s
)))
{
{
...
...
Titanium.Web.Proxy/Network/Tcp/TcpTable.cs
View file @
126eed5e
...
@@ -11,21 +11,19 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -11,21 +11,19 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </seealso>
/// </seealso>
internal
class
TcpTable
:
IEnumerable
<
TcpRow
>
internal
class
TcpTable
:
IEnumerable
<
TcpRow
>
{
{
private
readonly
IEnumerable
<
TcpRow
>
tcpRows
;
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="TcpTable"/> class.
/// Initializes a new instance of the <see cref="TcpTable"/> class.
/// </summary>
/// </summary>
/// <param name="tcpRows">TcpRow collection to initialize with.</param>
/// <param name="tcpRows">TcpRow collection to initialize with.</param>
internal
TcpTable
(
IEnumerable
<
TcpRow
>
tcpRows
)
internal
TcpTable
(
IEnumerable
<
TcpRow
>
tcpRows
)
{
{
this
.
t
cpRows
=
tcpRows
;
this
.
T
cpRows
=
tcpRows
;
}
}
/// <summary>
/// <summary>
/// Gets the TCP rows.
/// Gets the TCP rows.
/// </summary>
/// </summary>
internal
IEnumerable
<
TcpRow
>
TcpRows
=>
tcpRows
;
internal
IEnumerable
<
TcpRow
>
TcpRows
{
get
;
}
/// <summary>
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// Returns an enumerator that iterates through the collection.
...
@@ -33,7 +31,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -33,7 +31,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
/// <returns>An enumerator that can be used to iterate through the collection.</returns>
public
IEnumerator
<
TcpRow
>
GetEnumerator
()
public
IEnumerator
<
TcpRow
>
GetEnumerator
()
{
{
return
t
cpRows
.
GetEnumerator
();
return
T
cpRows
.
GetEnumerator
();
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/Common.cs
View file @
126eed5e
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
using
System
;
{
using
System.Runtime.InteropServices
;
using
System
;
using
System.Runtime.InteropServices
;
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
{
internal
class
Common
internal
class
Common
{
{
#
region
Private
constants
#
region
Private
constants
...
@@ -177,7 +177,7 @@
...
@@ -177,7 +177,7 @@
{
{
ulVersion
=
(
int
)
SecurityBufferType
.
SECBUFFER_VERSION
;
ulVersion
=
(
int
)
SecurityBufferType
.
SECBUFFER_VERSION
;
cBuffers
=
1
;
cBuffers
=
1
;
SecurityBuffe
r
thisSecBuffer
=
new
SecurityBuffer
(
bufferSize
);
va
r
thisSecBuffer
=
new
SecurityBuffer
(
bufferSize
);
pBuffers
=
Marshal
.
AllocHGlobal
(
Marshal
.
SizeOf
(
thisSecBuffer
));
pBuffers
=
Marshal
.
AllocHGlobal
(
Marshal
.
SizeOf
(
thisSecBuffer
));
Marshal
.
StructureToPtr
(
thisSecBuffer
,
pBuffers
,
false
);
Marshal
.
StructureToPtr
(
thisSecBuffer
,
pBuffers
,
false
);
}
}
...
@@ -186,7 +186,7 @@
...
@@ -186,7 +186,7 @@
{
{
ulVersion
=
(
int
)
SecurityBufferType
.
SECBUFFER_VERSION
;
ulVersion
=
(
int
)
SecurityBufferType
.
SECBUFFER_VERSION
;
cBuffers
=
1
;
cBuffers
=
1
;
SecurityBuffe
r
thisSecBuffer
=
new
SecurityBuffer
(
secBufferBytes
);
va
r
thisSecBuffer
=
new
SecurityBuffer
(
secBufferBytes
);
pBuffers
=
Marshal
.
AllocHGlobal
(
Marshal
.
SizeOf
(
thisSecBuffer
));
pBuffers
=
Marshal
.
AllocHGlobal
(
Marshal
.
SizeOf
(
thisSecBuffer
));
Marshal
.
StructureToPtr
(
thisSecBuffer
,
pBuffers
,
false
);
Marshal
.
StructureToPtr
(
thisSecBuffer
,
pBuffers
,
false
);
}
}
...
@@ -197,7 +197,7 @@
...
@@ -197,7 +197,7 @@
{
{
if
(
cBuffers
==
1
)
if
(
cBuffers
==
1
)
{
{
SecurityBuffe
r
thisSecBuffer
=
(
SecurityBuffer
)
Marshal
.
PtrToStructure
(
pBuffers
,
typeof
(
SecurityBuffer
));
va
r
thisSecBuffer
=
(
SecurityBuffer
)
Marshal
.
PtrToStructure
(
pBuffers
,
typeof
(
SecurityBuffer
));
thisSecBuffer
.
Dispose
();
thisSecBuffer
.
Dispose
();
}
}
else
else
...
@@ -211,7 +211,7 @@
...
@@ -211,7 +211,7 @@
//What we need to do here is to grab a hold of the pvBuffer allocate by the individual
//What we need to do here is to grab a hold of the pvBuffer allocate by the individual
//SecBuffer and release it...
//SecBuffer and release it...
int
currentOffset
=
index
*
Marshal
.
SizeOf
(
typeof
(
Buffer
));
int
currentOffset
=
index
*
Marshal
.
SizeOf
(
typeof
(
Buffer
));
IntPt
r
secBufferpvBuffer
=
Marshal
.
ReadIntPtr
(
pBuffers
,
currentOffset
+
Marshal
.
SizeOf
(
typeof
(
int
))
+
Marshal
.
SizeOf
(
typeof
(
int
)));
va
r
secBufferpvBuffer
=
Marshal
.
ReadIntPtr
(
pBuffers
,
currentOffset
+
Marshal
.
SizeOf
(
typeof
(
int
))
+
Marshal
.
SizeOf
(
typeof
(
int
)));
Marshal
.
FreeHGlobal
(
secBufferpvBuffer
);
Marshal
.
FreeHGlobal
(
secBufferpvBuffer
);
}
}
}
}
...
@@ -232,7 +232,7 @@
...
@@ -232,7 +232,7 @@
if
(
cBuffers
==
1
)
if
(
cBuffers
==
1
)
{
{
SecurityBuffe
r
thisSecBuffer
=
(
SecurityBuffer
)
Marshal
.
PtrToStructure
(
pBuffers
,
typeof
(
SecurityBuffer
));
va
r
thisSecBuffer
=
(
SecurityBuffer
)
Marshal
.
PtrToStructure
(
pBuffers
,
typeof
(
SecurityBuffer
));
if
(
thisSecBuffer
.
cbBuffer
>
0
)
if
(
thisSecBuffer
.
cbBuffer
>
0
)
{
{
...
@@ -267,7 +267,7 @@
...
@@ -267,7 +267,7 @@
//byte array...
//byte array...
int
currentOffset
=
index
*
Marshal
.
SizeOf
(
typeof
(
Buffer
));
int
currentOffset
=
index
*
Marshal
.
SizeOf
(
typeof
(
Buffer
));
int
bytesToCopy
=
Marshal
.
ReadInt32
(
pBuffers
,
currentOffset
);
int
bytesToCopy
=
Marshal
.
ReadInt32
(
pBuffers
,
currentOffset
);
IntPt
r
secBufferpvBuffer
=
Marshal
.
ReadIntPtr
(
pBuffers
,
currentOffset
+
Marshal
.
SizeOf
(
typeof
(
int
))
+
Marshal
.
SizeOf
(
typeof
(
int
)));
va
r
secBufferpvBuffer
=
Marshal
.
ReadIntPtr
(
pBuffers
,
currentOffset
+
Marshal
.
SizeOf
(
typeof
(
int
))
+
Marshal
.
SizeOf
(
typeof
(
int
)));
Marshal
.
Copy
(
secBufferpvBuffer
,
buffer
,
bufferIndex
,
bytesToCopy
);
Marshal
.
Copy
(
secBufferpvBuffer
,
buffer
,
bufferIndex
,
bytesToCopy
);
bufferIndex
+=
bytesToCopy
;
bufferIndex
+=
bytesToCopy
;
}
}
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs
View file @
126eed5e
...
@@ -27,17 +27,17 @@
...
@@ -27,17 +27,17 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
using
System
;
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
{
{
using
System
;
internal
sealed
class
LittleEndian
internal
sealed
class
LittleEndian
{
{
private
LittleEndian
()
private
LittleEndian
()
{
{
}
}
unsafe
private
static
byte
[]
GetUShortBytes
(
byte
*
bytes
)
private
static
unsafe
byte
[]
GetUShortBytes
(
byte
*
bytes
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -47,7 +47,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
new
[]
{
bytes
[
1
],
bytes
[
0
]
};
return
new
[]
{
bytes
[
1
],
bytes
[
0
]
};
}
}
unsafe
private
static
byte
[]
GetUIntBytes
(
byte
*
bytes
)
private
static
unsafe
byte
[]
GetUIntBytes
(
byte
*
bytes
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -57,7 +57,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -57,7 +57,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
new
[]
{
bytes
[
3
],
bytes
[
2
],
bytes
[
1
],
bytes
[
0
]
};
return
new
[]
{
bytes
[
3
],
bytes
[
2
],
bytes
[
1
],
bytes
[
0
]
};
}
}
unsafe
private
static
byte
[]
GetULongBytes
(
byte
*
bytes
)
private
static
unsafe
byte
[]
GetULongBytes
(
byte
*
bytes
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -72,52 +72,52 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -72,52 +72,52 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
new
[]
{
value
?
(
byte
)
1
:
(
byte
)
0
};
return
new
[]
{
value
?
(
byte
)
1
:
(
byte
)
0
};
}
}
unsafe
internal
static
byte
[]
GetBytes
(
char
value
)
internal
static
unsafe
byte
[]
GetBytes
(
char
value
)
{
{
return
GetUShortBytes
((
byte
*)&
value
);
return
GetUShortBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
short
value
)
internal
static
unsafe
byte
[]
GetBytes
(
short
value
)
{
{
return
GetUShortBytes
((
byte
*)&
value
);
return
GetUShortBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
int
value
)
internal
static
unsafe
byte
[]
GetBytes
(
int
value
)
{
{
return
GetUIntBytes
((
byte
*)&
value
);
return
GetUIntBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
long
value
)
internal
static
unsafe
byte
[]
GetBytes
(
long
value
)
{
{
return
GetULongBytes
((
byte
*)&
value
);
return
GetULongBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
ushort
value
)
internal
static
unsafe
byte
[]
GetBytes
(
ushort
value
)
{
{
return
GetUShortBytes
((
byte
*)&
value
);
return
GetUShortBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
uint
value
)
internal
static
unsafe
byte
[]
GetBytes
(
uint
value
)
{
{
return
GetUIntBytes
((
byte
*)&
value
);
return
GetUIntBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
ulong
value
)
internal
static
unsafe
byte
[]
GetBytes
(
ulong
value
)
{
{
return
GetULongBytes
((
byte
*)&
value
);
return
GetULongBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
float
value
)
internal
static
unsafe
byte
[]
GetBytes
(
float
value
)
{
{
return
GetUIntBytes
((
byte
*)&
value
);
return
GetUIntBytes
((
byte
*)&
value
);
}
}
unsafe
internal
static
byte
[]
GetBytes
(
double
value
)
internal
static
unsafe
byte
[]
GetBytes
(
double
value
)
{
{
return
GetULongBytes
((
byte
*)&
value
);
return
GetULongBytes
((
byte
*)&
value
);
}
}
unsafe
private
static
void
UShortFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
private
static
unsafe
void
UShortFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -131,7 +131,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -131,7 +131,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
}
}
}
}
unsafe
private
static
void
UIntFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
private
static
unsafe
void
UIntFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
}
}
}
}
unsafe
private
static
void
ULongFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
private
static
unsafe
void
ULongFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
{
if
(
BitConverter
.
IsLittleEndian
)
if
(
BitConverter
.
IsLittleEndian
)
{
{
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
value
[
startIndex
]
!=
0
;
return
value
[
startIndex
]
!=
0
;
}
}
unsafe
internal
static
char
ToChar
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
char
ToChar
(
byte
[]
value
,
int
startIndex
)
{
{
char
ret
;
char
ret
;
...
@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -177,7 +177,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
short
ToInt16
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
short
ToInt16
(
byte
[]
value
,
int
startIndex
)
{
{
short
ret
;
short
ret
;
...
@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
int
ToInt32
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
int
ToInt32
(
byte
[]
value
,
int
startIndex
)
{
{
int
ret
;
int
ret
;
...
@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -195,7 +195,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
long
ToInt64
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
long
ToInt64
(
byte
[]
value
,
int
startIndex
)
{
{
long
ret
;
long
ret
;
...
@@ -204,7 +204,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -204,7 +204,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
ushort
ToUInt16
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
ushort
ToUInt16
(
byte
[]
value
,
int
startIndex
)
{
{
ushort
ret
;
ushort
ret
;
...
@@ -213,7 +213,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -213,7 +213,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
uint
ToUInt32
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
uint
ToUInt32
(
byte
[]
value
,
int
startIndex
)
{
{
uint
ret
;
uint
ret
;
...
@@ -222,7 +222,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -222,7 +222,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
ulong
ToUInt64
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
ulong
ToUInt64
(
byte
[]
value
,
int
startIndex
)
{
{
ulong
ret
;
ulong
ret
;
...
@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -231,7 +231,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
float
ToSingle
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
float
ToSingle
(
byte
[]
value
,
int
startIndex
)
{
{
float
ret
;
float
ret
;
...
@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
return
ret
;
return
ret
;
}
}
unsafe
internal
static
double
ToDouble
(
byte
[]
value
,
int
startIndex
)
internal
static
unsafe
double
ToDouble
(
byte
[]
value
,
int
startIndex
)
{
{
double
ret
;
double
ret
;
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
View file @
126eed5e
...
@@ -33,14 +33,14 @@
...
@@ -33,14 +33,14 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
using
System
;
using
System.Text
;
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
{
{
using
System
;
using
System.Text
;
internal
class
Message
internal
class
Message
{
{
static
private
readonly
byte
[]
header
=
{
0x4e
,
0x54
,
0x4c
,
0x4d
,
0x53
,
0x53
,
0x50
,
0x00
};
private
static
readonly
byte
[]
header
=
{
0x4e
,
0x54
,
0x4c
,
0x4d
,
0x53
,
0x53
,
0x50
,
0x00
};
internal
Message
(
byte
[]
message
)
internal
Message
(
byte
[]
message
)
{
{
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/State.cs
View file @
126eed5e
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
using
System
;
{
using
System
;
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
{
/// <summary>
/// <summary>
/// Status of authenticated session
/// Status of authenticated session
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
View file @
126eed5e
// http://pinvoke.net/default.aspx/secur32/InitializeSecurityContext.html
// http://pinvoke.net/default.aspx/secur32/InitializeSecurityContext.html
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
System.Security.Principal
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
namespace
Titanium.Web.Proxy.Network.WinAuth.Security
{
{
using
System
;
using
System.Linq
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Security.Principal
;
using
static
Common
;
using
static
Common
;
using
System.Threading.Tasks
;
internal
class
WinAuthEndPoint
internal
class
WinAuthEndPoint
{
{
...
@@ -31,9 +32,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -31,9 +32,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
byte
[]
token
;
byte
[]
token
;
//null for initial call
//null for initial call
SecurityBufferDesciption
serverToken
=
new
SecurityBufferDesciption
();
var
serverToken
=
new
SecurityBufferDesciption
();
SecurityBufferDesciption
clientToken
=
new
SecurityBufferDesciption
(
MaximumTokenSize
);
var
clientToken
=
new
SecurityBufferDesciption
(
MaximumTokenSize
);
try
try
{
{
...
@@ -102,9 +103,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -102,9 +103,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
byte
[]
token
;
byte
[]
token
;
//user server challenge
//user server challenge
SecurityBufferDesciption
serverToken
=
new
SecurityBufferDesciption
(
serverChallenge
);
var
serverToken
=
new
SecurityBufferDesciption
(
serverChallenge
);
SecurityBufferDesciption
clientToken
=
new
SecurityBufferDesciption
(
MaximumTokenSize
);
var
clientToken
=
new
SecurityBufferDesciption
(
MaximumTokenSize
);
try
try
{
{
...
...
Titanium.Web.Proxy/Network/WinAuth/WinAuthHandler.cs
View file @
126eed5e
using
Titanium.Web.Proxy.Network.WinAuth.Security
;
using
System
;
using
System
;
using
Titanium.Web.Proxy.Network.WinAuth.Security
;
namespace
Titanium.Web.Proxy.Network.WinAuth
namespace
Titanium.Web.Proxy.Network.WinAuth
{
{
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
126eed5e
...
@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy
...
@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy
var
header
=
httpHeaders
.
FirstOrDefault
(
t
=>
t
.
Name
==
"Proxy-Authorization"
);
var
header
=
httpHeaders
.
FirstOrDefault
(
t
=>
t
.
Name
==
"Proxy-Authorization"
);
if
(
header
==
null
)
if
(
header
==
null
)
throw
new
NullReferenceException
();
throw
new
NullReferenceException
();
var
headerValue
=
header
.
Value
.
Trim
();
string
headerValue
=
header
.
Value
.
Trim
();
if
(!
headerValue
.
StartsWith
(
"basic"
,
StringComparison
.
CurrentCultureIgnoreCase
))
if
(!
headerValue
.
StartsWith
(
"basic"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
//Return not authorized
//Return not authorized
...
@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy
...
@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy
headerValue
=
headerValue
.
Substring
(
5
).
Trim
();
headerValue
=
headerValue
.
Substring
(
5
).
Trim
();
var
decoded
=
Encoding
.
UTF8
.
GetString
(
Convert
.
FromBase64String
(
headerValue
));
string
decoded
=
Encoding
.
UTF8
.
GetString
(
Convert
.
FromBase64String
(
headerValue
));
if
(
decoded
.
Contains
(
":"
)
==
false
)
if
(
decoded
.
Contains
(
":"
)
==
false
)
{
{
//Return not authorized
//Return not authorized
...
@@ -50,8 +50,8 @@ namespace Titanium.Web.Proxy
...
@@ -50,8 +50,8 @@ namespace Titanium.Web.Proxy
return
false
;
return
false
;
}
}
var
username
=
decoded
.
Substring
(
0
,
decoded
.
IndexOf
(
':'
));
string
username
=
decoded
.
Substring
(
0
,
decoded
.
IndexOf
(
':'
));
var
password
=
decoded
.
Substring
(
decoded
.
IndexOf
(
':'
)
+
1
);
string
password
=
decoded
.
Substring
(
decoded
.
IndexOf
(
':'
)
+
1
);
return
await
AuthenticateUserFunc
(
username
,
password
);
return
await
AuthenticateUserFunc
(
username
,
password
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
126eed5e
...
@@ -562,7 +562,7 @@ namespace Titanium.Web.Proxy
...
@@ -562,7 +562,7 @@ namespace Titanium.Web.Proxy
if
(!
RunTime
.
IsRunningOnMono
)
if
(!
RunTime
.
IsRunningOnMono
)
{
{
var
setAsSystemProxy
=
ProxyEndPoints
.
OfType
<
ExplicitProxyEndPoint
>().
Any
(
x
=>
x
.
IsSystemHttpProxy
||
x
.
IsSystemHttpsProxy
);
bool
setAsSystemProxy
=
ProxyEndPoints
.
OfType
<
ExplicitProxyEndPoint
>().
Any
(
x
=>
x
.
IsSystemHttpProxy
||
x
.
IsSystemHttpsProxy
);
if
(
setAsSystemProxy
)
if
(
setAsSystemProxy
)
{
{
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
126eed5e
...
@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
...
@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns>
/// <returns></returns>
private
async
Task
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
private
async
Task
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
{
var
disposed
=
false
;
bool
disposed
=
false
;
var
clientStream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
BufferSize
);
var
clientStream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
BufferSize
);
...
@@ -48,7 +48,7 @@ namespace Titanium.Web.Proxy
...
@@ -48,7 +48,7 @@ namespace Titanium.Web.Proxy
try
try
{
{
//read the first line HTTP command
//read the first line HTTP command
var
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
if
(
string
.
IsNullOrEmpty
(
httpCmd
))
if
(
string
.
IsNullOrEmpty
(
httpCmd
))
{
{
...
@@ -59,7 +59,7 @@ namespace Titanium.Web.Proxy
...
@@ -59,7 +59,7 @@ namespace Titanium.Web.Proxy
var
httpCmdSplit
=
httpCmd
.
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
var
httpCmdSplit
=
httpCmd
.
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
//Find the request Verb
//Find the request Verb
var
httpVerb
=
httpCmdSplit
[
0
].
ToUpper
();
string
httpVerb
=
httpCmdSplit
[
0
].
ToUpper
();
httpRemoteUri
=
httpVerb
==
"CONNECT"
?
new
Uri
(
"http://"
+
httpCmdSplit
[
1
])
:
new
Uri
(
httpCmdSplit
[
1
]);
httpRemoteUri
=
httpVerb
==
"CONNECT"
?
new
Uri
(
"http://"
+
httpCmdSplit
[
1
])
:
new
Uri
(
httpCmdSplit
[
1
]);
...
@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy
...
@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy
var
version
=
HttpHeader
.
Version11
;
var
version
=
HttpHeader
.
Version11
;
if
(
httpCmdSplit
.
Length
==
3
)
if
(
httpCmdSplit
.
Length
==
3
)
{
{
var
httpVersion
=
httpCmdSplit
[
2
].
Trim
();
string
httpVersion
=
httpCmdSplit
[
2
].
Trim
();
if
(
string
.
Equals
(
httpVersion
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
if
(
string
.
Equals
(
httpVersion
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
{
{
...
@@ -117,7 +117,7 @@ namespace Titanium.Web.Proxy
...
@@ -117,7 +117,7 @@ namespace Titanium.Web.Proxy
{
{
sslStream
=
new
SslStream
(
clientStream
);
sslStream
=
new
SslStream
(
clientStream
);
var
certName
=
HttpHelper
.
GetWildCardDomainName
(
httpRemoteUri
.
Host
);
string
certName
=
HttpHelper
.
GetWildCardDomainName
(
httpRemoteUri
.
Host
);
var
certificate
=
endPoint
.
GenericCertificate
??
CertificateManager
.
CreateCertificate
(
certName
,
false
);
var
certificate
=
endPoint
.
GenericCertificate
??
CertificateManager
.
CreateCertificate
(
certName
,
false
);
...
@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy
...
@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy
};
};
//now read the request line
//now read the request line
var
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
//Now create the request
//Now create the request
disposed
=
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
disposed
=
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
...
@@ -287,13 +287,13 @@ namespace Titanium.Web.Proxy
...
@@ -287,13 +287,13 @@ namespace Titanium.Web.Proxy
//break up the line into three components (method, remote URL & Http Version)
//break up the line into three components (method, remote URL & Http Version)
var
httpCmdSplit
=
httpCmd
.
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
var
httpCmdSplit
=
httpCmd
.
Split
(
ProxyConstants
.
SpaceSplit
,
3
);
var
httpMethod
=
httpCmdSplit
[
0
];
string
httpMethod
=
httpCmdSplit
[
0
];
//find the request HTTP version
//find the request HTTP version
var
httpVersion
=
HttpHeader
.
Version11
;
var
httpVersion
=
HttpHeader
.
Version11
;
if
(
httpCmdSplit
.
Length
==
3
)
if
(
httpCmdSplit
.
Length
==
3
)
{
{
var
httpVersionString
=
httpCmdSplit
[
2
].
Trim
();
string
httpVersionString
=
httpCmdSplit
[
2
].
Trim
();
if
(
string
.
Equals
(
httpVersionString
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
if
(
string
.
Equals
(
httpVersionString
,
"HTTP/1.0"
,
StringComparison
.
OrdinalIgnoreCase
))
{
{
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
126eed5e
...
@@ -36,7 +36,7 @@ namespace Titanium.Web.Proxy
...
@@ -36,7 +36,7 @@ namespace Titanium.Web.Proxy
&&
!
RunTime
.
IsRunningOnMono
&&
!
RunTime
.
IsRunningOnMono
&&
args
.
WebSession
.
Response
.
ResponseStatusCode
==
"401"
)
&&
args
.
WebSession
.
Response
.
ResponseStatusCode
==
"401"
)
{
{
var
disposed
=
await
Handle401UnAuthorized
(
args
);
bool
disposed
=
await
Handle401UnAuthorized
(
args
);
if
(
disposed
)
if
(
disposed
)
{
{
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy
{
{
//clear current response
//clear current response
await
args
.
ClearResponse
();
await
args
.
ClearResponse
();
var
disposed
=
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
,
false
);
bool
disposed
=
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
,
false
);
return
disposed
;
return
disposed
;
}
}
...
@@ -82,8 +82,8 @@ namespace Titanium.Web.Proxy
...
@@ -82,8 +82,8 @@ namespace Titanium.Web.Proxy
if
(
args
.
WebSession
.
Response
.
ResponseBodyRead
)
if
(
args
.
WebSession
.
Response
.
ResponseBodyRead
)
{
{
var
isChunked
=
args
.
WebSession
.
Response
.
IsChunked
;
bool
isChunked
=
args
.
WebSession
.
Response
.
IsChunked
;
var
contentEncoding
=
args
.
WebSession
.
Response
.
ContentEncoding
;
string
contentEncoding
=
args
.
WebSession
.
Response
.
ContentEncoding
;
if
(
contentEncoding
!=
null
)
if
(
contentEncoding
!=
null
)
{
{
...
@@ -198,8 +198,8 @@ namespace Titanium.Web.Proxy
...
@@ -198,8 +198,8 @@ namespace Titanium.Web.Proxy
private
void
FixProxyHeaders
(
Dictionary
<
string
,
HttpHeader
>
headers
)
private
void
FixProxyHeaders
(
Dictionary
<
string
,
HttpHeader
>
headers
)
{
{
//If proxy-connection close was returned inform to close the connection
//If proxy-connection close was returned inform to close the connection
var
hasProxyHeader
=
headers
.
ContainsKey
(
"proxy-connection"
);
bool
hasProxyHeader
=
headers
.
ContainsKey
(
"proxy-connection"
);
var
hasConnectionheader
=
headers
.
ContainsKey
(
"connection"
);
bool
hasConnectionheader
=
headers
.
ContainsKey
(
"connection"
);
if
(
hasProxyHeader
)
if
(
hasProxyHeader
)
{
{
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
126eed5e
...
@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy
...
@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy
if
(
authHeader
!=
null
)
if
(
authHeader
!=
null
)
{
{
var
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
Equals
(
x
,
StringComparison
.
OrdinalIgnoreCase
));
string
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
Equals
(
x
,
StringComparison
.
OrdinalIgnoreCase
));
//clear any existing headers to avoid confusing bad servers
//clear any existing headers to avoid confusing bad servers
if
(
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
ContainsKey
(
"Authorization"
))
if
(
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
ContainsKey
(
"Authorization"
))
...
@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy
...
@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy
//initial value will match exactly any of the schemes
//initial value will match exactly any of the schemes
if
(
scheme
!=
null
)
if
(
scheme
!=
null
)
{
{
var
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
args
.
WebSession
.
Request
.
Host
,
scheme
,
args
.
Id
);
string
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
args
.
WebSession
.
Request
.
Host
,
scheme
,
args
.
Id
);
var
auth
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
var
auth
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
...
@@ -118,8 +118,8 @@ namespace Titanium.Web.Proxy
...
@@ -118,8 +118,8 @@ namespace Titanium.Web.Proxy
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
authHeader
.
Value
.
Length
>
x
.
Length
+
1
);
authHeader
.
Value
.
Length
>
x
.
Length
+
1
);
var
serverToken
=
authHeader
.
Value
.
Substring
(
scheme
.
Length
+
1
);
string
serverToken
=
authHeader
.
Value
.
Substring
(
scheme
.
Length
+
1
);
var
clientToken
=
WinAuthHandler
.
GetFinalAuthToken
(
args
.
WebSession
.
Request
.
Host
,
serverToken
,
args
.
Id
);
string
clientToken
=
WinAuthHandler
.
GetFinalAuthToken
(
args
.
WebSession
.
Request
.
Host
,
serverToken
,
args
.
Id
);
//there will be an existing header from initial client request
//there will be an existing header from initial client request
args
.
WebSession
.
Request
.
RequestHeaders
[
"Authorization"
]
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
args
.
WebSession
.
Request
.
RequestHeaders
[
"Authorization"
]
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
...
@@ -140,7 +140,7 @@ namespace Titanium.Web.Proxy
...
@@ -140,7 +140,7 @@ namespace Titanium.Web.Proxy
//request again with updated authorization header
//request again with updated authorization header
//and server cookies
//and server cookies
var
disposed
=
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
,
false
);
bool
disposed
=
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
,
false
);
return
disposed
;
return
disposed
;
}
}
...
...
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