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
71d22f74
Commit
71d22f74
authored
Mar 28, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small cleanup
parent
7aaf9213
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
21 deletions
+24
-21
StringExtensions.cs
Titanium.Web.Proxy/Extensions/StringExtensions.cs
+5
-0
WinAuthEndPoint.cs
...ium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
+10
-16
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+9
-5
No files found.
Titanium.Web.Proxy/Extensions/StringExtensions.cs
View file @
71d22f74
...
...
@@ -14,5 +14,10 @@ namespace Titanium.Web.Proxy.Extensions
{
return
CultureInfo
.
CurrentCulture
.
CompareInfo
.
IndexOf
(
str
,
value
,
CompareOptions
.
IgnoreCase
)
>=
0
;
}
internal
static
int
IndexOfIgnoreCase
(
this
string
str
,
string
value
)
{
return
CultureInfo
.
CurrentCulture
.
CompareInfo
.
IndexOf
(
str
,
value
,
CompareOptions
.
IgnoreCase
);
}
}
}
Titanium.Web.Proxy/Network/WinAuth/Security/WinAuthEndPoint.cs
View file @
71d22f74
...
...
@@ -38,11 +38,9 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
try
{
int
result
;
var
state
=
new
State
();
result
=
AcquireCredentialsHandle
(
int
result
=
AcquireCredentialsHandle
(
WindowsIdentity
.
GetCurrent
().
Name
,
authScheme
,
SecurityCredentialsOutbound
,
...
...
@@ -110,13 +108,11 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
try
{
int
result
;
var
state
=
authStates
[
requestId
];
state
.
UpdatePresence
();
result
=
InitializeSecurityContext
(
ref
state
.
Credentials
,
int
result
=
InitializeSecurityContext
(
ref
state
.
Credentials
,
ref
state
.
Context
,
hostname
,
StandardContextAttributes
,
...
...
@@ -176,23 +172,22 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
/// <returns></returns>
internal
static
bool
ValidateWinAuthState
(
Guid
requestId
,
State
.
WinAuthState
expectedAuthState
)
{
State
state
;
var
stateExists
=
authStates
.
TryGetValue
(
requestId
,
out
state
);
var
stateExists
=
authStates
.
TryGetValue
(
requestId
,
out
var
state
);
if
(
expectedAuthState
==
State
.
WinAuthState
.
UNAUTHORIZED
)
{
// Validation before initial token
return
(
stateExists
==
false
||
state
.
AuthState
==
State
.
WinAuthState
.
UNAUTHORIZED
||
state
.
AuthState
==
State
.
WinAuthState
.
AUTHORIZED
)
;
// Server may require re-authentication on an open connection
return
stateExists
==
false
||
state
.
AuthState
==
State
.
WinAuthState
.
UNAUTHORIZED
||
state
.
AuthState
==
State
.
WinAuthState
.
AUTHORIZED
;
// Server may require re-authentication on an open connection
}
if
(
expectedAuthState
==
State
.
WinAuthState
.
INITIAL_TOKEN
)
{
// Validation before final token
return
(
stateExists
&&
(
state
.
AuthState
==
State
.
WinAuthState
.
INITIAL_TOKEN
||
state
.
AuthState
==
State
.
WinAuthState
.
AUTHORIZED
)
);
// Server may require re-authentication on an open connection
return
stateExists
&&
(
state
.
AuthState
==
State
.
WinAuthState
.
INITIAL_TOKEN
||
state
.
AuthState
==
State
.
WinAuthState
.
AUTHORIZED
);
// Server may require re-authentication on an open connection
}
throw
new
Exception
(
"Unsupported validation of WinAuthState"
);
...
...
@@ -204,8 +199,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
/// <param name="requestId"></param>
internal
static
void
AuthenticatedResponse
(
Guid
requestId
)
{
State
state
;
if
(
authStates
.
TryGetValue
(
requestId
,
out
state
))
if
(
authStates
.
TryGetValue
(
requestId
,
out
var
state
))
{
state
.
AuthState
=
State
.
WinAuthState
.
AUTHORIZED
;
state
.
UpdatePresence
();
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
71d22f74
...
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.WinAuth
;
...
...
@@ -85,8 +86,9 @@ namespace Titanium.Web.Proxy
{
string
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
Equals
(
x
,
StringComparison
.
OrdinalIgnoreCase
));
if
((
scheme
!=
null
&&
!
WinAuthEndPoint
.
ValidateWinAuthState
(
args
.
WebSession
.
RequestId
,
State
.
WinAuthState
.
UNAUTHORIZED
))
||
(
scheme
==
null
&&
!
WinAuthEndPoint
.
ValidateWinAuthState
(
args
.
WebSession
.
RequestId
,
State
.
WinAuthState
.
INITIAL_TOKEN
)))
var
expectedAuthState
=
scheme
==
null
?
State
.
WinAuthState
.
INITIAL_TOKEN
:
State
.
WinAuthState
.
UNAUTHORIZED
;
if
(!
WinAuthEndPoint
.
ValidateWinAuthState
(
args
.
WebSession
.
RequestId
,
expectedAuthState
))
{
// Invalid state, create proper error message to client
await
RewriteUnauthorizedResponse
(
args
);
...
...
@@ -117,7 +119,7 @@ namespace Titanium.Web.Proxy
//challenge value will start with any of the scheme selected
else
{
scheme
=
authSchemes
.
First
OrDefault
(
x
=>
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
scheme
=
authSchemes
.
First
(
x
=>
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
authHeader
.
Value
.
Length
>
x
.
Length
+
1
);
string
serverToken
=
authHeader
.
Value
.
Substring
(
scheme
.
Length
+
1
);
...
...
@@ -152,6 +154,7 @@ namespace Titanium.Web.Proxy
internal
async
Task
RewriteUnauthorizedResponse
(
SessionEventArgs
args
)
{
var
response
=
args
.
WebSession
.
Response
;
// Strip authentication headers to avoid credentials prompt in client web browser
foreach
(
var
authHeaderName
in
authHeaderNames
)
{
...
...
@@ -164,9 +167,10 @@ namespace Titanium.Web.Proxy
") failed. Please check credentials.</h2></div>"
;
string
originalErrorMessage
=
"<div class=\"inserted-by-proxy\"><h3>Response from remote web server below.</h3></div><br/>"
;
string
body
=
await
args
.
GetResponseBodyAsString
();
if
(
body
.
ToLower
().
Contains
(
"<body>"
))
int
idx
=
body
.
IndexOfIgnoreCase
(
"<body>"
);
if
(
idx
>=
0
)
{
var
bodyPos
=
body
.
ToLower
().
IndexOf
(
"<body>"
)
+
(
"<body>"
)
.
Length
;
var
bodyPos
=
idx
+
"<body>"
.
Length
;
body
=
body
.
Insert
(
bodyPos
,
authErrorMessage
+
originalErrorMessage
);
}
else
...
...
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