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
e2c392f9
Commit
e2c392f9
authored
Jun 17, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format code
parent
711fc5e5
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
263 additions
and
257 deletions
+263
-257
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+2
-3
CustomBufferedStream.cs
Titanium.Web.Proxy/Helpers/CustomBufferedStream.cs
+1
-2
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+0
-1
ProxyInfo.cs
Titanium.Web.Proxy/Helpers/ProxyInfo.cs
+1
-1
RunTime.cs
Titanium.Web.Proxy/Helpers/RunTime.cs
+2
-2
WinHttpHandle.cs
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpHandle.cs
+1
-1
WinHttpWebProxyFinder.cs
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
+3
-3
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+2
-2
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+1
-4
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+3
-4
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+0
-1
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+1
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+4
-4
Common.cs
Titanium.Web.Proxy/Network/WinAuth/Security/Common.cs
+18
-1
LittleEndian.cs
Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs
+178
-169
Message.cs
Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
+31
-40
WinAuthEndPoint.cs
...ium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
+0
-1
WinAuthHandler.cs
Titanium.Web.Proxy/Network/WinAuth/WinAuthHandler.cs
+4
-5
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+5
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-2
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+3
-3
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+1
-4
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
e2c392f9
...
...
@@ -48,7 +48,6 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
Guid
Id
=>
WebSession
.
RequestId
;
/// <summary>
/// Should we send the request again
/// </summary>
...
...
@@ -59,8 +58,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
if
(
WebSession
.
Response
.
ResponseStatusCode
==
null
)
{
throw
new
Exception
(
"Response status code is null. Cannot request again a request "
+
"which was never send to server."
);
throw
new
Exception
(
"Response status code is null. Cannot request again a request "
+
"which was never send to server."
);
}
reRequest
=
value
;
...
...
Titanium.Web.Proxy/Helpers/CustomBufferedStream.cs
View file @
e2c392f9
...
...
@@ -359,7 +359,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected
override
void
Dispose
(
bool
disposing
)
{
if
(!
disposed
)
if
(!
disposed
)
{
disposed
=
true
;
baseStream
.
Dispose
();
...
...
@@ -367,7 +367,6 @@ namespace Titanium.Web.Proxy.Helpers
streamBuffer
=
null
;
readCallback
=
null
;
}
}
/// <summary>
...
...
Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
e2c392f9
...
...
@@ -68,7 +68,6 @@ namespace Titanium.Web.Proxy.Helpers
int
idx
=
hostname
.
IndexOf
(
ProxyConstants
.
DotSplit
);
var
rootDomain
=
hostname
.
Substring
(
idx
+
1
);
return
"*."
+
rootDomain
;
}
//return as it is
...
...
Titanium.Web.Proxy/Helpers/ProxyInfo.cs
View file @
e2c392f9
...
...
@@ -36,7 +36,7 @@ namespace Titanium.Web.Proxy.Helpers
if
(
proxyServer
!=
null
)
{
Proxies
=
GetSystemProxyValues
(
proxyServer
).
ToDictionary
(
x
=>
x
.
ProtocolType
);
Proxies
=
GetSystemProxyValues
(
proxyServer
).
ToDictionary
(
x
=>
x
.
ProtocolType
);
}
if
(
proxyOverride
!=
null
)
...
...
Titanium.Web.Proxy/Helpers/RunTime.cs
View file @
e2c392f9
...
...
@@ -12,8 +12,8 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// <returns></returns>
private
static
readonly
Lazy
<
bool
>
isRunningOnMono
=
new
Lazy
<
bool
>(()=>
Type
.
GetType
(
"Mono.Runtime"
)
!=
null
);
=
new
Lazy
<
bool
>(()
=>
Type
.
GetType
(
"Mono.Runtime"
)
!=
null
);
/// <summary>
/// Is running on Mono?
/// </summary>
...
...
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpHandle.cs
View file @
e2c392f9
...
...
@@ -16,4 +16,4 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public
override
bool
IsInvalid
=>
handle
==
IntPtr
.
Zero
;
}
}
\ No newline at end of file
}
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
View file @
e2c392f9
...
...
@@ -21,7 +21,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public
bool
BypassLoopback
{
get
;
internal
set
;
}
public
bool
BypassOnLocal
{
get
;
internal
set
;
}
public
Uri
AutomaticConfigurationScript
{
get
;
internal
set
;
}
public
bool
AutomaticallyDetectSettings
{
get
;
internal
set
;
}
...
...
@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
if
(!
WinHttpGetProxyForUrl
(
destination
.
ToString
(),
ref
autoProxyOptions
,
out
proxyListString
))
{
num
=
GetLastWin32Error
();
if
(
num
==
(
int
)
NativeMethods
.
WinHttp
.
ErrorCodes
.
LoginFailure
&&
Credentials
!=
null
)
{
autoProxyOptions
.
AutoLogonIfChallenged
=
true
;
...
...
@@ -329,4 +329,4 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
Completed
,
}
}
}
\ No newline at end of file
}
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
e2c392f9
...
...
@@ -84,8 +84,8 @@ namespace Titanium.Web.Proxy.Http
//Send Authentication to Upstream proxy if needed
if
(
ServerConnection
.
UpStreamHttpProxy
!=
null
&&
ServerConnection
.
IsHttps
==
false
if
(
ServerConnection
.
UpStreamHttpProxy
!=
null
&&
ServerConnection
.
IsHttps
==
false
&&
!
string
.
IsNullOrEmpty
(
ServerConnection
.
UpStreamHttpProxy
.
UserName
)
&&
ServerConnection
.
UpStreamHttpProxy
.
Password
!=
null
)
{
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
e2c392f9
...
...
@@ -431,12 +431,11 @@ namespace Titanium.Web.Proxy.Http
RequestHeaders
.
Remove
(
header
.
Name
);
return
true
;
}
}
else
if
(
NonUniqueRequestHeaders
.
ContainsKey
(
header
.
Name
))
{
if
(
NonUniqueRequestHeaders
[
header
.
Name
]
.
RemoveAll
(
x
=>
x
.
Equals
(
header
))
>
0
)
.
RemoveAll
(
x
=>
x
.
Equals
(
header
))
>
0
)
{
return
true
;
}
...
...
@@ -460,7 +459,5 @@ namespace Titanium.Web.Proxy.Http
RequestBody
=
null
;
RequestBody
=
null
;
}
}
}
Titanium.Web.Proxy/Http/Response.cs
View file @
e2c392f9
...
...
@@ -249,7 +249,7 @@ namespace Titanium.Web.Proxy.Http
/// <returns></returns>
public
bool
HeaderExists
(
string
name
)
{
if
(
ResponseHeaders
.
ContainsKey
(
name
)
if
(
ResponseHeaders
.
ContainsKey
(
name
)
||
NonUniqueResponseHeaders
.
ContainsKey
(
name
))
{
return
true
;
...
...
@@ -336,7 +336,7 @@ namespace Titanium.Web.Proxy.Http
/// False if no header exists with given name</returns>
public
bool
RemoveHeader
(
string
headerName
)
{
if
(
ResponseHeaders
.
ContainsKey
(
headerName
))
if
(
ResponseHeaders
.
ContainsKey
(
headerName
))
{
ResponseHeaders
.
Remove
(
headerName
);
return
true
;
...
...
@@ -363,12 +363,11 @@ namespace Titanium.Web.Proxy.Http
ResponseHeaders
.
Remove
(
header
.
Name
);
return
true
;
}
}
else
if
(
NonUniqueResponseHeaders
.
ContainsKey
(
header
.
Name
))
{
if
(
NonUniqueResponseHeaders
[
header
.
Name
]
.
RemoveAll
(
x
=>
x
.
Equals
(
header
))
>
0
)
.
RemoveAll
(
x
=>
x
.
Equals
(
header
))
>
0
)
{
return
true
;
}
...
...
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
e2c392f9
...
...
@@ -53,7 +53,6 @@ namespace Titanium.Web.Proxy.Models
public
bool
IpV6Enabled
=>
Equals
(
IpAddress
,
IPAddress
.
IPv6Any
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6Loopback
)
||
Equals
(
IpAddress
,
IPAddress
.
IPv6None
);
}
/// <summary>
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
e2c392f9
...
...
@@ -351,7 +351,7 @@ namespace Titanium.Web.Proxy.Network
x509Store
.
Close
();
}
}
/// <summary>
/// Create an SSL certificate
/// </summary>
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
e2c392f9
...
...
@@ -34,11 +34,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
bool
isHttps
,
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
)
{
bool
useHttpProxy
=
false
;
bool
useHttpProxy
=
false
;
//check if external proxy is set for HTTP
if
(!
isHttps
&&
externalHttpProxy
!=
null
&&
!(
externalHttpProxy
.
HostName
==
remoteHostName
&&
externalHttpProxy
.
Port
==
remotePort
))
&&
externalHttpProxy
.
Port
==
remotePort
))
{
useHttpProxy
=
true
;
...
...
@@ -53,8 +53,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
bool
useHttpsProxy
=
false
;
//check if external proxy is set for HTTPS
if
(
isHttps
&&
externalHttpsProxy
!=
null
&&
!(
externalHttpsProxy
.
HostName
==
remoteHostName
&&
externalHttpsProxy
.
Port
==
remotePort
))
&&
!(
externalHttpsProxy
.
HostName
==
remoteHostName
&&
externalHttpsProxy
.
Port
==
remotePort
))
{
useHttpsProxy
=
true
;
...
...
Titanium.Web.Proxy/Network/WinAuth/Security/Common.cs
View file @
e2c392f9
...
...
@@ -6,25 +6,30 @@
internal
class
Common
{
#
region
Private
constants
private
const
int
ISC_REQ_REPLAY_DETECT
=
0x00000004
;
private
const
int
ISC_REQ_SEQUENCE_DETECT
=
0x00000008
;
private
const
int
ISC_REQ_CONFIDENTIALITY
=
0x00000010
;
private
const
int
ISC_REQ_CONNECTION
=
0x00000800
;
#
endregion
internal
static
uint
NewContextAttributes
=
0
;
internal
static
SecurityInteger
NewLifeTime
=
new
SecurityInteger
(
0
);
#
region
internal
constants
internal
const
int
StandardContextAttributes
=
ISC_REQ_CONFIDENTIALITY
|
ISC_REQ_REPLAY_DETECT
|
ISC_REQ_SEQUENCE_DETECT
|
ISC_REQ_CONNECTION
;
internal
const
int
SecurityNativeDataRepresentation
=
0x10
;
internal
const
int
MaximumTokenSize
=
12288
;
internal
const
int
SecurityCredentialsOutbound
=
2
;
internal
const
int
SuccessfulResult
=
0
;
internal
const
int
IntermediateResult
=
0x90312
;
#
endregion
#
region
internal
enumerations
internal
enum
SecurityBufferType
{
SECBUFFER_VERSION
=
0
,
...
...
@@ -38,22 +43,31 @@
{
// The client sets this flag to indicate that it supports Unicode strings.
NegotiateUnicode
=
0x00000001
,
// This is set to indicate that the client supports OEM strings.
NegotiateOem
=
0x00000002
,
// This requests that the server send the authentication target with the Type 2 reply.
RequestTarget
=
0x00000004
,
// Indicates that NTLM authentication is supported.
NegotiateNtlm
=
0x00000200
,
// When set, the client will send with the message the name of the domain in which the workstation has membership.
NegotiateDomainSupplied
=
0x00001000
,
// Indicates that the client is sending its workstation name with the message.
NegotiateWorkstationSupplied
=
0x00002000
,
// Indicates that communication between the client and server after authentication should carry a "dummy" signature.
NegotiateAlwaysSign
=
0x00008000
,
// Indicates that this client supports the NTLM2 signing and sealing scheme; if negotiated, this can also affect the response calculations.
NegotiateNtlm2Key
=
0x00080000
,
// Indicates that this client supports strong (128-bit) encryption.
Negotiate128
=
0x20000000
,
// Indicates that this client supports medium (56-bit) encryption.
Negotiate56
=
(
unchecked
((
int
)
0x80000000
))
}
...
...
@@ -74,9 +88,11 @@
/* Use NTLMv2 only. */
NTLMv2_only
,
}
#
endregion
#
region
internal
structures
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
SecurityHandle
{
...
...
@@ -102,6 +118,7 @@
{
internal
uint
LowPart
;
internal
int
HighPart
;
internal
SecurityInteger
(
int
dummy
)
{
LowPart
=
0
;
...
...
@@ -152,7 +169,6 @@
[
StructLayout
(
LayoutKind
.
Sequential
)]
internal
struct
SecurityBufferDesciption
:
IDisposable
{
internal
int
ulVersion
;
internal
int
cBuffers
;
internal
IntPtr
pBuffers
;
//Point to SecBuffer
...
...
@@ -260,6 +276,7 @@
return
(
buffer
);
}
}
#
endregion
}
}
Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs
View file @
e2c392f9
...
...
@@ -31,221 +31,230 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
using
System
;
internal
sealed
class
LittleEndian
{
private
LittleEndian
()
{
}
unsafe
private
static
byte
[]
GetUShortBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
internal
sealed
class
LittleEndian
{
private
LittleEndian
()
{
}
unsafe
private
static
byte
[]
GetUShortBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
return
new
[]
{
bytes
[
0
],
bytes
[
1
]
};
}
return
new
[]
{
bytes
[
1
],
bytes
[
0
]
};
}
}
unsafe
private
static
byte
[]
GetUIntBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
unsafe
private
static
byte
[]
GetUIntBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
return
new
[]
{
bytes
[
0
],
bytes
[
1
],
bytes
[
2
],
bytes
[
3
]
};
}
return
new
[]
{
bytes
[
3
],
bytes
[
2
],
bytes
[
1
],
bytes
[
0
]
};
}
}
unsafe
private
static
byte
[]
GetULongBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
unsafe
private
static
byte
[]
GetULongBytes
(
byte
*
bytes
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
return
new
[]
{
bytes
[
0
],
bytes
[
1
],
bytes
[
2
],
bytes
[
3
],
bytes
[
4
],
bytes
[
5
],
bytes
[
6
],
bytes
[
7
]
};
return
new
[]
{
bytes
[
0
],
bytes
[
1
],
bytes
[
2
],
bytes
[
3
],
bytes
[
4
],
bytes
[
5
],
bytes
[
6
],
bytes
[
7
]
};
}
return
new
[]
{
bytes
[
7
],
bytes
[
6
],
bytes
[
5
],
bytes
[
4
],
bytes
[
3
],
bytes
[
2
],
bytes
[
1
],
bytes
[
0
]
};
}
internal
static
byte
[]
GetBytes
(
bool
value
)
{
return
new
[]
{
value
?
(
byte
)
1
:
(
byte
)
0
};
}
unsafe
internal
static
byte
[]
GetBytes
(
char
value
)
{
return
GetUShortBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
short
value
)
{
return
GetUShortBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
int
value
)
{
return
GetUIntBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
long
value
)
{
return
GetULongBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
ushort
value
)
{
return
GetUShortBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
uint
value
)
{
return
GetUIntBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
ulong
value
)
{
return
GetULongBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
float
value
)
{
return
GetUIntBytes
((
byte
*)
&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
double
value
)
{
return
GetULongBytes
((
byte
*)
&
value
);
}
unsafe
private
static
void
UShortFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
return
new
[]
{
dst
[
0
]
=
src
[
startIndex
];
dst
[
1
]
=
src
[
startIndex
+
1
];
}
else
bytes
[
7
],
bytes
[
6
],
bytes
[
5
],
bytes
[
4
],
bytes
[
3
],
bytes
[
2
],
bytes
[
1
],
bytes
[
0
]
};
}
internal
static
byte
[]
GetBytes
(
bool
value
)
{
return
new
[]
{
value
?
(
byte
)
1
:
(
byte
)
0
};
}
unsafe
internal
static
byte
[]
GetBytes
(
char
value
)
{
return
GetUShortBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
short
value
)
{
return
GetUShortBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
int
value
)
{
return
GetUIntBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
long
value
)
{
return
GetULongBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
ushort
value
)
{
return
GetUShortBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
uint
value
)
{
return
GetUIntBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
ulong
value
)
{
return
GetULongBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
float
value
)
{
return
GetUIntBytes
((
byte
*)&
value
);
}
unsafe
internal
static
byte
[]
GetBytes
(
double
value
)
{
return
GetULongBytes
((
byte
*)&
value
);
}
unsafe
private
static
void
UShortFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
dst
[
0
]
=
src
[
startIndex
+
1
];
dst
[
1
]
=
src
[
startIndex
];
}
}
unsafe
private
static
void
UIntFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
dst
[
0
]
=
src
[
startIndex
];
dst
[
1
]
=
src
[
startIndex
+
1
];
}
else
{
dst
[
0
]
=
src
[
startIndex
];
dst
[
1
]
=
src
[
startIndex
+
1
];
dst
[
2
]
=
src
[
startIndex
+
2
];
dst
[
3
]
=
src
[
startIndex
+
3
];
}
else
dst
[
0
]
=
src
[
startIndex
+
1
];
dst
[
1
]
=
src
[
startIndex
];
}
}
unsafe
private
static
void
UIntFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
dst
[
0
]
=
src
[
startIndex
];
dst
[
1
]
=
src
[
startIndex
+
1
];
dst
[
2
]
=
src
[
startIndex
+
2
];
dst
[
3
]
=
src
[
startIndex
+
3
];
}
else
{
dst
[
0
]
=
src
[
startIndex
+
3
];
dst
[
1
]
=
src
[
startIndex
+
2
];
dst
[
2
]
=
src
[
startIndex
+
1
];
dst
[
3
]
=
src
[
startIndex
];
}
}
dst
[
0
]
=
src
[
startIndex
+
3
];
dst
[
1
]
=
src
[
startIndex
+
2
];
dst
[
2
]
=
src
[
startIndex
+
1
];
dst
[
3
]
=
src
[
startIndex
];
}
}
unsafe
private
static
void
ULongFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
dst
[
i
]
=
src
[
startIndex
+
i
];
}
else
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
dst
[
i
]
=
src
[
startIndex
+
(
7
-
i
)];
}
}
unsafe
private
static
void
ULongFromBytes
(
byte
*
dst
,
byte
[]
src
,
int
startIndex
)
{
if
(
BitConverter
.
IsLittleEndian
)
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
dst
[
i
]
=
src
[
startIndex
+
i
];
}
else
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
dst
[
i
]
=
src
[
startIndex
+
(
7
-
i
)];
}
}
internal
static
bool
ToBoolean
(
byte
[]
value
,
int
startIndex
)
{
return
value
[
startIndex
]
!=
0
;
}
internal
static
bool
ToBoolean
(
byte
[]
value
,
int
startIndex
)
{
return
value
[
startIndex
]
!=
0
;
}
unsafe
internal
static
char
ToChar
(
byte
[]
value
,
int
startIndex
)
{
char
ret
;
unsafe
internal
static
char
ToChar
(
byte
[]
value
,
int
startIndex
)
{
char
ret
;
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
short
ToInt16
(
byte
[]
value
,
int
startIndex
)
{
short
ret
;
unsafe
internal
static
short
ToInt16
(
byte
[]
value
,
int
startIndex
)
{
short
ret
;
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
int
ToInt32
(
byte
[]
value
,
int
startIndex
)
{
int
ret
;
unsafe
internal
static
int
ToInt32
(
byte
[]
value
,
int
startIndex
)
{
int
ret
;
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
long
ToInt64
(
byte
[]
value
,
int
startIndex
)
{
long
ret
;
unsafe
internal
static
long
ToInt64
(
byte
[]
value
,
int
startIndex
)
{
long
ret
;
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
ushort
ToUInt16
(
byte
[]
value
,
int
startIndex
)
{
ushort
ret
;
unsafe
internal
static
ushort
ToUInt16
(
byte
[]
value
,
int
startIndex
)
{
ushort
ret
;
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UShortFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
uint
ToUInt32
(
byte
[]
value
,
int
startIndex
)
{
uint
ret
;
unsafe
internal
static
uint
ToUInt32
(
byte
[]
value
,
int
startIndex
)
{
uint
ret
;
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
ulong
ToUInt64
(
byte
[]
value
,
int
startIndex
)
{
ulong
ret
;
unsafe
internal
static
ulong
ToUInt64
(
byte
[]
value
,
int
startIndex
)
{
ulong
ret
;
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
float
ToSingle
(
byte
[]
value
,
int
startIndex
)
{
float
ret
;
unsafe
internal
static
float
ToSingle
(
byte
[]
value
,
int
startIndex
)
{
float
ret
;
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
UIntFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
return
ret
;
}
unsafe
internal
static
double
ToDouble
(
byte
[]
value
,
int
startIndex
)
{
double
ret
;
unsafe
internal
static
double
ToDouble
(
byte
[]
value
,
int
startIndex
)
{
double
ret
;
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
ULongFromBytes
((
byte
*)
&
ret
,
value
,
startIndex
);
return
ret
;
}
}
return
ret
;
}
}
}
Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
View file @
e2c392f9
...
...
@@ -33,46 +33,38 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
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
};
internal
Message
(
byte
[]
message
)
{
type
=
3
;
Decode
(
message
);
}
/// <summary>
/// Domain name
/// </summary>
internal
string
Domain
internal
Message
(
byte
[]
message
)
{
get
;
private
set
;
type
=
3
;
Decode
(
message
)
;
}
/// <summary>
/// Domain name
/// </summary>
internal
string
Domain
{
get
;
private
set
;
}
/// <summary>
/// Username
/// </summary>
internal
string
Username
{
get
;
private
set
;
}
internal
string
Username
{
get
;
private
set
;
}
private
readonly
int
type
;
internal
Common
.
NtlmFlags
Flags
{
get
;
set
;
}
// methods
private
void
Decode
(
byte
[]
message
)
{
private
void
Decode
(
byte
[]
message
)
{
//base.Decode (message);
if
(
message
==
null
)
...
...
@@ -90,11 +82,11 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
throw
new
ArgumentException
(
msg
,
"message"
);
}
if
(
LittleEndian
.
ToUInt16
(
message
,
56
)
!=
message
.
Length
)
if
(
LittleEndian
.
ToUInt16
(
message
,
56
)
!=
message
.
Length
)
{
string
msg
=
"Invalid Type3 message length."
;
throw
new
ArgumentException
(
msg
,
"message"
);
}
string
msg
=
"Invalid Type3 message length."
;
throw
new
ArgumentException
(
msg
,
"message"
);
}
if
(
message
.
Length
>=
64
)
{
...
...
@@ -104,26 +96,26 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
{
Flags
=
(
Common
.
NtlmFlags
)
0x8201
;
}
int
domLen
=
LittleEndian
.
ToUInt16
(
message
,
28
);
int
domOff
=
LittleEndian
.
ToUInt16
(
message
,
32
);
Domain
=
DecodeString
(
message
,
domOff
,
domLen
);
int
domLen
=
LittleEndian
.
ToUInt16
(
message
,
28
);
int
domOff
=
LittleEndian
.
ToUInt16
(
message
,
32
);
int
userLen
=
LittleEndian
.
ToUInt16
(
message
,
36
);
int
userOff
=
LittleEndian
.
ToUInt16
(
message
,
40
);
Domain
=
DecodeString
(
message
,
domOff
,
domLen
);
Username
=
DecodeString
(
message
,
userOff
,
userLen
);
}
int
userLen
=
LittleEndian
.
ToUInt16
(
message
,
36
);
int
userOff
=
LittleEndian
.
ToUInt16
(
message
,
40
);
Username
=
DecodeString
(
message
,
userOff
,
userLen
);
}
string
DecodeString
(
byte
[]
buffer
,
int
offset
,
int
len
)
{
if
((
Flags
&
Common
.
NtlmFlags
.
NegotiateUnicode
)
!=
0
)
string
DecodeString
(
byte
[]
buffer
,
int
offset
,
int
len
)
{
if
((
Flags
&
Common
.
NtlmFlags
.
NegotiateUnicode
)
!=
0
)
{
return
Encoding
.
Unicode
.
GetString
(
buffer
,
offset
,
len
);
}
return
Encoding
.
ASCII
.
GetString
(
buffer
,
offset
,
len
);
}
return
Encoding
.
ASCII
.
GetString
(
buffer
,
offset
,
len
);
}
protected
bool
CheckHeader
(
byte
[]
message
)
{
...
...
@@ -134,6 +126,5 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
}
return
(
LittleEndian
.
ToUInt32
(
message
,
8
)
==
type
);
}
}
}
Titanium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
View file @
e2c392f9
...
...
@@ -216,7 +216,6 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
ref
SecurityHandle
phCredential
,
//SecHandle //PCtxtHandle ref
ref
SecurityInteger
ptsExpiry
);
//PTimeStamp //TimeStamp ref
#
endregion
}
}
Titanium.Web.Proxy/Network/WinAuth/WinAuthHandler.cs
View file @
e2c392f9
...
...
@@ -18,11 +18,11 @@ namespace Titanium.Web.Proxy.Network.WinAuth
/// <param name="authScheme"></param>
/// <param name="requestId"></param>
/// <returns></returns>
public
static
string
GetInitialAuthToken
(
string
serverHostname
,
public
static
string
GetInitialAuthToken
(
string
serverHostname
,
string
authScheme
,
Guid
requestId
)
{
var
tokenBytes
=
WinAuthEndPoint
.
AcquireInitialSecurityToken
(
serverHostname
,
authScheme
,
requestId
);
return
string
.
Concat
(
" "
,
Convert
.
ToBase64String
(
tokenBytes
));
var
tokenBytes
=
WinAuthEndPoint
.
AcquireInitialSecurityToken
(
serverHostname
,
authScheme
,
requestId
);
return
string
.
Concat
(
" "
,
Convert
.
ToBase64String
(
tokenBytes
));
}
...
...
@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth
/// <param name="serverToken"></param>
/// <param name="requestId"></param>
/// <returns></returns>
public
static
string
GetFinalAuthToken
(
string
serverHostname
,
public
static
string
GetFinalAuthToken
(
string
serverHostname
,
string
serverToken
,
Guid
requestId
)
{
var
tokenBytes
=
WinAuthEndPoint
.
AcquireFinalSecurityToken
(
serverHostname
,
...
...
@@ -41,6 +41,5 @@ namespace Titanium.Web.Proxy.Network.WinAuth
return
string
.
Concat
(
" "
,
Convert
.
ToBase64String
(
tokenBytes
));
}
}
}
Titanium.Web.Proxy/ProxyServer.cs
View file @
e2c392f9
...
...
@@ -290,7 +290,7 @@ namespace Titanium.Web.Proxy
{
systemProxySettingsManager
=
new
SystemProxyManager
();
}
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
if
(
rootCertificateName
!=
null
)
{
...
...
@@ -409,7 +409,9 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager
.
SetProxy
(
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Loopback
)
?
"127.0.0.1"
:
endPoint
.
IpAddress
.
ToString
(),
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Loopback
)
?
"127.0.0.1"
:
endPoint
.
IpAddress
.
ToString
(),
endPoint
.
Port
,
protocolType
);
...
...
@@ -521,7 +523,7 @@ namespace Titanium.Web.Proxy
}
}
if
(
ForwardToUpstreamGateway
if
(
ForwardToUpstreamGateway
&&
GetCustomUpStreamHttpProxyFunc
==
null
&&
GetCustomUpStreamHttpsProxyFunc
==
null
&&
systemProxySettingsManager
!=
null
)
{
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
e2c392f9
...
...
@@ -88,7 +88,7 @@ namespace Titanium.Web.Proxy
List
<
HttpHeader
>
connectRequestHeaders
=
null
;
//Client wants to create a secure tcp tunnel (its a HTTPS request)
if
(
httpVerb
==
"CONNECT"
&&
!
excluded
if
(
httpVerb
==
"CONNECT"
&&
!
excluded
&&
endPoint
.
RemoteHttpsPorts
.
Contains
(
httpRemoteUri
.
Port
))
{
httpRemoteUri
=
new
Uri
(
"https://"
+
httpCmdSplit
[
1
]);
...
...
@@ -380,7 +380,7 @@ namespace Titanium.Web.Proxy
args
.
Dispose
();
break
;
}
//if connection is closing exit
if
(
args
.
WebSession
.
Response
.
ResponseKeepAlive
==
false
)
{
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
e2c392f9
...
...
@@ -32,13 +32,13 @@ namespace Titanium.Web.Proxy
await
args
.
WebSession
.
ReceiveResponse
();
//check for windows authentication
if
(
EnableWinAuth
if
(
EnableWinAuth
&&
!
RunTime
.
IsRunningOnMono
&&
args
.
WebSession
.
Response
.
ResponseStatusCode
==
"401"
)
{
var
disposed
=
await
Handle401UnAuthorized
(
args
);
if
(
disposed
)
if
(
disposed
)
{
return
true
;
}
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
e2c392f9
...
...
@@ -115,7 +115,6 @@ namespace Titanium.Web.Proxy
{
args
.
WebSession
.
Request
.
ContentLength
=
0
;
}
}
//challenge value will start with any of the scheme selected
else
...
...
@@ -136,7 +135,6 @@ namespace Titanium.Web.Proxy
args
.
WebSession
.
Request
.
ContentLength
=
args
.
WebSession
.
Request
.
RequestBody
.
Length
;
}
}
//Need to revisit this.
...
...
@@ -154,6 +152,5 @@ namespace Titanium.Web.Proxy
return
false
;
}
}
}
\ No newline at end of file
}
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