Commit e2c392f9 authored by Honfika's avatar Honfika

Format code

parent 711fc5e5
......@@ -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;
......
......@@ -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>
......
......@@ -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
......
......@@ -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)
......
......@@ -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>
......
......@@ -16,4 +16,4 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public override bool IsInvalid => handle == IntPtr.Zero;
}
}
\ No newline at end of file
}
......@@ -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
}
......@@ -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)
{
......
......@@ -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;
}
}
}
......@@ -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;
}
......
......@@ -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>
......
......@@ -351,7 +351,7 @@ namespace Titanium.Web.Proxy.Network
x509Store.Close();
}
}
/// <summary>
/// Create an SSL certificate
/// </summary>
......
......@@ -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;
......
......@@ -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
}
}
......@@ -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);
}
}
}
......@@ -216,7 +216,6 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
ref SecurityHandle phCredential, //SecHandle //PCtxtHandle ref
ref SecurityInteger ptsExpiry); //PTimeStamp //TimeStamp ref
#endregion
}
}
......@@ -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));
}
}
}
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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;
}
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment