Commit 3bf4649c authored by Honfika's avatar Honfika

stylecop fixes

parent 875ba62f
......@@ -27,7 +27,7 @@ namespace Titanium.Web.Proxy.EventArguments
protected readonly ExceptionHandler ExceptionFunc;
/// <summary>
/// Constructor to initialize the proxy
/// Initializes a new instance of the <see cref="SessionEventArgsBase" /> class.
/// </summary>
internal SessionEventArgsBase(int bufferSize, ProxyEndPoint endPoint,
CancellationTokenSource cancellationTokenSource, ExceptionHandler exceptionFunc)
......
......@@ -37,6 +37,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
get => isHttpsConnect ??
throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event");
internal set => isHttpsConnect = value;
}
}
......
......@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Exceptions
public class ProxyAuthorizationException : ProxyException
{
/// <summary>
/// Instantiate new instance.
/// Initializes a new instance of the <see cref="ProxyAuthorizationException" /> class.
/// </summary>
/// <param name="message">Exception message.</param>
/// <param name="session">The <see cref="SessionEventArgs" /> instance containing the event data.</param>
......
......@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.Exceptions
public class ProxyConnectException : ProxyException
{
/// <summary>
/// Instantiate new instance
/// Initializes a new instance of the <see cref="ProxyConnectException" /> class.
/// </summary>
/// <param name="message">Message for this exception</param>
/// <param name="innerException">Associated inner exception</param>
......
......@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Exceptions
public abstract class ProxyException : Exception
{
/// <summary>
/// Instantiate a new instance of this exception - must be invoked by derived classes' constructors
/// Initializes a new instance of the <see cref="ProxyException" /> class.
/// - must be invoked by derived classes' constructors
/// </summary>
/// <param name="message">Exception message</param>
protected ProxyException(string message) : base(message)
......@@ -16,7 +17,8 @@ namespace Titanium.Web.Proxy.Exceptions
}
/// <summary>
/// Instantiate this exception - must be invoked by derived classes' constructors
/// Initializes a new instance of the <see cref="ProxyException" /> class.
/// - must be invoked by derived classes' constructors
/// </summary>
/// <param name="message">Excception message</param>
/// <param name="innerException">Inner exception associated</param>
......
......@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.Exceptions
public class ProxyHttpException : ProxyException
{
/// <summary>
/// Instantiate new instance
/// Initializes a new instance of the <see cref="ProxyHttpException" /> class.
/// </summary>
/// <param name="message">Message for this exception</param>
/// <param name="innerException">Associated inner exception</param>
......
......@@ -20,7 +20,7 @@ using Titanium.Web.Proxy.Network.Tcp;
namespace Titanium.Web.Proxy
{
partial class ProxyServer
public partial class ProxyServer
{
/// <summary>
/// This is called when client is aware of proxy
......@@ -278,7 +278,7 @@ namespace Titanium.Web.Proxy
// Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
}
catch (ProxyException e)
{
......
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
......@@ -81,6 +82,7 @@ namespace Titanium.Web.Proxy.Extensions
Http2
}
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleType", Justification = "Reviewed.")]
internal class SslClientAuthenticationOptions
{
internal bool AllowRenegotiation { get; set; }
......
......@@ -35,7 +35,7 @@ namespace Titanium.Web.Proxy.Helpers
if (split.Length == 2 && split[0].Trim().EqualsIgnoreCase(KnownHeaders.ContentTypeCharset))
{
string value = split[1];
if (value.Equals("x-user-defined", StringComparison.OrdinalIgnoreCase))
if (value.EqualsIgnoreCase("x-user-defined"))
{
continue;
}
......
......@@ -21,6 +21,7 @@ namespace Titanium.Web.Proxy.Helpers
// get local IP addresses
var localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
return localIPs.Contains(address);
}
......
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.Win32;
using Titanium.Web.Proxy.Models;
......@@ -6,7 +7,6 @@ using Titanium.Web.Proxy.Models;
// Helper classes for setting system proxy settings
namespace Titanium.Web.Proxy.Helpers
{
internal class HttpSystemProxyValue
{
internal string HostName { get; set; }
......@@ -37,6 +37,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary>
/// Manage system proxy settings
/// </summary>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleType", Justification = "Reviewed.")]
internal class SystemProxyManager
{
private const string regKeyInternetSettings = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
......
......@@ -93,8 +93,7 @@ namespace Titanium.Web.Proxy.Http
await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method,
useUpstreamProxy || isTransparent ? Request.OriginalUrl : Request.RequestUri.PathAndQuery,
Request.HttpVersion), cancellationToken);
// Send Authentication to Upstream proxy if needed
if (!isTransparent && upstreamProxy != null
&& ServerConnection.IsHttps == false
......
......@@ -212,7 +212,7 @@ namespace Titanium.Web.Proxy.Http
{
string httpVersion = httpCmdSplit[2].Trim();
if (string.Equals(httpVersion, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
if (httpVersion.EqualsIgnoreCase("HTTP/1.0"))
{
version = HttpHeader.Version10;
}
......
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using Titanium.Web.Proxy.Compression;
......@@ -14,7 +15,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Cached body content as byte array.
/// </summary>
protected byte[] BodyInternal;
protected byte[] BodyInternal { get; private set; }
/// <summary>
/// Cached body as string.
......@@ -24,7 +25,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Store weather the original request/response has body or not, since the user may change the parameters
/// </summary>
internal bool OriginalHasBody;
internal bool OriginalHasBody { get; set; }
/// <summary>
/// Keeps the body data after the session is finished.
......@@ -62,6 +63,7 @@ namespace Titanium.Web.Proxy.Http
return -1;
}
set
{
if (value >= 0)
......@@ -105,6 +107,7 @@ namespace Titanium.Web.Proxy.Http
string headerValue = Headers.GetHeaderValueOrNull(KnownHeaders.TransferEncoding);
return headerValue != null && headerValue.ContainsIgnoreCase(KnownHeaders.TransferEncodingChunked);
}
set
{
if (value)
......@@ -135,6 +138,7 @@ namespace Titanium.Web.Proxy.Http
EnsureBodyAvailable();
return BodyInternal;
}
internal set
{
BodyInternal = value;
......
......@@ -155,7 +155,7 @@ namespace Titanium.Web.Proxy.Http
string httpVersion = httpResult[0];
version = HttpHeader.Version11;
if (string.Equals(httpVersion, "HTTP/1.0", StringComparison.OrdinalIgnoreCase))
if (httpVersion.EqualsIgnoreCase("HTTP/1.0"))
{
version = HttpHeader.Version10;
}
......
......@@ -3,9 +3,9 @@ using System.Web;
namespace Titanium.Web.Proxy.Http.Responses
{
/// <summary>
/// Anything other than a 200 or 302 response
/// </summary>
/// <summary>
/// Anything other than a 200 or 302 response
/// </summary>
public class GenericResponse : Response
{
/// <summary>
......
......@@ -8,7 +8,7 @@ namespace Titanium.Web.Proxy.Http.Responses
public sealed class RedirectResponse : Response
{
/// <summary>
/// Constructor.
/// Initializes a new instance of the <see cref="RedirectResponse" /> class.
/// </summary>
public RedirectResponse()
{
......
......@@ -57,9 +57,9 @@ namespace Titanium.Web.Proxy.Network
private X509Certificate2 rootCertificate;
private string rootCertificateName;
/// <summary>
/// Initializes a new instance of the <see cref="CertificateManager"/> class.
/// </summary>
/// <param name="rootCertificateName"></param>
/// <param name="rootCertificateIssuerName"></param>
......@@ -241,8 +241,7 @@ namespace Titanium.Web.Proxy.Network
public void Dispose()
{
}
private string GetRootCertificateDirectory()
{
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
......@@ -254,7 +253,7 @@ namespace Titanium.Web.Proxy.Network
}
string path = Path.GetDirectoryName(assemblyLocation);
if (null == path)
if (path == null)
{
throw new NullReferenceException();
}
......@@ -322,7 +321,6 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// <param name="storeName"></param>
/// <param name="storeLocation"></param>
/// <returns></returns>
private void InstallCertificate(StoreName storeName, StoreLocation storeLocation)
{
if (RootCertificate == null)
......@@ -359,7 +357,6 @@ namespace Titanium.Web.Proxy.Network
/// <param name="storeName"></param>
/// <param name="storeLocation"></param>
/// <param name="certificate"></param>
/// <returns></returns>
private void UninstallCertificate(StoreName storeName, StoreLocation storeLocation,
X509Certificate2 certificate)
{
......@@ -447,9 +444,9 @@ namespace Titanium.Web.Proxy.Network
{
certificate = new X509Certificate2(certificatePath, string.Empty, StorageFlag);
}
// if load failed create again
catch
{
// if load failed create again
certificate = MakeCertificate(certificateName, false);
}
}
......@@ -532,8 +529,7 @@ namespace Titanium.Web.Proxy.Network
await Task.Delay(1000 * 60);
}
}
/// <summary>
/// Stops the certificate cache clear process
/// </summary>
......@@ -779,8 +775,7 @@ namespace Titanium.Web.Proxy.Network
EnsureRootCertificate();
}
/// <summary>
/// Determines whether the root certificate is trusted.
/// </summary>
......@@ -866,6 +861,7 @@ namespace Titanium.Web.Proxy.Network
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden
},
// currentUser\Personal & currentMachine\Personal
new ProcessStartInfo
{
......
......@@ -65,8 +65,6 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
// methods
private void Decode(byte[] message)
{
//base.Decode (message);
if (message == null)
{
throw new ArgumentNullException(nameof(message));
......
......@@ -18,8 +18,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
/// Keep track of auth states for reuse in final challenge response
/// </summary>
private static readonly IDictionary<Guid, State> authStates = new ConcurrentDictionary<Guid, State>();
/// <summary>
/// Acquire the intial client token to send
/// </summary>
......@@ -68,8 +67,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
out clientToken,
out NewContextAttributes,
out NewLifeTime);
if (result != IntermediateResult)
{
return null;
......@@ -122,8 +120,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
out clientToken,
out NewContextAttributes,
out NewLifeTime);
if (result != SuccessfulResult)
{
return null;
......@@ -173,18 +170,16 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
if (expectedAuthState == State.WinAuthState.UNAUTHORIZED)
{
return stateExists == false ||
return !stateExists ||
state.AuthState == State.WinAuthState.UNAUTHORIZED ||
state.AuthState ==
State.WinAuthState.AUTHORIZED; // Server may require re-authentication on an open connection
state.AuthState == State.WinAuthState.AUTHORIZED; // Server may require re-authentication on an open connection
}
if (expectedAuthState == State.WinAuthState.INITIAL_TOKEN)
{
return stateExists &&
(state.AuthState == State.WinAuthState.INITIAL_TOKEN ||
state.AuthState == State.WinAuthState.AUTHORIZED
); // Server may require re-authentication on an open connection
state.AuthState == State.WinAuthState.AUTHORIZED); // Server may require re-authentication on an open connection
}
throw new Exception("Unsupported validation of WinAuthState");
......
......@@ -23,8 +23,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth
var tokenBytes = WinAuthEndPoint.AcquireInitialSecurityToken(serverHostname, authScheme, requestId);
return string.Concat(" ", Convert.ToBase64String(tokenBytes));
}
/// <summary>
/// Get the final token given the server challenge token
/// </summary>
......
......@@ -9,6 +9,7 @@ using System.Threading;
using System.Threading.Tasks;
using StreamExtended.Network;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Helpers.WinHttp;
using Titanium.Web.Proxy.Models;
......@@ -25,7 +26,7 @@ namespace Titanium.Web.Proxy
public partial class ProxyServer : IDisposable
{
/// <summary>
/// HTTP & HTTPS scheme shorthands.
/// HTTP &amp; HTTPS scheme shorthands.
/// </summary>
internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp;
......@@ -170,8 +171,7 @@ namespace Titanium.Web.Proxy
/// Realm used during Proxy Basic Authentication.
/// </summary>
public string ProxyRealm { get; set; } = "TitaniumProxy";
/// <summary>
/// List of supported Ssl versions.
/// </summary>
......@@ -181,7 +181,6 @@ namespace Titanium.Web.Proxy
#endif
SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
/// <summary>
/// Manages certificates used by this proxy.
/// </summary>
......@@ -483,7 +482,7 @@ namespace Titanium.Web.Proxy
foreach (var proxy in proxyInfo.Proxies.Values)
{
if ((proxy.HostName == "127.0.0.1"
|| proxy.HostName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
|| proxy.HostName.EqualsIgnoreCase("localhost"))
&& ProxyEndPoints.Any(x => x.Port == proxy.Port))
{
protocolToRemove |= proxy.ProtocolType;
......
......@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Handle the request
/// </summary>
partial class ProxyServer
public partial class ProxyServer
{
private static readonly Regex uriSchemeRegex =
new Regex("^[a-z]*://", RegexOptions.IgnoreCase | RegexOptions.Compiled);
......@@ -40,8 +40,6 @@ namespace Titanium.Web.Proxy
/// explicit endpoint.
/// </param>
/// <param name="connectRequest">The Connect request if this is a HTTPS request from explicit endpoint.</param>
/// <param name="isTransparentEndPoint">Is this a request from transparent endpoint?</param>
/// <returns></returns>
private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection,
CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter,
CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest)
......@@ -171,10 +169,9 @@ namespace Titanium.Web.Proxy
// create a new connection if hostname/upstream end point changes
if (serverConnection != null
&& (!serverConnection.HostName.Equals(request.RequestUri.Host,
StringComparison.OrdinalIgnoreCase)
|| args.WebSession.UpStreamEndPoint != null
&& !args.WebSession.UpStreamEndPoint.Equals(serverConnection.UpStreamEndPoint)))
&& (!serverConnection.HostName.EqualsIgnoreCase(request.RequestUri.Host)
|| args.WebSession.UpStreamEndPoint?.Equals(serverConnection.UpStreamEndPoint) ==
false))
{
serverConnection.Dispose();
serverConnection = null;
......
......@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Handle the response from server.
/// </summary>
partial class ProxyServer
public partial class ProxyServer
{
/// <summary>
/// Called asynchronously when a request was successfully and we received the response.
......@@ -23,6 +23,7 @@ namespace Titanium.Web.Proxy
try
{
var cancellationToken = args.CancellationTokenSource.Token;
// read response & headers from server
await args.WebSession.ReceiveResponse(cancellationToken);
......
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="FileMustHaveHeader">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertySummaryDocumentationMustMatchAccessors">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstructorSummaryDocumentationMustBeginWithStandardText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EnumerationItemsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustContainWhitespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustShowCopyright">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParametersMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="PrefixLocalCallsWithThis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterMustFollowComma">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SplitParametersMustStartOnLineAfterDeclaration">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParametersMustBeOnSameLineOrSeparateLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PrefixCallsCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="ElementMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StaticReadonlyFieldsMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstFieldNamesMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotUseHungarianNotation">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustBeginWithLowerCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeOrderedByAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StaticElementsMustAppearBeforeInstanceElements">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustAppearInTheCorrectOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstantsMustAppearBeforeFields">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>
\ No newline at end of file
......@@ -17,7 +17,7 @@ using Titanium.Web.Proxy.Network.Tcp;
namespace Titanium.Web.Proxy
{
partial class ProxyServer
public partial class ProxyServer
{
/// <summary>
/// This is called when this proxy acts as a reverse proxy (like a real http server).
......@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy
}
}
//var serverHelloInfo = await SslTools.PeekServerHello(serverStream);
////var serverHelloInfo = await SslTools.PeekServerHello(serverStream);
await TcpHelper.SendRaw(clientStream, serverStream, BufferSize,
null, null, cancellationTokenSource, ExceptionFunc);
......
......@@ -124,9 +124,10 @@ namespace Titanium.Web.Proxy
request.ContentLength = 0;
}
}
// challenge value will start with any of the scheme selected
else
{
// challenge value will start with any of the scheme selected
scheme = authSchemes.First(x =>
authHeader.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase) &&
authHeader.Value.Length > x.Length + 1);
......
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