diff --git a/README.md b/README.md index 4c252d3ca..ed2037a81 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ## Titanium Web Proxy +### Note: This Project is no longer maintained. Any pull requests for fixes are welcome. + A lightweight HTTP(S) proxy server written in C#. ![Build Status](https://ci.appveyor.com/api/projects/status/p5vvtbpx9yp250ol?svg=true) [![Join the chat at https://gitter.im/Titanium-Web-Proxy/Lobby](https://badges.gitter.im/Titanium-Web-Proxy/Lobby.svg)](https://gitter.im/Titanium-Web-Proxy/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/docs/api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html b/docs/api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html index d933bae8d..b7891fdb3 100644 --- a/docs/api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html +++ b/docs/api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html @@ -136,7 +136,7 @@

Properties

AcceptableIssuers

-

Acceptable issuers as listed by remoted server.

+

Acceptable issuers as listed by remote server.

Declaration
diff --git a/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html b/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html index 0affc9e96..346c3549d 100644 --- a/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html +++ b/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html @@ -103,13 +103,13 @@
Implements
Inherited Members
- SessionEventArgsBase.bufferSize + SessionEventArgsBase.BufferSize
- SessionEventArgsBase.bufferPool + SessionEventArgsBase.BufferPool
- SessionEventArgsBase.exceptionFunc + SessionEventArgsBase.ExceptionFunc
SessionEventArgsBase.TimeLine @@ -188,7 +188,7 @@

Constructors Improve this Doc - View Source + View Source

SessionEventArgs(ProxyServer, ProxyEndPoint, Request, CancellationTokenSource)

@@ -232,12 +232,43 @@
Parameters

Properties

+ + | + Improve this Doc + + + View Source + + +

IsPromise

+

Is this session a HTTP/2 promise?

+
+
+
Declaration
+
+
public bool IsPromise { get; }
+
+
Property Value
+ + + + + + + + + + + + + +
TypeDescription
Boolean
| Improve this Doc - View Source + View Source

ReRequest

@@ -270,7 +301,7 @@

Methods Improve this Doc - View Source + View Source

Dispose()

@@ -288,7 +319,7 @@
Overrides
Improve this Doc - View Source + View Source

GenericResponse(Byte[], HttpStatusCode, Dictionary<String, HttpHeader>, Boolean)

@@ -341,7 +372,7 @@
Parameters
Improve this Doc - View Source + View Source

GenericResponse(String, HttpStatusCode, Dictionary<String, HttpHeader>, Boolean)

@@ -395,7 +426,7 @@
Parameters
Improve this Doc - View Source + View Source

GetRequestBody(CancellationToken)

@@ -445,7 +476,7 @@
Returns
Improve this Doc - View Source + View Source

GetRequestBodyAsString(CancellationToken)

@@ -495,7 +526,7 @@
Returns
Improve this Doc - View Source + View Source

GetResponseBody(CancellationToken)

@@ -545,7 +576,7 @@
Returns
Improve this Doc - View Source + View Source

GetResponseBodyAsString(CancellationToken)

@@ -595,7 +626,7 @@
Returns
Improve this Doc - View Source + View Source

Ok(Byte[], Dictionary<String, HttpHeader>, Boolean)

@@ -642,7 +673,7 @@
Parameters
Improve this Doc - View Source + View Source

Ok(String, Dictionary<String, HttpHeader>, Boolean)

@@ -689,7 +720,7 @@
Parameters
Improve this Doc - View Source + View Source

Redirect(String, Boolean)

@@ -729,7 +760,7 @@
Parameters
Improve this Doc - View Source + View Source

Respond(Response, Boolean)

@@ -769,7 +800,7 @@
Parameters
Improve this Doc - View Source + View Source

SetRequestBody(Byte[])

@@ -803,7 +834,7 @@
Parameters
Improve this Doc - View Source + View Source

SetRequestBodyString(String)

@@ -837,7 +868,7 @@
Parameters
Improve this Doc - View Source + View Source

SetResponseBody(Byte[])

@@ -871,7 +902,7 @@
Parameters
Improve this Doc - View Source + View Source

SetResponseBodyString(String)

@@ -905,7 +936,7 @@
Parameters
Improve this Doc - View Source + View Source

TerminateServerConnection()

@@ -923,7 +954,7 @@

Events Improve this Doc - View Source + View Source

MultipartRequestPartSent

Occurs when multipart request part sent.

diff --git a/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html b/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html index 348c180bf..0fb1f2ed9 100644 --- a/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html +++ b/docs/api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html @@ -187,17 +187,17 @@

Fields

| - Improve this Doc + Improve this Doc View Source -

bufferPool

+

BufferPool

Declaration
-
protected readonly IBufferPool bufferPool
+
protected readonly IBufferPool BufferPool
Field Value
@@ -209,24 +209,24 @@
Field Value
- +
StreamExtended.IBufferPoolIBufferPool
| - Improve this Doc + Improve this Doc View Source -

bufferSize

+

BufferSize

Declaration
-
protected readonly int bufferSize
+
protected readonly int BufferSize
Field Value
@@ -245,17 +245,17 @@
Field Value
| - Improve this Doc + Improve this Doc View Source -

exceptionFunc

+

ExceptionFunc

Declaration
-
protected readonly ExceptionHandler exceptionFunc
+
protected readonly ExceptionHandler ExceptionFunc
Field Value
@@ -279,7 +279,7 @@

Properties Improve this Doc - View Source + View Source

ClientEndPoint

@@ -310,7 +310,7 @@
Property Value
Improve this Doc - View Source + View Source

CustomUpStreamProxyUsed

@@ -341,7 +341,7 @@
Property Value
Improve this Doc - View Source + View Source

Exception

@@ -372,7 +372,7 @@
Property Value
Improve this Doc - View Source + View Source

HttpClient

@@ -403,7 +403,7 @@
Property Value
Improve this Doc - View Source + View Source

IsHttps

@@ -434,7 +434,7 @@
Property Value
Improve this Doc - View Source + View Source

IsTransparent

@@ -465,7 +465,7 @@
Property Value
Improve this Doc - View Source + View Source

LocalEndPoint

@@ -505,7 +505,7 @@

Declaration
-
public Dictionary<string, DateTime> TimeLine { get; set; }
+
public Dictionary<string, DateTime> TimeLine { get; }
Property Value
@@ -527,7 +527,7 @@
Property Value
Improve this Doc - View Source + View Source

UserData

@@ -559,7 +559,7 @@
Property Value
Improve this Doc - View Source + View Source

WebSession

@@ -592,7 +592,7 @@

Methods Improve this Doc - View Source + View Source

Dispose()

@@ -608,7 +608,7 @@
Declaration
Improve this Doc - View Source + View Source

TerminateSession()

@@ -626,7 +626,7 @@

Events Improve this Doc - View Source + View Source

DataReceived

Fired when data is received within this session from client/server.

@@ -646,7 +646,7 @@
Event Type
- + @@ -656,7 +656,7 @@
Event Type
Improve this Doc - View Source + View Source

DataSent

Fired when data is sent within this session to server/client.

@@ -676,7 +676,7 @@
Event Type
- + diff --git a/docs/api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html b/docs/api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html index 6ca5f3be1..57d74bdf5 100644 --- a/docs/api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html +++ b/docs/api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html @@ -100,13 +100,13 @@
Implements
Inherited Members
SessionEventArgsBase.TimeLine @@ -255,7 +255,7 @@
Property Value

IsHttpsConnect

-

Is this a connect request to secure HTTP server? Or is it to someother protocol.

+

Is this a connect request to secure HTTP server? Or is it to some other protocol.

Declaration
diff --git a/docs/api/Titanium.Web.Proxy.Exceptions.ProxyException.html b/docs/api/Titanium.Web.Proxy.Exceptions.ProxyException.html index dd82a921f..dfb8a7fbf 100644 --- a/docs/api/Titanium.Web.Proxy.Exceptions.ProxyException.html +++ b/docs/api/Titanium.Web.Proxy.Exceptions.ProxyException.html @@ -236,7 +236,7 @@
Parameters
- diff --git a/docs/api/Titanium.Web.Proxy.Http.ConnectRequest.html b/docs/api/Titanium.Web.Proxy.Http.ConnectRequest.html index 5cb8d182a..d4f26e346 100644 --- a/docs/api/Titanium.Web.Proxy.Http.ConnectRequest.html +++ b/docs/api/Titanium.Web.Proxy.Http.ConnectRequest.html @@ -107,6 +107,9 @@
Inherited Members
Request.OriginalUrl
+
+ Request.RequestUriString +
Request.HasBody
@@ -222,7 +225,7 @@

Properties Improve this Doc - View Source + View Source

ClientHelloInfo

@@ -242,7 +245,37 @@
Property Value
- + + + + +
EventHandler<StreamExtended.Network.DataEventArgs>EventHandler<DataEventArgs>
EventHandler<StreamExtended.Network.DataEventArgs>EventHandler<DataEventArgs>
String message

Excception message

+

Exception message

StreamExtended.ClientHelloInfoClientHelloInfo
+ + | + Improve this Doc + + + View Source + + +

TunnelType

+
+
+
Declaration
+
+
public TunnelType TunnelType { get; }
+
+
Property Value
+ + + + + + + + + + diff --git a/docs/api/Titanium.Web.Proxy.Http.ConnectResponse.html b/docs/api/Titanium.Web.Proxy.Http.ConnectResponse.html index 3d084a572..1e433a258 100644 --- a/docs/api/Titanium.Web.Proxy.Http.ConnectResponse.html +++ b/docs/api/Titanium.Web.Proxy.Http.ConnectResponse.html @@ -201,7 +201,7 @@
Property Value
- + diff --git a/docs/api/Titanium.Web.Proxy.Http.HeaderCollection.html b/docs/api/Titanium.Web.Proxy.Http.HeaderCollection.html index 17d286072..1b6582381 100644 --- a/docs/api/Titanium.Web.Proxy.Http.HeaderCollection.html +++ b/docs/api/Titanium.Web.Proxy.Http.HeaderCollection.html @@ -517,7 +517,7 @@
Returns

GetHeaders(String)

Returns all headers with given name if exists -Returns null if does'nt exist

+Returns null if doesn't exist

Declaration
diff --git a/docs/api/Titanium.Web.Proxy.Http.KnownHeaders.html b/docs/api/Titanium.Web.Proxy.Http.KnownHeaders.html index 84655e4d9..9629efa2d 100644 --- a/docs/api/Titanium.Web.Proxy.Http.KnownHeaders.html +++ b/docs/api/Titanium.Web.Proxy.Http.KnownHeaders.html @@ -135,7 +135,7 @@

Declaration
-
public const string AcceptEncoding = "accept-encoding"
+
public const string AcceptEncoding = "Accept-Encoding"
Field Value
TypeDescription
TunnelType
StreamExtended.ServerHelloInfoServerHelloInfo
@@ -193,7 +193,7 @@

Declaration
-
public const string Connection = "connection"
+
public const string Connection = "Connection"
Field Value
@@ -280,7 +280,7 @@

Declaration
-
public const string ContentEncoding = "content-encoding"
+
public const string ContentEncoding = "Content-Encoding"
Field Value
@@ -396,7 +396,7 @@

Declaration
-
public const string ContentLength = "content-length"
+
public const string ContentLength = "Content-Length"
Field Value
@@ -425,7 +425,7 @@

Declaration
-
public const string ContentType = "content-type"
+
public const string ContentType = "Content-Type"
Field Value
@@ -512,7 +512,7 @@

Declaration
-
public const string Expect = "expect"
+
public const string Expect = "Expect"
Field Value
@@ -570,7 +570,7 @@

Declaration
-
public const string Host = "host"
+
public const string Host = "Host"
Field Value
@@ -773,7 +773,7 @@

Declaration
-
public const string TransferEncoding = "transfer-encoding"
+
public const string TransferEncoding = "Transfer-Encoding"
Field Value
@@ -831,7 +831,7 @@

Declaration
-
public const string Upgrade = "upgrade"
+
public const string Upgrade = "Upgrade"
Field Value
diff --git a/docs/api/Titanium.Web.Proxy.Http.Request.html b/docs/api/Titanium.Web.Proxy.Http.Request.html index 6413812fc..dc10305c4 100644 --- a/docs/api/Titanium.Web.Proxy.Http.Request.html +++ b/docs/api/Titanium.Web.Proxy.Http.Request.html @@ -167,7 +167,7 @@

Properties Improve this Doc - View Source + View Source

ExpectationFailed

@@ -198,7 +198,7 @@
Property Value
Improve this Doc - View Source + View Source

ExpectationSucceeded

@@ -229,7 +229,7 @@
Property Value
Improve this Doc - View Source + View Source

ExpectContinue

@@ -260,7 +260,7 @@
Property Value
Improve this Doc - View Source + View Source

HasBody

@@ -293,7 +293,7 @@
Overrides
Improve this Doc - View Source + View Source

HeaderText

@@ -326,7 +326,7 @@
Overrides
Improve this Doc - View Source + View Source

Host

@@ -359,7 +359,7 @@
Property Value
Improve this Doc - View Source + View Source

IsHttps

@@ -390,7 +390,7 @@
Property Value
Improve this Doc - View Source + View Source

IsMultipartFormData

@@ -421,7 +421,7 @@
Property Value
Improve this Doc - View Source + View Source

Method

@@ -452,7 +452,7 @@
Property Value
Improve this Doc - View Source + View Source

OriginalUrl

@@ -461,7 +461,7 @@

Declaration
-
public string OriginalUrl { get; set; }
+
public string OriginalUrl { get; }
Property Value
@@ -483,7 +483,7 @@
Property Value
Improve this Doc - View Source + View Source

RequestUri

@@ -509,12 +509,43 @@
Property Value
+ + | + Improve this Doc + + + View Source + + +

RequestUriString

+

The request uri as it is in the HTTP header

+
+
+
Declaration
+
+
public string RequestUriString { get; set; }
+
+
Property Value
+ + + + + + + + + + + + + +
TypeDescription
String
| Improve this Doc - View Source + View Source

UpgradeToWebSocket

@@ -545,7 +576,7 @@
Property Value
Improve this Doc - View Source + View Source

Url

diff --git a/docs/api/Titanium.Web.Proxy.Http.RequestResponseBase.html b/docs/api/Titanium.Web.Proxy.Http.RequestResponseBase.html index 82bb8dd9b..d641d2aa0 100644 --- a/docs/api/Titanium.Web.Proxy.Http.RequestResponseBase.html +++ b/docs/api/Titanium.Web.Proxy.Http.RequestResponseBase.html @@ -127,7 +127,7 @@

Properties Improve this Doc - View Source + View Source

Body

@@ -159,7 +159,7 @@
Property Value
Improve this Doc - View Source + View Source

BodyInternal

@@ -190,7 +190,7 @@
Property Value
Improve this Doc - View Source + View Source

BodyString

@@ -223,7 +223,7 @@
Property Value
Improve this Doc - View Source + View Source

ContentEncoding

@@ -254,7 +254,7 @@
Property Value
Improve this Doc - View Source + View Source

ContentLength

@@ -285,7 +285,7 @@
Property Value
Improve this Doc - View Source + View Source

ContentType

@@ -316,7 +316,7 @@
Property Value
Improve this Doc - View Source + View Source

Encoding

@@ -347,7 +347,7 @@
Property Value
Improve this Doc - View Source + View Source

HasBody

@@ -378,7 +378,7 @@
Property Value
Improve this Doc - View Source + View Source

Headers

@@ -409,7 +409,7 @@
Property Value
Improve this Doc - View Source + View Source

HeaderText

@@ -440,7 +440,7 @@
Property Value
Improve this Doc - View Source + View Source

HttpVersion

@@ -471,7 +471,7 @@
Property Value
Improve this Doc - View Source + View Source

IsBodyRead

@@ -502,7 +502,7 @@
Property Value
Improve this Doc - View Source + View Source

IsChunked

@@ -533,7 +533,7 @@
Property Value
Improve this Doc - View Source + View Source

KeepBody

@@ -566,7 +566,7 @@

Methods Improve this Doc - View Source + View Source

ToString()

@@ -604,7 +604,7 @@
Overrides
Improve this Doc
  • - View Source + View Source
  • diff --git a/docs/api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html b/docs/api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html index d8e1a8a57..200933900 100644 --- a/docs/api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html +++ b/docs/api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html @@ -194,19 +194,19 @@

    Methods

    | - Improve this Doc + Improve this Doc - View Source + View Source -

    EncodeHeader(BinaryWriter, String, String, Boolean)

    +

    EncodeHeader(BinaryWriter, String, String, Boolean, HpackUtil.IndexType, Boolean)

    Encode the header field into the header block.

    Declaration
    -
    public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false)
    +
    public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false, HpackUtil.IndexType indexType = HpackUtil.IndexType.Incremental, bool useStaticName = true)
    Parameters
    @@ -240,6 +240,18 @@
    Parameters
    + + + + + + + + + + @@ -249,7 +261,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    SetMaxHeaderTableSize(BinaryWriter, Int32)

    diff --git a/docs/api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html b/docs/api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html index b392b1fbf..2333ac748 100644 --- a/docs/api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html +++ b/docs/api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html @@ -199,7 +199,7 @@

    Intercept tunnel connect request. Valid only for explicit endpoints. Set the DecryptSsl property to false if this HTTP connect request -should'nt be decrypted and instead be relayed.

    +shouldn't be decrypted and instead be relayed.

    Declaration
    diff --git a/docs/api/Titanium.Web.Proxy.Models.HttpHeader.html b/docs/api/Titanium.Web.Proxy.Models.HttpHeader.html index 4f8c6e96d..e812f35a3 100644 --- a/docs/api/Titanium.Web.Proxy.Models.HttpHeader.html +++ b/docs/api/Titanium.Web.Proxy.Models.HttpHeader.html @@ -160,6 +160,48 @@
    Parameters
    Boolean sensitive

    If set to true sensitive.

    +
    HpackUtil.IndexTypeindexType

    Index type.

    +
    BooleanuseStaticName

    Use static name.

    + + | + Improve this Doc + + + View Source + + +

    HttpHeader(String, String, Boolean)

    +
    +
    +
    Declaration
    +
    +
    protected HttpHeader(string name, string value, bool headerEntry)
    +
    +
    Parameters
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeNameDescription
    Stringname
    Stringvalue
    BooleanheaderEntry

    Fields

    @@ -201,7 +243,7 @@

    Properties Improve this Doc - View Source + View Source

    Name

    @@ -210,7 +252,7 @@

    Declaration
    -
    public string Name { get; set; }
    +
    public string Name { get; }
    Property Value
    @@ -232,7 +274,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    Size

    @@ -262,7 +304,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    Value

    @@ -295,7 +337,7 @@

    Methods Improve this Doc - View Source + View Source

    SizeOf(String, String)

    @@ -347,7 +389,7 @@
    Returns
    Improve this Doc - View Source + View Source

    ToString()

    diff --git a/docs/api/Titanium.Web.Proxy.ProxyServer.html b/docs/api/Titanium.Web.Proxy.ProxyServer.html index 7fd5fdb7e..835d27fdc 100644 --- a/docs/api/Titanium.Web.Proxy.ProxyServer.html +++ b/docs/api/Titanium.Web.Proxy.ProxyServer.html @@ -243,7 +243,7 @@

    Properties Improve this Doc - View Source + View Source

    BufferPool

    @@ -266,7 +266,7 @@
    Property Value
    - + @@ -276,7 +276,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    BufferSize

    @@ -308,7 +308,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    CertificateManager

    @@ -339,11 +339,11 @@
    Property Value
    Improve this Doc - View Source + View Source

    CheckCertificateRevocation

    -

    Should we check for certificare revocation during SSL authentication to servers +

    Should we check for certificate revocation during SSL authentication to servers Note: If enabled can reduce performance. Defaults to false.

    @@ -371,7 +371,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ClientConnectionCount

    @@ -402,7 +402,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ConnectionTimeOutSeconds

    @@ -435,7 +435,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    Enable100ContinueBehaviour

    @@ -468,7 +468,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    EnableConnectionPool

    @@ -495,12 +495,48 @@
    Property Value
    StreamExtended.IBufferPoolIBufferPool
    + + | + Improve this Doc + + + View Source + + +

    EnableHttp2

    +

    Enable disable HTTP/2 support. +Warning: HTTP/2 support is very limited

    +
      +
    • only enabled when both client and server supports it (no protocol changing in proxy)
    • +
    • cannot modify the request/response (e.g header modifications in BeforeRequest/Response events are ignored)
    • +
    +
    +
    +
    Declaration
    +
    +
    public bool EnableHttp2 { get; set; }
    +
    +
    Property Value
    + + + + + + + + + + + + + +
    TypeDescription
    Boolean
    | Improve this Doc - View Source + View Source

    EnableTcpServerConnectionPrefetch

    @@ -508,7 +544,7 @@

    @@ -571,7 +607,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ExceptionFunc

    @@ -634,7 +670,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    GetCustomUpStreamProxyFunc

    @@ -666,7 +702,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    MaxCachedConnections

    @@ -699,7 +735,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    NoDelay

    @@ -731,7 +767,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ProxyAuthenticationRealm

    @@ -762,7 +798,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ProxyAuthenticationSchemes

    @@ -794,7 +830,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ProxyBasicAuthenticateFunc

    @@ -827,7 +863,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ProxyEndPoints

    @@ -889,7 +925,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ProxySchemeAuthenticateFunc

    @@ -922,7 +958,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ReuseSocket

    @@ -954,7 +990,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ServerConnectionCount

    @@ -985,7 +1021,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    SupportedSslProtocols

    @@ -1016,7 +1052,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    TcpTimeWaitSeconds

    @@ -1048,7 +1084,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    ThreadPoolWorkerThread

    @@ -1079,7 +1115,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    UpStreamEndPoint

    @@ -1111,7 +1147,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    UpStreamHttpProxy

    @@ -1142,7 +1178,7 @@
    Property Value
    Improve this Doc - View Source + View Source

    UpStreamHttpsProxy

    @@ -1175,7 +1211,7 @@

    Methods Improve this Doc - View Source + View Source

    AddEndPoint(ProxyEndPoint)

    @@ -1209,7 +1245,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    DisableAllSystemProxies()

    @@ -1225,7 +1261,7 @@
    Declaration
    Improve this Doc - View Source + View Source

    DisableSystemHttpProxy()

    @@ -1241,7 +1277,7 @@
    Declaration
    Improve this Doc - View Source + View Source

    DisableSystemHttpsProxy()

    @@ -1257,7 +1293,7 @@
    Declaration
    Improve this Doc - View Source + View Source

    DisableSystemProxy(ProxyProtocolType)

    @@ -1290,7 +1326,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    Dispose()

    @@ -1306,12 +1342,12 @@
    Declaration
    Improve this Doc - View Source + View Source

    RemoveEndPoint(ProxyEndPoint)

    Remove a proxy end point. -Will throw error if the end point does'nt exist.

    +Will throw error if the end point doesn't exist.

    Declaration
    @@ -1341,7 +1377,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    SetAsSystemHttpProxy(ExplicitProxyEndPoint)

    @@ -1375,7 +1411,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    SetAsSystemHttpsProxy(ExplicitProxyEndPoint)

    @@ -1409,7 +1445,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    SetAsSystemProxy(ExplicitProxyEndPoint, ProxyProtocolType)

    @@ -1449,7 +1485,7 @@
    Parameters
    Improve this Doc - View Source + View Source

    Start()

    @@ -1465,7 +1501,7 @@
    Declaration
    Improve this Doc - View Source + View Source

    Stop()

    @@ -1483,7 +1519,7 @@

    Events Improve this Doc - View Source + View Source

    AfterResponse

    Intercept after response event from server.

    @@ -1513,7 +1549,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    BeforeRequest

    Intercept request event to server.

    @@ -1543,7 +1579,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    BeforeResponse

    Intercept response event from server.

    @@ -1573,7 +1609,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    ClientCertificateSelectionCallback

    Event to override client certificate selection during mutual SSL authentication.

    @@ -1603,7 +1639,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    ClientConnectionCountChanged

    Event occurs when client connection count changed.

    @@ -1633,7 +1669,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    OnClientConnectionCreate

    Customize TcpClient used for client connection upon create.

    @@ -1663,7 +1699,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    OnServerConnectionCreate

    Customize TcpClient used for server connection upon create.

    @@ -1693,7 +1729,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    ServerCertificateValidationCallback

    Event to override the default verification logic of remote SSL certificate received during authentication.

    @@ -1723,7 +1759,7 @@
    Event Type
    Improve this Doc - View Source + View Source

    ServerConnectionCountChanged

    Event occurs when server connection count changed.

    diff --git a/docs/index.json b/docs/index.json index ec4728af1..9c9dde4be 100644 --- a/docs/index.json +++ b/docs/index.json @@ -12,7 +12,7 @@ "api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html": { "href": "api/Titanium.Web.Proxy.EventArguments.CertificateSelectionEventArgs.html", "title": "Class CertificateSelectionEventArgs | Titanium Web Proxy", - "keywords": "Class CertificateSelectionEventArgs An argument passed on to user for client certificate selection during mutual SSL authentication. Inheritance Object EventArgs CertificateSelectionEventArgs Inherited Members EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class CertificateSelectionEventArgs : EventArgs Properties | Improve this Doc View Source AcceptableIssuers Acceptable issuers as listed by remoted server. Declaration public string[] AcceptableIssuers { get; } Property Value Type Description String [] | Improve this Doc View Source ClientCertificate Client Certificate we selected. Set this value to override. Declaration public X509Certificate ClientCertificate { get; set; } Property Value Type Description X509Certificate | Improve this Doc View Source LocalCertificates Local certificates in store with matching issuers requested by TargetHost website. Declaration public X509CertificateCollection LocalCertificates { get; } Property Value Type Description X509CertificateCollection | Improve this Doc View Source RemoteCertificate Certificate of the remote server. Declaration public X509Certificate RemoteCertificate { get; } Property Value Type Description X509Certificate | Improve this Doc View Source Sender The proxy server instance. Declaration public object Sender { get; } Property Value Type Description Object | Improve this Doc View Source TargetHost The remote hostname to which we are authenticating against. Declaration public string TargetHost { get; } Property Value Type Description String" + "keywords": "Class CertificateSelectionEventArgs An argument passed on to user for client certificate selection during mutual SSL authentication. Inheritance Object EventArgs CertificateSelectionEventArgs Inherited Members EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class CertificateSelectionEventArgs : EventArgs Properties | Improve this Doc View Source AcceptableIssuers Acceptable issuers as listed by remote server. Declaration public string[] AcceptableIssuers { get; } Property Value Type Description String [] | Improve this Doc View Source ClientCertificate Client Certificate we selected. Set this value to override. Declaration public X509Certificate ClientCertificate { get; set; } Property Value Type Description X509Certificate | Improve this Doc View Source LocalCertificates Local certificates in store with matching issuers requested by TargetHost website. Declaration public X509CertificateCollection LocalCertificates { get; } Property Value Type Description X509CertificateCollection | Improve this Doc View Source RemoteCertificate Certificate of the remote server. Declaration public X509Certificate RemoteCertificate { get; } Property Value Type Description X509Certificate | Improve this Doc View Source Sender The proxy server instance. Declaration public object Sender { get; } Property Value Type Description Object | Improve this Doc View Source TargetHost The remote hostname to which we are authenticating against. Declaration public string TargetHost { get; } Property Value Type Description String" }, "api/Titanium.Web.Proxy.EventArguments.CertificateValidationEventArgs.html": { "href": "api/Titanium.Web.Proxy.EventArguments.CertificateValidationEventArgs.html", @@ -32,17 +32,17 @@ "api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html": { "href": "api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html", "title": "Class SessionEventArgs | Titanium Web Proxy", - "keywords": "Class SessionEventArgs Holds info related to a single proxy session (single request/response sequence). A proxy session is bounded to a single connection from client. A proxy session ends when client terminates connection to proxy or when server terminates connection from proxy. Inheritance Object EventArgs SessionEventArgsBase SessionEventArgs Implements IDisposable Inherited Members SessionEventArgsBase.bufferSize SessionEventArgsBase.bufferPool SessionEventArgsBase.exceptionFunc SessionEventArgsBase.TimeLine SessionEventArgsBase.UserData SessionEventArgsBase.IsHttps SessionEventArgsBase.ClientEndPoint SessionEventArgsBase.HttpClient SessionEventArgsBase.WebSession SessionEventArgsBase.CustomUpStreamProxyUsed SessionEventArgsBase.LocalEndPoint SessionEventArgsBase.IsTransparent SessionEventArgsBase.Exception SessionEventArgsBase.DataSent SessionEventArgsBase.DataReceived SessionEventArgsBase.TerminateSession() EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class SessionEventArgs : SessionEventArgsBase, IDisposable Constructors | Improve this Doc View Source SessionEventArgs(ProxyServer, ProxyEndPoint, Request, CancellationTokenSource) Declaration protected SessionEventArgs(ProxyServer server, ProxyEndPoint endPoint, Request request, CancellationTokenSource cancellationTokenSource) Parameters Type Name Description ProxyServer server ProxyEndPoint endPoint Request request CancellationTokenSource cancellationTokenSource Properties | Improve this Doc View Source ReRequest Should we send the request again ? Declaration public bool ReRequest { get; set; } Property Value Type Description Boolean Methods | Improve this Doc View Source Dispose() Implement any cleanup here Declaration public override void Dispose() Overrides SessionEventArgsBase.Dispose() | Improve this Doc View Source GenericResponse(Byte[], HttpStatusCode, Dictionary, Boolean) Before request is made to server respond with the specified byte[], the specified status to client. And then ignore the request. Declaration public void GenericResponse(byte[] result, HttpStatusCode status, Dictionary headers, bool closeServerConnection = false) Parameters Type Name Description Byte [] result The bytes to sent. HttpStatusCode status The HTTP status code. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source GenericResponse(String, HttpStatusCode, Dictionary, Boolean) Before request is made to server respond with the specified HTML string and the specified status to client. And then ignore the request. Declaration public void GenericResponse(string html, HttpStatusCode status, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description String html The html content. HttpStatusCode status The HTTP status code. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source GetRequestBody(CancellationToken) Gets the request body as bytes. Declaration public Task GetRequestBody(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < Byte []> The body as bytes. | Improve this Doc View Source GetRequestBodyAsString(CancellationToken) Gets the request body as string. Declaration public Task GetRequestBodyAsString(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < String > The body as string. | Improve this Doc View Source GetResponseBody(CancellationToken) Gets the response body as bytes. Declaration public Task GetResponseBody(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < Byte []> The resulting bytes. | Improve this Doc View Source GetResponseBodyAsString(CancellationToken) Gets the response body as string. Declaration public Task GetResponseBodyAsString(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < String > The string body. | Improve this Doc View Source Ok(Byte[], Dictionary, Boolean) Before request is made to server respond with the specified byte[] to client and ignore the request. Declaration public void Ok(byte[] result, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description Byte [] result The html content bytes. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Ok(String, Dictionary, Boolean) Before request is made to server respond with the specified HTML string to client and ignore the request. Declaration public void Ok(string html, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description String html HTML content to sent. Dictionary < String , HttpHeader > headers HTTP response headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Redirect(String, Boolean) Redirect to provided URL. Declaration public void Redirect(string url, bool closeServerConnection = false) Parameters Type Name Description String url The URL to redirect. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Respond(Response, Boolean) Respond with given response object to client. Declaration public void Respond(Response response, bool closeServerConnection = false) Parameters Type Name Description Response response The response object. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source SetRequestBody(Byte[]) Sets the request body. Declaration public void SetRequestBody(byte[] body) Parameters Type Name Description Byte [] body The request body bytes. | Improve this Doc View Source SetRequestBodyString(String) Sets the body with the specified string. Declaration public void SetRequestBodyString(string body) Parameters Type Name Description String body The request body string to set. | Improve this Doc View Source SetResponseBody(Byte[]) Set the response body bytes. Declaration public void SetResponseBody(byte[] body) Parameters Type Name Description Byte [] body The body bytes to set. | Improve this Doc View Source SetResponseBodyString(String) Replace the response body with the specified string. Declaration public void SetResponseBodyString(string body) Parameters Type Name Description String body The body string to set. | Improve this Doc View Source TerminateServerConnection() Terminate the connection to server at the end of this HTTP request/response session. Declaration public void TerminateServerConnection() Events | Improve this Doc View Source MultipartRequestPartSent Occurs when multipart request part sent. Declaration public event EventHandler MultipartRequestPartSent Event Type Type Description EventHandler < MultipartRequestPartSentEventArgs > Implements System.IDisposable" + "keywords": "Class SessionEventArgs Holds info related to a single proxy session (single request/response sequence). A proxy session is bounded to a single connection from client. A proxy session ends when client terminates connection to proxy or when server terminates connection from proxy. Inheritance Object EventArgs SessionEventArgsBase SessionEventArgs Implements IDisposable Inherited Members SessionEventArgsBase.BufferSize SessionEventArgsBase.BufferPool SessionEventArgsBase.ExceptionFunc SessionEventArgsBase.TimeLine SessionEventArgsBase.UserData SessionEventArgsBase.IsHttps SessionEventArgsBase.ClientEndPoint SessionEventArgsBase.HttpClient SessionEventArgsBase.WebSession SessionEventArgsBase.CustomUpStreamProxyUsed SessionEventArgsBase.LocalEndPoint SessionEventArgsBase.IsTransparent SessionEventArgsBase.Exception SessionEventArgsBase.DataSent SessionEventArgsBase.DataReceived SessionEventArgsBase.TerminateSession() EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class SessionEventArgs : SessionEventArgsBase, IDisposable Constructors | Improve this Doc View Source SessionEventArgs(ProxyServer, ProxyEndPoint, Request, CancellationTokenSource) Declaration protected SessionEventArgs(ProxyServer server, ProxyEndPoint endPoint, Request request, CancellationTokenSource cancellationTokenSource) Parameters Type Name Description ProxyServer server ProxyEndPoint endPoint Request request CancellationTokenSource cancellationTokenSource Properties | Improve this Doc View Source IsPromise Is this session a HTTP/2 promise? Declaration public bool IsPromise { get; } Property Value Type Description Boolean | Improve this Doc View Source ReRequest Should we send the request again ? Declaration public bool ReRequest { get; set; } Property Value Type Description Boolean Methods | Improve this Doc View Source Dispose() Implement any cleanup here Declaration public override void Dispose() Overrides SessionEventArgsBase.Dispose() | Improve this Doc View Source GenericResponse(Byte[], HttpStatusCode, Dictionary, Boolean) Before request is made to server respond with the specified byte[], the specified status to client. And then ignore the request. Declaration public void GenericResponse(byte[] result, HttpStatusCode status, Dictionary headers, bool closeServerConnection = false) Parameters Type Name Description Byte [] result The bytes to sent. HttpStatusCode status The HTTP status code. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source GenericResponse(String, HttpStatusCode, Dictionary, Boolean) Before request is made to server respond with the specified HTML string and the specified status to client. And then ignore the request. Declaration public void GenericResponse(string html, HttpStatusCode status, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description String html The html content. HttpStatusCode status The HTTP status code. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source GetRequestBody(CancellationToken) Gets the request body as bytes. Declaration public Task GetRequestBody(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < Byte []> The body as bytes. | Improve this Doc View Source GetRequestBodyAsString(CancellationToken) Gets the request body as string. Declaration public Task GetRequestBodyAsString(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < String > The body as string. | Improve this Doc View Source GetResponseBody(CancellationToken) Gets the response body as bytes. Declaration public Task GetResponseBody(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < Byte []> The resulting bytes. | Improve this Doc View Source GetResponseBodyAsString(CancellationToken) Gets the response body as string. Declaration public Task GetResponseBodyAsString(CancellationToken cancellationToken = default(CancellationToken)) Parameters Type Name Description CancellationToken cancellationToken Optional cancellation token for this async task. Returns Type Description Task < String > The string body. | Improve this Doc View Source Ok(Byte[], Dictionary, Boolean) Before request is made to server respond with the specified byte[] to client and ignore the request. Declaration public void Ok(byte[] result, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description Byte [] result The html content bytes. Dictionary < String , HttpHeader > headers The HTTP headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Ok(String, Dictionary, Boolean) Before request is made to server respond with the specified HTML string to client and ignore the request. Declaration public void Ok(string html, Dictionary headers = null, bool closeServerConnection = false) Parameters Type Name Description String html HTML content to sent. Dictionary < String , HttpHeader > headers HTTP response headers. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Redirect(String, Boolean) Redirect to provided URL. Declaration public void Redirect(string url, bool closeServerConnection = false) Parameters Type Name Description String url The URL to redirect. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source Respond(Response, Boolean) Respond with given response object to client. Declaration public void Respond(Response response, bool closeServerConnection = false) Parameters Type Name Description Response response The response object. Boolean closeServerConnection Close the server connection used by request if any? | Improve this Doc View Source SetRequestBody(Byte[]) Sets the request body. Declaration public void SetRequestBody(byte[] body) Parameters Type Name Description Byte [] body The request body bytes. | Improve this Doc View Source SetRequestBodyString(String) Sets the body with the specified string. Declaration public void SetRequestBodyString(string body) Parameters Type Name Description String body The request body string to set. | Improve this Doc View Source SetResponseBody(Byte[]) Set the response body bytes. Declaration public void SetResponseBody(byte[] body) Parameters Type Name Description Byte [] body The body bytes to set. | Improve this Doc View Source SetResponseBodyString(String) Replace the response body with the specified string. Declaration public void SetResponseBodyString(string body) Parameters Type Name Description String body The body string to set. | Improve this Doc View Source TerminateServerConnection() Terminate the connection to server at the end of this HTTP request/response session. Declaration public void TerminateServerConnection() Events | Improve this Doc View Source MultipartRequestPartSent Occurs when multipart request part sent. Declaration public event EventHandler MultipartRequestPartSent Event Type Type Description EventHandler < MultipartRequestPartSentEventArgs > Implements System.IDisposable" }, "api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html": { "href": "api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html", "title": "Class SessionEventArgsBase | Titanium Web Proxy", - "keywords": "Class SessionEventArgsBase Holds info related to a single proxy session (single request/response sequence). A proxy session is bounded to a single connection from client. A proxy session ends when client terminates connection to proxy or when server terminates connection from proxy. Inheritance Object EventArgs SessionEventArgsBase SessionEventArgs TunnelConnectSessionEventArgs Implements IDisposable Inherited Members EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public abstract class SessionEventArgsBase : EventArgs, IDisposable Constructors | Improve this Doc View Source SessionEventArgsBase(ProxyServer, ProxyEndPoint, CancellationTokenSource, Request) Declaration protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, CancellationTokenSource cancellationTokenSource, Request request) Parameters Type Name Description ProxyServer server ProxyEndPoint endPoint CancellationTokenSource cancellationTokenSource Request request Fields | Improve this Doc View Source bufferPool Declaration protected readonly IBufferPool bufferPool Field Value Type Description StreamExtended.IBufferPool | Improve this Doc View Source bufferSize Declaration protected readonly int bufferSize Field Value Type Description Int32 | Improve this Doc View Source exceptionFunc Declaration protected readonly ExceptionHandler exceptionFunc Field Value Type Description ExceptionHandler Properties | Improve this Doc View Source ClientEndPoint Client End Point. Declaration public IPEndPoint ClientEndPoint { get; } Property Value Type Description IPEndPoint | Improve this Doc View Source CustomUpStreamProxyUsed Are we using a custom upstream HTTP(S) proxy? Declaration public ExternalProxy CustomUpStreamProxyUsed { get; } Property Value Type Description ExternalProxy | Improve this Doc View Source Exception The last exception that happened. Declaration public Exception Exception { get; } Property Value Type Description Exception | Improve this Doc View Source HttpClient The web client used to communicate with server for this session. Declaration public HttpWebClient HttpClient { get; } Property Value Type Description HttpWebClient | Improve this Doc View Source IsHttps Does this session uses SSL? Declaration public bool IsHttps { get; } Property Value Type Description Boolean | Improve this Doc View Source IsTransparent Is this a transparent endpoint? Declaration public bool IsTransparent { get; } Property Value Type Description Boolean | Improve this Doc View Source LocalEndPoint Local endpoint via which we make the request. Declaration public ProxyEndPoint LocalEndPoint { get; } Property Value Type Description ProxyEndPoint | Improve this Doc View Source TimeLine Relative milliseconds for various events. Declaration public Dictionary TimeLine { get; set; } Property Value Type Description Dictionary < String , DateTime > | Improve this Doc View Source UserData Returns a user data for this request/response session which is same as the user data of HttpClient. Declaration public object UserData { get; set; } Property Value Type Description Object | Improve this Doc View Source WebSession Declaration [Obsolete(\"Use HttpClient instead.\")] public HttpWebClient WebSession { get; } Property Value Type Description HttpWebClient Methods | Improve this Doc View Source Dispose() Implements cleanup here. Declaration public virtual void Dispose() | Improve this Doc View Source TerminateSession() Terminates the session abruptly by terminating client/server connections. Declaration public void TerminateSession() Events | Improve this Doc View Source DataReceived Fired when data is received within this session from client/server. Declaration public event EventHandler DataReceived Event Type Type Description EventHandler < StreamExtended.Network.DataEventArgs > | Improve this Doc View Source DataSent Fired when data is sent within this session to server/client. Declaration public event EventHandler DataSent Event Type Type Description EventHandler < StreamExtended.Network.DataEventArgs > Implements System.IDisposable" + "keywords": "Class SessionEventArgsBase Holds info related to a single proxy session (single request/response sequence). A proxy session is bounded to a single connection from client. A proxy session ends when client terminates connection to proxy or when server terminates connection from proxy. Inheritance Object EventArgs SessionEventArgsBase SessionEventArgs TunnelConnectSessionEventArgs Implements IDisposable Inherited Members EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public abstract class SessionEventArgsBase : EventArgs, IDisposable Constructors | Improve this Doc View Source SessionEventArgsBase(ProxyServer, ProxyEndPoint, CancellationTokenSource, Request) Declaration protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, CancellationTokenSource cancellationTokenSource, Request request) Parameters Type Name Description ProxyServer server ProxyEndPoint endPoint CancellationTokenSource cancellationTokenSource Request request Fields | Improve this Doc View Source BufferPool Declaration protected readonly IBufferPool BufferPool Field Value Type Description IBufferPool | Improve this Doc View Source BufferSize Declaration protected readonly int BufferSize Field Value Type Description Int32 | Improve this Doc View Source ExceptionFunc Declaration protected readonly ExceptionHandler ExceptionFunc Field Value Type Description ExceptionHandler Properties | Improve this Doc View Source ClientEndPoint Client End Point. Declaration public IPEndPoint ClientEndPoint { get; } Property Value Type Description IPEndPoint | Improve this Doc View Source CustomUpStreamProxyUsed Are we using a custom upstream HTTP(S) proxy? Declaration public ExternalProxy CustomUpStreamProxyUsed { get; } Property Value Type Description ExternalProxy | Improve this Doc View Source Exception The last exception that happened. Declaration public Exception Exception { get; } Property Value Type Description Exception | Improve this Doc View Source HttpClient The web client used to communicate with server for this session. Declaration public HttpWebClient HttpClient { get; } Property Value Type Description HttpWebClient | Improve this Doc View Source IsHttps Does this session uses SSL? Declaration public bool IsHttps { get; } Property Value Type Description Boolean | Improve this Doc View Source IsTransparent Is this a transparent endpoint? Declaration public bool IsTransparent { get; } Property Value Type Description Boolean | Improve this Doc View Source LocalEndPoint Local endpoint via which we make the request. Declaration public ProxyEndPoint LocalEndPoint { get; } Property Value Type Description ProxyEndPoint | Improve this Doc View Source TimeLine Relative milliseconds for various events. Declaration public Dictionary TimeLine { get; } Property Value Type Description Dictionary < String , DateTime > | Improve this Doc View Source UserData Returns a user data for this request/response session which is same as the user data of HttpClient. Declaration public object UserData { get; set; } Property Value Type Description Object | Improve this Doc View Source WebSession Declaration [Obsolete(\"Use HttpClient instead.\")] public HttpWebClient WebSession { get; } Property Value Type Description HttpWebClient Methods | Improve this Doc View Source Dispose() Implements cleanup here. Declaration public virtual void Dispose() | Improve this Doc View Source TerminateSession() Terminates the session abruptly by terminating client/server connections. Declaration public void TerminateSession() Events | Improve this Doc View Source DataReceived Fired when data is received within this session from client/server. Declaration public event EventHandler DataReceived Event Type Type Description EventHandler < DataEventArgs > | Improve this Doc View Source DataSent Fired when data is sent within this session to server/client. Declaration public event EventHandler DataSent Event Type Type Description EventHandler < DataEventArgs > Implements System.IDisposable" }, "api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html": { "href": "api/Titanium.Web.Proxy.EventArguments.TunnelConnectSessionEventArgs.html", "title": "Class TunnelConnectSessionEventArgs | Titanium Web Proxy", - "keywords": "Class TunnelConnectSessionEventArgs A class that wraps the state when a tunnel connect event happen for Explicit endpoints. Inheritance Object EventArgs SessionEventArgsBase TunnelConnectSessionEventArgs Implements IDisposable Inherited Members SessionEventArgsBase.bufferSize SessionEventArgsBase.bufferPool SessionEventArgsBase.exceptionFunc SessionEventArgsBase.TimeLine SessionEventArgsBase.UserData SessionEventArgsBase.IsHttps SessionEventArgsBase.ClientEndPoint SessionEventArgsBase.HttpClient SessionEventArgsBase.WebSession SessionEventArgsBase.CustomUpStreamProxyUsed SessionEventArgsBase.LocalEndPoint SessionEventArgsBase.IsTransparent SessionEventArgsBase.Exception SessionEventArgsBase.Dispose() SessionEventArgsBase.DataSent SessionEventArgsBase.DataReceived SessionEventArgsBase.TerminateSession() EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class TunnelConnectSessionEventArgs : SessionEventArgsBase, IDisposable Properties | Improve this Doc View Source DecryptSsl Should we decrypt the Ssl or relay it to server? Default is true. Declaration public bool DecryptSsl { get; set; } Property Value Type Description Boolean | Improve this Doc View Source DenyConnect When set to true it denies the connect request with a Forbidden status. Declaration public bool DenyConnect { get; set; } Property Value Type Description Boolean | Improve this Doc View Source IsHttpsConnect Is this a connect request to secure HTTP server? Or is it to someother protocol. Declaration public bool IsHttpsConnect { get; } Property Value Type Description Boolean Implements System.IDisposable" + "keywords": "Class TunnelConnectSessionEventArgs A class that wraps the state when a tunnel connect event happen for Explicit endpoints. Inheritance Object EventArgs SessionEventArgsBase TunnelConnectSessionEventArgs Implements IDisposable Inherited Members SessionEventArgsBase.BufferSize SessionEventArgsBase.BufferPool SessionEventArgsBase.ExceptionFunc SessionEventArgsBase.TimeLine SessionEventArgsBase.UserData SessionEventArgsBase.IsHttps SessionEventArgsBase.ClientEndPoint SessionEventArgsBase.HttpClient SessionEventArgsBase.WebSession SessionEventArgsBase.CustomUpStreamProxyUsed SessionEventArgsBase.LocalEndPoint SessionEventArgsBase.IsTransparent SessionEventArgsBase.Exception SessionEventArgsBase.Dispose() SessionEventArgsBase.DataSent SessionEventArgsBase.DataReceived SessionEventArgsBase.TerminateSession() EventArgs.Empty Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.EventArguments Assembly : Titanium.Web.Proxy.dll Syntax public class TunnelConnectSessionEventArgs : SessionEventArgsBase, IDisposable Properties | Improve this Doc View Source DecryptSsl Should we decrypt the Ssl or relay it to server? Default is true. Declaration public bool DecryptSsl { get; set; } Property Value Type Description Boolean | Improve this Doc View Source DenyConnect When set to true it denies the connect request with a Forbidden status. Declaration public bool DenyConnect { get; set; } Property Value Type Description Boolean | Improve this Doc View Source IsHttpsConnect Is this a connect request to secure HTTP server? Or is it to some other protocol. Declaration public bool IsHttpsConnect { get; } Property Value Type Description Boolean Implements System.IDisposable" }, "api/Titanium.Web.Proxy.ExceptionHandler.html": { "href": "api/Titanium.Web.Proxy.ExceptionHandler.html", @@ -72,7 +72,7 @@ "api/Titanium.Web.Proxy.Exceptions.ProxyException.html": { "href": "api/Titanium.Web.Proxy.Exceptions.ProxyException.html", "title": "Class ProxyException | Titanium Web Proxy", - "keywords": "Class ProxyException Base class exception associated with this proxy server. Inheritance Object Exception ProxyException BodyNotFoundException ProxyAuthorizationException ProxyConnectException ProxyHttpException ServerConnectionException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public abstract class ProxyException : Exception, ISerializable, _Exception Constructors | Improve this Doc View Source ProxyException(String) Initializes a new instance of the ProxyException class. must be invoked by derived classes' constructors Declaration protected ProxyException(string message) Parameters Type Name Description String message Exception message | Improve this Doc View Source ProxyException(String, Exception) Initializes a new instance of the ProxyException class. must be invoked by derived classes' constructors Declaration protected ProxyException(string message, Exception innerException) Parameters Type Name Description String message Excception message Exception innerException Inner exception associated Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception" + "keywords": "Class ProxyException Base class exception associated with this proxy server. Inheritance Object Exception ProxyException BodyNotFoundException ProxyAuthorizationException ProxyConnectException ProxyHttpException ServerConnectionException Implements ISerializable _Exception Inherited Members Exception.GetBaseException() Exception.ToString() Exception.GetObjectData(SerializationInfo, StreamingContext) Exception.GetType() Exception.Message Exception.Data Exception.InnerException Exception.TargetSite Exception.StackTrace Exception.HelpLink Exception.Source Exception.HResult Exception.SerializeObjectState Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Exceptions Assembly : Titanium.Web.Proxy.dll Syntax public abstract class ProxyException : Exception, ISerializable, _Exception Constructors | Improve this Doc View Source ProxyException(String) Initializes a new instance of the ProxyException class. must be invoked by derived classes' constructors Declaration protected ProxyException(string message) Parameters Type Name Description String message Exception message | Improve this Doc View Source ProxyException(String, Exception) Initializes a new instance of the ProxyException class. must be invoked by derived classes' constructors Declaration protected ProxyException(string message, Exception innerException) Parameters Type Name Description String message Exception message Exception innerException Inner exception associated Implements System.Runtime.Serialization.ISerializable System.Runtime.InteropServices._Exception" }, "api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html": { "href": "api/Titanium.Web.Proxy.Exceptions.ProxyHttpException.html", @@ -102,17 +102,17 @@ "api/Titanium.Web.Proxy.Http.ConnectRequest.html": { "href": "api/Titanium.Web.Proxy.Http.ConnectRequest.html", "title": "Class ConnectRequest | Titanium Web Proxy", - "keywords": "Class ConnectRequest The tcp tunnel Connect request. Inheritance Object RequestResponseBase Request ConnectRequest Inherited Members Request.Method Request.RequestUri Request.IsHttps Request.OriginalUrl Request.HasBody Request.Host Request.ExpectContinue Request.IsMultipartFormData Request.Url Request.UpgradeToWebSocket Request.ExpectationSucceeded Request.ExpectationFailed Request.HeaderText RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public class ConnectRequest : Request Constructors | Improve this Doc View Source ConnectRequest() Declaration public ConnectRequest() Properties | Improve this Doc View Source ClientHelloInfo Declaration public ClientHelloInfo ClientHelloInfo { get; set; } Property Value Type Description StreamExtended.ClientHelloInfo" + "keywords": "Class ConnectRequest The tcp tunnel Connect request. Inheritance Object RequestResponseBase Request ConnectRequest Inherited Members Request.Method Request.RequestUri Request.IsHttps Request.OriginalUrl Request.RequestUriString Request.HasBody Request.Host Request.ExpectContinue Request.IsMultipartFormData Request.Url Request.UpgradeToWebSocket Request.ExpectationSucceeded Request.ExpectationFailed Request.HeaderText RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public class ConnectRequest : Request Constructors | Improve this Doc View Source ConnectRequest() Declaration public ConnectRequest() Properties | Improve this Doc View Source ClientHelloInfo Declaration public ClientHelloInfo ClientHelloInfo { get; set; } Property Value Type Description ClientHelloInfo | Improve this Doc View Source TunnelType Declaration public TunnelType TunnelType { get; } Property Value Type Description TunnelType" }, "api/Titanium.Web.Proxy.Http.ConnectResponse.html": { "href": "api/Titanium.Web.Proxy.Http.ConnectResponse.html", "title": "Class ConnectResponse | Titanium Web Proxy", - "keywords": "Class ConnectResponse The tcp tunnel connect response object. Inheritance Object RequestResponseBase Response ConnectResponse Inherited Members Response.StatusCode Response.StatusDescription Response.HasBody Response.KeepAlive Response.HeaderText RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public class ConnectResponse : Response Properties | Improve this Doc View Source ServerHelloInfo Declaration public ServerHelloInfo ServerHelloInfo { get; set; } Property Value Type Description StreamExtended.ServerHelloInfo" + "keywords": "Class ConnectResponse The tcp tunnel connect response object. Inheritance Object RequestResponseBase Response ConnectResponse Inherited Members Response.StatusCode Response.StatusDescription Response.HasBody Response.KeepAlive Response.HeaderText RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public class ConnectResponse : Response Properties | Improve this Doc View Source ServerHelloInfo Declaration public ServerHelloInfo ServerHelloInfo { get; set; } Property Value Type Description ServerHelloInfo" }, "api/Titanium.Web.Proxy.Http.HeaderCollection.html": { "href": "api/Titanium.Web.Proxy.Http.HeaderCollection.html", "title": "Class HeaderCollection | Titanium Web Proxy", - "keywords": "Class HeaderCollection The http header collection. Inheritance Object HeaderCollection Implements IEnumerable < HttpHeader > IEnumerable Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax [TypeConverter(typeof(ExpandableObjectConverter))] public class HeaderCollection : IEnumerable, IEnumerable Constructors | Improve this Doc View Source HeaderCollection() Initializes a new instance of the HeaderCollection class. Declaration public HeaderCollection() Properties | Improve this Doc View Source Headers Unique Request header collection. Declaration public ReadOnlyDictionary Headers { get; } Property Value Type Description ReadOnlyDictionary < String , HttpHeader > | Improve this Doc View Source NonUniqueHeaders Non Unique headers. Declaration public ReadOnlyDictionary> NonUniqueHeaders { get; } Property Value Type Description ReadOnlyDictionary < String , List < HttpHeader >> Methods | Improve this Doc View Source AddHeader(String, String) Add a new header with given name and value Declaration public void AddHeader(string name, string value) Parameters Type Name Description String name String value | Improve this Doc View Source AddHeader(HttpHeader) Adds the given header object to Request Declaration public void AddHeader(HttpHeader newHeader) Parameters Type Name Description HttpHeader newHeader | Improve this Doc View Source AddHeaders(IEnumerable>) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable> newHeaders) Parameters Type Name Description IEnumerable < KeyValuePair < String , String >> newHeaders | Improve this Doc View Source AddHeaders(IEnumerable>) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable> newHeaders) Parameters Type Name Description IEnumerable < KeyValuePair < String , HttpHeader >> newHeaders | Improve this Doc View Source AddHeaders(IEnumerable) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable newHeaders) Parameters Type Name Description IEnumerable < HttpHeader > newHeaders | Improve this Doc View Source Clear() Removes all the headers. Declaration public void Clear() | Improve this Doc View Source GetAllHeaders() Returns all headers Declaration public List GetAllHeaders() Returns Type Description List < HttpHeader > | Improve this Doc View Source GetEnumerator() Returns an enumerator that iterates through the collection. Declaration public IEnumerator GetEnumerator() Returns Type Description IEnumerator < HttpHeader > An enumerator that can be used to iterate through the collection. | Improve this Doc View Source GetFirstHeader(String) Declaration public HttpHeader GetFirstHeader(string name) Parameters Type Name Description String name Returns Type Description HttpHeader | Improve this Doc View Source GetHeaders(String) Returns all headers with given name if exists Returns null if does'nt exist Declaration public List GetHeaders(string name) Parameters Type Name Description String name Returns Type Description List < HttpHeader > | Improve this Doc View Source HeaderExists(String) True if header exists Declaration public bool HeaderExists(string name) Parameters Type Name Description String name Returns Type Description Boolean | Improve this Doc View Source RemoveHeader(String) removes all headers with given name Declaration public bool RemoveHeader(string headerName) Parameters Type Name Description String headerName Returns Type Description Boolean True if header was removed False if no header exists with given name | Improve this Doc View Source RemoveHeader(HttpHeader) Removes given header object if it exist Declaration public bool RemoveHeader(HttpHeader header) Parameters Type Name Description HttpHeader header Returns true if header exists and was removed Returns Type Description Boolean Explicit Interface Implementations | Improve this Doc View Source IEnumerable.GetEnumerator() Declaration IEnumerator IEnumerable.GetEnumerator() Returns Type Description IEnumerator Implements System.Collections.Generic.IEnumerable System.Collections.IEnumerable" + "keywords": "Class HeaderCollection The http header collection. Inheritance Object HeaderCollection Implements IEnumerable < HttpHeader > IEnumerable Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax [TypeConverter(typeof(ExpandableObjectConverter))] public class HeaderCollection : IEnumerable, IEnumerable Constructors | Improve this Doc View Source HeaderCollection() Initializes a new instance of the HeaderCollection class. Declaration public HeaderCollection() Properties | Improve this Doc View Source Headers Unique Request header collection. Declaration public ReadOnlyDictionary Headers { get; } Property Value Type Description ReadOnlyDictionary < String , HttpHeader > | Improve this Doc View Source NonUniqueHeaders Non Unique headers. Declaration public ReadOnlyDictionary> NonUniqueHeaders { get; } Property Value Type Description ReadOnlyDictionary < String , List < HttpHeader >> Methods | Improve this Doc View Source AddHeader(String, String) Add a new header with given name and value Declaration public void AddHeader(string name, string value) Parameters Type Name Description String name String value | Improve this Doc View Source AddHeader(HttpHeader) Adds the given header object to Request Declaration public void AddHeader(HttpHeader newHeader) Parameters Type Name Description HttpHeader newHeader | Improve this Doc View Source AddHeaders(IEnumerable>) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable> newHeaders) Parameters Type Name Description IEnumerable < KeyValuePair < String , String >> newHeaders | Improve this Doc View Source AddHeaders(IEnumerable>) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable> newHeaders) Parameters Type Name Description IEnumerable < KeyValuePair < String , HttpHeader >> newHeaders | Improve this Doc View Source AddHeaders(IEnumerable) Adds the given header objects to Request Declaration public void AddHeaders(IEnumerable newHeaders) Parameters Type Name Description IEnumerable < HttpHeader > newHeaders | Improve this Doc View Source Clear() Removes all the headers. Declaration public void Clear() | Improve this Doc View Source GetAllHeaders() Returns all headers Declaration public List GetAllHeaders() Returns Type Description List < HttpHeader > | Improve this Doc View Source GetEnumerator() Returns an enumerator that iterates through the collection. Declaration public IEnumerator GetEnumerator() Returns Type Description IEnumerator < HttpHeader > An enumerator that can be used to iterate through the collection. | Improve this Doc View Source GetFirstHeader(String) Declaration public HttpHeader GetFirstHeader(string name) Parameters Type Name Description String name Returns Type Description HttpHeader | Improve this Doc View Source GetHeaders(String) Returns all headers with given name if exists Returns null if doesn't exist Declaration public List GetHeaders(string name) Parameters Type Name Description String name Returns Type Description List < HttpHeader > | Improve this Doc View Source HeaderExists(String) True if header exists Declaration public bool HeaderExists(string name) Parameters Type Name Description String name Returns Type Description Boolean | Improve this Doc View Source RemoveHeader(String) removes all headers with given name Declaration public bool RemoveHeader(string headerName) Parameters Type Name Description String headerName Returns Type Description Boolean True if header was removed False if no header exists with given name | Improve this Doc View Source RemoveHeader(HttpHeader) Removes given header object if it exist Declaration public bool RemoveHeader(HttpHeader header) Parameters Type Name Description HttpHeader header Returns true if header exists and was removed Returns Type Description Boolean Explicit Interface Implementations | Improve this Doc View Source IEnumerable.GetEnumerator() Declaration IEnumerator IEnumerable.GetEnumerator() Returns Type Description IEnumerator Implements System.Collections.Generic.IEnumerable System.Collections.IEnumerable" }, "api/Titanium.Web.Proxy.Http.html": { "href": "api/Titanium.Web.Proxy.Http.html", @@ -127,12 +127,12 @@ "api/Titanium.Web.Proxy.Http.KnownHeaders.html": { "href": "api/Titanium.Web.Proxy.Http.KnownHeaders.html", "title": "Class KnownHeaders | Titanium Web Proxy", - "keywords": "Class KnownHeaders Well known http headers. Inheritance Object KnownHeaders Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public static class KnownHeaders Fields | Improve this Doc View Source AcceptEncoding Declaration public const string AcceptEncoding = \"accept-encoding\" Field Value Type Description String | Improve this Doc View Source Authorization Declaration public const string Authorization = \"Authorization\" Field Value Type Description String | Improve this Doc View Source Connection Declaration public const string Connection = \"connection\" Field Value Type Description String | Improve this Doc View Source ConnectionClose Declaration public const string ConnectionClose = \"close\" Field Value Type Description String | Improve this Doc View Source ConnectionKeepAlive Declaration public const string ConnectionKeepAlive = \"keep-alive\" Field Value Type Description String | Improve this Doc View Source ContentEncoding Declaration public const string ContentEncoding = \"content-encoding\" Field Value Type Description String | Improve this Doc View Source ContentEncodingBrotli Declaration public const string ContentEncodingBrotli = \"br\" Field Value Type Description String | Improve this Doc View Source ContentEncodingDeflate Declaration public const string ContentEncodingDeflate = \"deflate\" Field Value Type Description String | Improve this Doc View Source ContentEncodingGzip Declaration public const string ContentEncodingGzip = \"gzip\" Field Value Type Description String | Improve this Doc View Source ContentLength Declaration public const string ContentLength = \"content-length\" Field Value Type Description String | Improve this Doc View Source ContentType Declaration public const string ContentType = \"content-type\" Field Value Type Description String | Improve this Doc View Source ContentTypeBoundary Declaration public const string ContentTypeBoundary = \"boundary\" Field Value Type Description String | Improve this Doc View Source ContentTypeCharset Declaration public const string ContentTypeCharset = \"charset\" Field Value Type Description String | Improve this Doc View Source Expect Declaration public const string Expect = \"expect\" Field Value Type Description String | Improve this Doc View Source Expect100Continue Declaration public const string Expect100Continue = \"100-continue\" Field Value Type Description String | Improve this Doc View Source Host Declaration public const string Host = \"host\" Field Value Type Description String | Improve this Doc View Source Location Declaration public const string Location = \"Location\" Field Value Type Description String | Improve this Doc View Source ProxyAuthenticate Declaration public const string ProxyAuthenticate = \"Proxy-Authenticate\" Field Value Type Description String | Improve this Doc View Source ProxyAuthorization Declaration public const string ProxyAuthorization = \"Proxy-Authorization\" Field Value Type Description String | Improve this Doc View Source ProxyAuthorizationBasic Declaration public const string ProxyAuthorizationBasic = \"basic\" Field Value Type Description String | Improve this Doc View Source ProxyConnection Declaration public const string ProxyConnection = \"Proxy-Connection\" Field Value Type Description String | Improve this Doc View Source ProxyConnectionClose Declaration public const string ProxyConnectionClose = \"close\" Field Value Type Description String | Improve this Doc View Source TransferEncoding Declaration public const string TransferEncoding = \"transfer-encoding\" Field Value Type Description String | Improve this Doc View Source TransferEncodingChunked Declaration public const string TransferEncodingChunked = \"chunked\" Field Value Type Description String | Improve this Doc View Source Upgrade Declaration public const string Upgrade = \"upgrade\" Field Value Type Description String | Improve this Doc View Source UpgradeWebsocket Declaration public const string UpgradeWebsocket = \"websocket\" Field Value Type Description String" + "keywords": "Class KnownHeaders Well known http headers. Inheritance Object KnownHeaders Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax public static class KnownHeaders Fields | Improve this Doc View Source AcceptEncoding Declaration public const string AcceptEncoding = \"Accept-Encoding\" Field Value Type Description String | Improve this Doc View Source Authorization Declaration public const string Authorization = \"Authorization\" Field Value Type Description String | Improve this Doc View Source Connection Declaration public const string Connection = \"Connection\" Field Value Type Description String | Improve this Doc View Source ConnectionClose Declaration public const string ConnectionClose = \"close\" Field Value Type Description String | Improve this Doc View Source ConnectionKeepAlive Declaration public const string ConnectionKeepAlive = \"keep-alive\" Field Value Type Description String | Improve this Doc View Source ContentEncoding Declaration public const string ContentEncoding = \"Content-Encoding\" Field Value Type Description String | Improve this Doc View Source ContentEncodingBrotli Declaration public const string ContentEncodingBrotli = \"br\" Field Value Type Description String | Improve this Doc View Source ContentEncodingDeflate Declaration public const string ContentEncodingDeflate = \"deflate\" Field Value Type Description String | Improve this Doc View Source ContentEncodingGzip Declaration public const string ContentEncodingGzip = \"gzip\" Field Value Type Description String | Improve this Doc View Source ContentLength Declaration public const string ContentLength = \"Content-Length\" Field Value Type Description String | Improve this Doc View Source ContentType Declaration public const string ContentType = \"Content-Type\" Field Value Type Description String | Improve this Doc View Source ContentTypeBoundary Declaration public const string ContentTypeBoundary = \"boundary\" Field Value Type Description String | Improve this Doc View Source ContentTypeCharset Declaration public const string ContentTypeCharset = \"charset\" Field Value Type Description String | Improve this Doc View Source Expect Declaration public const string Expect = \"Expect\" Field Value Type Description String | Improve this Doc View Source Expect100Continue Declaration public const string Expect100Continue = \"100-continue\" Field Value Type Description String | Improve this Doc View Source Host Declaration public const string Host = \"Host\" Field Value Type Description String | Improve this Doc View Source Location Declaration public const string Location = \"Location\" Field Value Type Description String | Improve this Doc View Source ProxyAuthenticate Declaration public const string ProxyAuthenticate = \"Proxy-Authenticate\" Field Value Type Description String | Improve this Doc View Source ProxyAuthorization Declaration public const string ProxyAuthorization = \"Proxy-Authorization\" Field Value Type Description String | Improve this Doc View Source ProxyAuthorizationBasic Declaration public const string ProxyAuthorizationBasic = \"basic\" Field Value Type Description String | Improve this Doc View Source ProxyConnection Declaration public const string ProxyConnection = \"Proxy-Connection\" Field Value Type Description String | Improve this Doc View Source ProxyConnectionClose Declaration public const string ProxyConnectionClose = \"close\" Field Value Type Description String | Improve this Doc View Source TransferEncoding Declaration public const string TransferEncoding = \"Transfer-Encoding\" Field Value Type Description String | Improve this Doc View Source TransferEncodingChunked Declaration public const string TransferEncodingChunked = \"chunked\" Field Value Type Description String | Improve this Doc View Source Upgrade Declaration public const string Upgrade = \"Upgrade\" Field Value Type Description String | Improve this Doc View Source UpgradeWebsocket Declaration public const string UpgradeWebsocket = \"websocket\" Field Value Type Description String" }, "api/Titanium.Web.Proxy.Http.Request.html": { "href": "api/Titanium.Web.Proxy.Http.Request.html", "title": "Class Request | Titanium Web Proxy", - "keywords": "Class Request Http(s) request object Inheritance Object RequestResponseBase Request ConnectRequest Inherited Members RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax [TypeConverter(typeof(ExpandableObjectConverter))] public class Request : RequestResponseBase Properties | Improve this Doc View Source ExpectationFailed Did server respond negatively for 100 continue request? Declaration public bool ExpectationFailed { get; } Property Value Type Description Boolean | Improve this Doc View Source ExpectationSucceeded Did server respond positively for 100 continue request? Declaration public bool ExpectationSucceeded { get; } Property Value Type Description Boolean | Improve this Doc View Source ExpectContinue Does this request has a 100-continue header? Declaration public bool ExpectContinue { get; } Property Value Type Description Boolean | Improve this Doc View Source HasBody Has request body? Declaration public override bool HasBody { get; } Property Value Type Description Boolean Overrides RequestResponseBase.HasBody | Improve this Doc View Source HeaderText Gets the header text. Declaration public override string HeaderText { get; } Property Value Type Description String Overrides RequestResponseBase.HeaderText | Improve this Doc View Source Host Http hostname header value if exists. Note: Changing this does NOT change host in RequestUri. Users can set new RequestUri separately. Declaration public string Host { get; set; } Property Value Type Description String | Improve this Doc View Source IsHttps Is Https? Declaration public bool IsHttps { get; } Property Value Type Description Boolean | Improve this Doc View Source IsMultipartFormData Does this request contain multipart/form-data? Declaration public bool IsMultipartFormData { get; } Property Value Type Description Boolean | Improve this Doc View Source Method Request Method. Declaration public string Method { get; set; } Property Value Type Description String | Improve this Doc View Source OriginalUrl The original request Url. Declaration public string OriginalUrl { get; set; } Property Value Type Description String | Improve this Doc View Source RequestUri Request HTTP Uri. Declaration public Uri RequestUri { get; set; } Property Value Type Description Uri | Improve this Doc View Source UpgradeToWebSocket Does this request has an upgrade to websocket header? Declaration public bool UpgradeToWebSocket { get; } Property Value Type Description Boolean | Improve this Doc View Source Url Request Url. Declaration public string Url { get; } Property Value Type Description String" + "keywords": "Class Request Http(s) request object Inheritance Object RequestResponseBase Request ConnectRequest Inherited Members RequestResponseBase.BodyInternal RequestResponseBase.KeepBody RequestResponseBase.HttpVersion RequestResponseBase.Headers RequestResponseBase.ContentLength RequestResponseBase.ContentEncoding RequestResponseBase.Encoding RequestResponseBase.ContentType RequestResponseBase.IsChunked RequestResponseBase.Body RequestResponseBase.BodyString RequestResponseBase.IsBodyRead RequestResponseBase.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http Assembly : Titanium.Web.Proxy.dll Syntax [TypeConverter(typeof(ExpandableObjectConverter))] public class Request : RequestResponseBase Properties | Improve this Doc View Source ExpectationFailed Did server respond negatively for 100 continue request? Declaration public bool ExpectationFailed { get; } Property Value Type Description Boolean | Improve this Doc View Source ExpectationSucceeded Did server respond positively for 100 continue request? Declaration public bool ExpectationSucceeded { get; } Property Value Type Description Boolean | Improve this Doc View Source ExpectContinue Does this request has a 100-continue header? Declaration public bool ExpectContinue { get; } Property Value Type Description Boolean | Improve this Doc View Source HasBody Has request body? Declaration public override bool HasBody { get; } Property Value Type Description Boolean Overrides RequestResponseBase.HasBody | Improve this Doc View Source HeaderText Gets the header text. Declaration public override string HeaderText { get; } Property Value Type Description String Overrides RequestResponseBase.HeaderText | Improve this Doc View Source Host Http hostname header value if exists. Note: Changing this does NOT change host in RequestUri. Users can set new RequestUri separately. Declaration public string Host { get; set; } Property Value Type Description String | Improve this Doc View Source IsHttps Is Https? Declaration public bool IsHttps { get; } Property Value Type Description Boolean | Improve this Doc View Source IsMultipartFormData Does this request contain multipart/form-data? Declaration public bool IsMultipartFormData { get; } Property Value Type Description Boolean | Improve this Doc View Source Method Request Method. Declaration public string Method { get; set; } Property Value Type Description String | Improve this Doc View Source OriginalUrl The original request Url. Declaration public string OriginalUrl { get; } Property Value Type Description String | Improve this Doc View Source RequestUri Request HTTP Uri. Declaration public Uri RequestUri { get; set; } Property Value Type Description Uri | Improve this Doc View Source RequestUriString The request uri as it is in the HTTP header Declaration public string RequestUriString { get; set; } Property Value Type Description String | Improve this Doc View Source UpgradeToWebSocket Does this request has an upgrade to websocket header? Declaration public bool UpgradeToWebSocket { get; } Property Value Type Description Boolean | Improve this Doc View Source Url Request Url. Declaration public string Url { get; } Property Value Type Description String" }, "api/Titanium.Web.Proxy.Http.RequestResponseBase.html": { "href": "api/Titanium.Web.Proxy.Http.RequestResponseBase.html", @@ -177,7 +177,7 @@ "api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html": { "href": "api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html", "title": "Class Encoder | Titanium Web Proxy", - "keywords": "Class Encoder Inheritance Object Encoder Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http2.Hpack Assembly : Titanium.Web.Proxy.dll Syntax public class Encoder Constructors | Improve this Doc View Source Encoder(Int32) Initializes a new instance of the Encoder class. Declaration public Encoder(int maxHeaderTableSize) Parameters Type Name Description Int32 maxHeaderTableSize Max header table size. Properties | Improve this Doc View Source MaxHeaderTableSize Gets the the maximum table size. Declaration public int MaxHeaderTableSize { get; } Property Value Type Description Int32 The max header table size. Methods | Improve this Doc View Source EncodeHeader(BinaryWriter, String, String, Boolean) Encode the header field into the header block. Declaration public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false) Parameters Type Name Description BinaryWriter output Output. String name Name. String value Value. Boolean sensitive If set to true sensitive. | Improve this Doc View Source SetMaxHeaderTableSize(BinaryWriter, Int32) Set the maximum table size. Declaration public void SetMaxHeaderTableSize(BinaryWriter output, int maxHeaderTableSize) Parameters Type Name Description BinaryWriter output Output. Int32 maxHeaderTableSize Max header table size." + "keywords": "Class Encoder Inheritance Object Encoder Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Http2.Hpack Assembly : Titanium.Web.Proxy.dll Syntax public class Encoder Constructors | Improve this Doc View Source Encoder(Int32) Initializes a new instance of the Encoder class. Declaration public Encoder(int maxHeaderTableSize) Parameters Type Name Description Int32 maxHeaderTableSize Max header table size. Properties | Improve this Doc View Source MaxHeaderTableSize Gets the the maximum table size. Declaration public int MaxHeaderTableSize { get; } Property Value Type Description Int32 The max header table size. Methods | Improve this Doc View Source EncodeHeader(BinaryWriter, String, String, Boolean, HpackUtil.IndexType, Boolean) Encode the header field into the header block. Declaration public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false, HpackUtil.IndexType indexType = HpackUtil.IndexType.Incremental, bool useStaticName = true) Parameters Type Name Description BinaryWriter output Output. String name Name. String value Value. Boolean sensitive If set to true sensitive. HpackUtil.IndexType indexType Index type. Boolean useStaticName Use static name. | Improve this Doc View Source SetMaxHeaderTableSize(BinaryWriter, Int32) Set the maximum table size. Declaration public void SetMaxHeaderTableSize(BinaryWriter output, int maxHeaderTableSize) Parameters Type Name Description BinaryWriter output Output. Int32 maxHeaderTableSize Max header table size." }, "api/Titanium.Web.Proxy.Http2.Hpack.HpackUtil.html": { "href": "api/Titanium.Web.Proxy.Http2.Hpack.HpackUtil.html", @@ -217,7 +217,7 @@ "api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html": { "href": "api/Titanium.Web.Proxy.Models.ExplicitProxyEndPoint.html", "title": "Class ExplicitProxyEndPoint | Titanium Web Proxy", - "keywords": "Class ExplicitProxyEndPoint A proxy endpoint that the client is aware of. So client application know that it is communicating with a proxy server. Inheritance Object ProxyEndPoint ExplicitProxyEndPoint Inherited Members ProxyEndPoint.IpAddress ProxyEndPoint.Port ProxyEndPoint.DecryptSsl ProxyEndPoint.IpV6Enabled ProxyEndPoint.GenericCertificate Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Models Assembly : Titanium.Web.Proxy.dll Syntax public class ExplicitProxyEndPoint : ProxyEndPoint Constructors | Improve this Doc View Source ExplicitProxyEndPoint(IPAddress, Int32, Boolean) Constructor. Declaration public ExplicitProxyEndPoint(IPAddress ipAddress, int port, bool decryptSsl = true) Parameters Type Name Description IPAddress ipAddress Listening IP address. Int32 port Listening port. Boolean decryptSsl Should we decrypt ssl? Events | Improve this Doc View Source BeforeTunnelConnectRequest Intercept tunnel connect request. Valid only for explicit endpoints. Set the DecryptSsl property to false if this HTTP connect request should'nt be decrypted and instead be relayed. Declaration public event AsyncEventHandler BeforeTunnelConnectRequest Event Type Type Description AsyncEventHandler < TunnelConnectSessionEventArgs > | Improve this Doc View Source BeforeTunnelConnectResponse Intercept tunnel connect response. Valid only for explicit endpoints. Declaration public event AsyncEventHandler BeforeTunnelConnectResponse Event Type Type Description AsyncEventHandler < TunnelConnectSessionEventArgs >" + "keywords": "Class ExplicitProxyEndPoint A proxy endpoint that the client is aware of. So client application know that it is communicating with a proxy server. Inheritance Object ProxyEndPoint ExplicitProxyEndPoint Inherited Members ProxyEndPoint.IpAddress ProxyEndPoint.Port ProxyEndPoint.DecryptSsl ProxyEndPoint.IpV6Enabled ProxyEndPoint.GenericCertificate Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Models Assembly : Titanium.Web.Proxy.dll Syntax public class ExplicitProxyEndPoint : ProxyEndPoint Constructors | Improve this Doc View Source ExplicitProxyEndPoint(IPAddress, Int32, Boolean) Constructor. Declaration public ExplicitProxyEndPoint(IPAddress ipAddress, int port, bool decryptSsl = true) Parameters Type Name Description IPAddress ipAddress Listening IP address. Int32 port Listening port. Boolean decryptSsl Should we decrypt ssl? Events | Improve this Doc View Source BeforeTunnelConnectRequest Intercept tunnel connect request. Valid only for explicit endpoints. Set the DecryptSsl property to false if this HTTP connect request shouldn't be decrypted and instead be relayed. Declaration public event AsyncEventHandler BeforeTunnelConnectRequest Event Type Type Description AsyncEventHandler < TunnelConnectSessionEventArgs > | Improve this Doc View Source BeforeTunnelConnectResponse Intercept tunnel connect response. Valid only for explicit endpoints. Declaration public event AsyncEventHandler BeforeTunnelConnectResponse Event Type Type Description AsyncEventHandler < TunnelConnectSessionEventArgs >" }, "api/Titanium.Web.Proxy.Models.ExternalProxy.html": { "href": "api/Titanium.Web.Proxy.Models.ExternalProxy.html", @@ -232,7 +232,7 @@ "api/Titanium.Web.Proxy.Models.HttpHeader.html": { "href": "api/Titanium.Web.Proxy.Models.HttpHeader.html", "title": "Class HttpHeader | Titanium Web Proxy", - "keywords": "Class HttpHeader Http Header object used by proxy Inheritance Object HttpHeader Inherited Members Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Models Assembly : Titanium.Web.Proxy.dll Syntax public class HttpHeader Constructors | Improve this Doc View Source HttpHeader(String, String) Initialize a new instance. Declaration public HttpHeader(string name, string value) Parameters Type Name Description String name Header name. String value Header value. Fields | Improve this Doc View Source HttpHeaderOverhead HPACK: Header Compression for HTTP/2 Section 4.1. Calculating Table Size The additional 32 octets account for an estimated overhead associated with an entry. Declaration public const int HttpHeaderOverhead = 32 Field Value Type Description Int32 Properties | Improve this Doc View Source Name Header Name. Declaration public string Name { get; set; } Property Value Type Description String | Improve this Doc View Source Size Declaration public int Size { get; } Property Value Type Description Int32 | Improve this Doc View Source Value Header Value. Declaration public string Value { get; set; } Property Value Type Description String Methods | Improve this Doc View Source SizeOf(String, String) Declaration public static int SizeOf(string name, string value) Parameters Type Name Description String name String value Returns Type Description Int32 | Improve this Doc View Source ToString() Returns header as a valid header string. Declaration public override string ToString() Returns Type Description String Overrides Object.ToString()" + "keywords": "Class HttpHeader Http Header object used by proxy Inheritance Object HttpHeader Inherited Members Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy.Models Assembly : Titanium.Web.Proxy.dll Syntax public class HttpHeader Constructors | Improve this Doc View Source HttpHeader(String, String) Initialize a new instance. Declaration public HttpHeader(string name, string value) Parameters Type Name Description String name Header name. String value Header value. | Improve this Doc View Source HttpHeader(String, String, Boolean) Declaration protected HttpHeader(string name, string value, bool headerEntry) Parameters Type Name Description String name String value Boolean headerEntry Fields | Improve this Doc View Source HttpHeaderOverhead HPACK: Header Compression for HTTP/2 Section 4.1. Calculating Table Size The additional 32 octets account for an estimated overhead associated with an entry. Declaration public const int HttpHeaderOverhead = 32 Field Value Type Description Int32 Properties | Improve this Doc View Source Name Header Name. Declaration public string Name { get; } Property Value Type Description String | Improve this Doc View Source Size Declaration public int Size { get; } Property Value Type Description Int32 | Improve this Doc View Source Value Header Value. Declaration public string Value { get; set; } Property Value Type Description String Methods | Improve this Doc View Source SizeOf(String, String) Declaration public static int SizeOf(string name, string value) Parameters Type Name Description String name String value Returns Type Description Int32 | Improve this Doc View Source ToString() Returns header as a valid header string. Declaration public override string ToString() Returns Type Description String Overrides Object.ToString()" }, "api/Titanium.Web.Proxy.Models.ProxyAuthenticationContext.html": { "href": "api/Titanium.Web.Proxy.Models.ProxyAuthenticationContext.html", @@ -277,6 +277,6 @@ "api/Titanium.Web.Proxy.ProxyServer.html": { "href": "api/Titanium.Web.Proxy.ProxyServer.html", "title": "Class ProxyServer | Titanium Web Proxy", - "keywords": "Class ProxyServer This class is the backbone of proxy. One can create as many instances as needed. However care should be taken to avoid using the same listening ports across multiple instances. Inheritance Object ProxyServer Implements IDisposable Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyServer : IDisposable Constructors | Improve this Doc View Source ProxyServer(Boolean, Boolean, Boolean) Initializes a new instance of ProxyServer class with provided parameters. Declaration public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false) Parameters Type Name Description Boolean userTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's user certificate store? Boolean machineTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's certificate store? Boolean trustRootCertificateAsAdmin Should we attempt to trust certificates with elevated permissions by prompting for UAC if required? | Improve this Doc View Source ProxyServer(String, String, Boolean, Boolean, Boolean) Initializes a new instance of ProxyServer class with provided parameters. Declaration public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false) Parameters Type Name Description String rootCertificateName Name of the root certificate. String rootCertificateIssuerName Name of the root certificate issuer. Boolean userTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's user certificate store? Boolean machineTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's certificate store? Boolean trustRootCertificateAsAdmin Should we attempt to trust certificates with elevated permissions by prompting for UAC if required? Properties | Improve this Doc View Source BufferPool The buffer pool used throughout this proxy instance. Set custom implementations by implementing this interface. By default this uses DefaultBufferPool implementation available in StreamExtended library package. Declaration public IBufferPool BufferPool { get; set; } Property Value Type Description StreamExtended.IBufferPool | Improve this Doc View Source BufferSize Buffer size in bytes used throughout this proxy. Default value is 8192 bytes. Declaration public int BufferSize { get; set; } Property Value Type Description Int32 | Improve this Doc View Source CertificateManager Manages certificates used by this proxy. Declaration public CertificateManager CertificateManager { get; } Property Value Type Description CertificateManager | Improve this Doc View Source CheckCertificateRevocation Should we check for certificare revocation during SSL authentication to servers Note: If enabled can reduce performance. Defaults to false. Declaration public X509RevocationMode CheckCertificateRevocation { get; set; } Property Value Type Description X509RevocationMode | Improve this Doc View Source ClientConnectionCount Total number of active client connections. Declaration public int ClientConnectionCount { get; } Property Value Type Description Int32 | Improve this Doc View Source ConnectionTimeOutSeconds Seconds client/server connection are to be kept alive when waiting for read/write to complete. This will also determine the pool eviction time when connection pool is enabled. Default value is 60 seconds. Declaration public int ConnectionTimeOutSeconds { get; set; } Property Value Type Description Int32 | Improve this Doc View Source Enable100ContinueBehaviour Does this proxy uses the HTTP protocol 100 continue behaviour strictly? Broken 100 continue implementations on server/client may cause problems if enabled. Defaults to false. Declaration public bool Enable100ContinueBehaviour { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableConnectionPool Should we enable experimental server connection pool? Defaults to true. Declaration public bool EnableConnectionPool { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableTcpServerConnectionPrefetch Should we enable tcp server connection prefetching? When enabled, as soon as we receive a client connection we concurrently initiate corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request we will have the server connection immediately ready or in the process of getting ready. If a server connection is available in cache then this prefetch task will immediatly return with the available connection from cache. Defaults to true. Declaration public bool EnableTcpServerConnectionPrefetch { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableWinAuth Enable disable Windows Authentication (NTLM/Kerberos). Note: NTLM/Kerberos will always send local credentials of current user running the proxy process. This is because a man in middle attack with Windows domain authentication is not currently supported. Defaults to false. Declaration public bool EnableWinAuth { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ExceptionFunc Callback for error events in this proxy instance. Declaration public ExceptionHandler ExceptionFunc { get; set; } Property Value Type Description ExceptionHandler | Improve this Doc View Source ForwardToUpstreamGateway Gets or sets a value indicating whether requests will be chained to upstream gateway. Defaults to false. Declaration public bool ForwardToUpstreamGateway { get; set; } Property Value Type Description Boolean | Improve this Doc View Source GetCustomUpStreamProxyFunc A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests. User should return the ExternalProxy object with valid credentials. Declaration public Func> GetCustomUpStreamProxyFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , Task < ExternalProxy >> | Improve this Doc View Source MaxCachedConnections Maximum number of concurrent connections per remote host in cache. Only valid when connection pooling is enabled. Default value is 2. Declaration public int MaxCachedConnections { get; set; } Property Value Type Description Int32 | Improve this Doc View Source NoDelay Gets or sets a Boolean value that specifies whether server and client stream Sockets are using the Nagle algorithm. Defaults to true, no nagle algorithm is used. Declaration public bool NoDelay { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ProxyAuthenticationRealm Realm used during Proxy Basic Authentication. Declaration public string ProxyAuthenticationRealm { get; set; } Property Value Type Description String | Improve this Doc View Source ProxyAuthenticationSchemes A collection of scheme types, e.g. basic, NTLM, Kerberos, Negotiate, to return if scheme authentication is required. Works in relation with ProxySchemeAuthenticateFunc. Declaration public IEnumerable ProxyAuthenticationSchemes { get; set; } Property Value Type Description IEnumerable < String > | Improve this Doc View Source ProxyBasicAuthenticateFunc A callback to authenticate proxy clients via basic authentication. Parameters are username and password as provided by client. Should return true for successful authentication. Declaration public Func> ProxyBasicAuthenticateFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , String , String , Task < Boolean >> | Improve this Doc View Source ProxyEndPoints A list of IpAddress and port this proxy is listening to. Declaration public List ProxyEndPoints { get; set; } Property Value Type Description List < ProxyEndPoint > | Improve this Doc View Source ProxyRunning Is the proxy currently running? Declaration public bool ProxyRunning { get; } Property Value Type Description Boolean | Improve this Doc View Source ProxySchemeAuthenticateFunc A pluggable callback to authenticate clients by scheme instead of requiring basic authentication through ProxyBasicAuthenticateFunc. Parameters are current working session, schemeType, and token as provided by a calling client. Should return success for successful authentication, continuation if the package requests, or failure. Declaration public Func> ProxySchemeAuthenticateFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , String , String , Task < ProxyAuthenticationContext >> | Improve this Doc View Source ReuseSocket Should we reuse client/server tcp sockets. Default is true (disabled for linux/macOS due to bug in .Net core). Declaration public bool ReuseSocket { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ServerConnectionCount Total number of active server connections. Declaration public int ServerConnectionCount { get; } Property Value Type Description Int32 | Improve this Doc View Source SupportedSslProtocols List of supported Ssl versions. Declaration public SslProtocols SupportedSslProtocols { get; set; } Property Value Type Description SslProtocols | Improve this Doc View Source TcpTimeWaitSeconds Number of seconds to linger when Tcp connection is in TIME_WAIT state. Default value is 30. Declaration public int TcpTimeWaitSeconds { get; set; } Property Value Type Description Int32 | Improve this Doc View Source ThreadPoolWorkerThread Customize the minimum ThreadPool size (increase it on a server) Declaration public int ThreadPoolWorkerThread { get; set; } Property Value Type Description Int32 | Improve this Doc View Source UpStreamEndPoint Local adapter/NIC endpoint where proxy makes request via. Defaults via any IP addresses of this machine. Declaration public IPEndPoint UpStreamEndPoint { get; set; } Property Value Type Description IPEndPoint | Improve this Doc View Source UpStreamHttpProxy External proxy used for Http requests. Declaration public ExternalProxy UpStreamHttpProxy { get; set; } Property Value Type Description ExternalProxy | Improve this Doc View Source UpStreamHttpsProxy External proxy used for Https requests. Declaration public ExternalProxy UpStreamHttpsProxy { get; set; } Property Value Type Description ExternalProxy Methods | Improve this Doc View Source AddEndPoint(ProxyEndPoint) Add a proxy end point. Declaration public void AddEndPoint(ProxyEndPoint endPoint) Parameters Type Name Description ProxyEndPoint endPoint The proxy endpoint. | Improve this Doc View Source DisableAllSystemProxies() Clear all proxy settings for current machine. Declaration public void DisableAllSystemProxies() | Improve this Doc View Source DisableSystemHttpProxy() Clear HTTP proxy settings of current machine. Declaration public void DisableSystemHttpProxy() | Improve this Doc View Source DisableSystemHttpsProxy() Clear HTTPS proxy settings of current machine. Declaration public void DisableSystemHttpsProxy() | Improve this Doc View Source DisableSystemProxy(ProxyProtocolType) Clear the specified proxy setting for current machine. Declaration public void DisableSystemProxy(ProxyProtocolType protocolType) Parameters Type Name Description ProxyProtocolType protocolType | Improve this Doc View Source Dispose() Dispose the Proxy instance. Declaration public void Dispose() | Improve this Doc View Source RemoveEndPoint(ProxyEndPoint) Remove a proxy end point. Will throw error if the end point does'nt exist. Declaration public void RemoveEndPoint(ProxyEndPoint endPoint) Parameters Type Name Description ProxyEndPoint endPoint The existing endpoint to remove. | Improve this Doc View Source SetAsSystemHttpProxy(ExplicitProxyEndPoint) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. | Improve this Doc View Source SetAsSystemHttpsProxy(ExplicitProxyEndPoint) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. | Improve this Doc View Source SetAsSystemProxy(ExplicitProxyEndPoint, ProxyProtocolType) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemProxy(ExplicitProxyEndPoint endPoint, ProxyProtocolType protocolType) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. ProxyProtocolType protocolType The proxy protocol type. | Improve this Doc View Source Start() Start this proxy server instance. Declaration public void Start() | Improve this Doc View Source Stop() Stop this proxy server instance. Declaration public void Stop() Events | Improve this Doc View Source AfterResponse Intercept after response event from server. Declaration public event AsyncEventHandler AfterResponse Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source BeforeRequest Intercept request event to server. Declaration public event AsyncEventHandler BeforeRequest Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source BeforeResponse Intercept response event from server. Declaration public event AsyncEventHandler BeforeResponse Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source ClientCertificateSelectionCallback Event to override client certificate selection during mutual SSL authentication. Declaration public event AsyncEventHandler ClientCertificateSelectionCallback Event Type Type Description AsyncEventHandler < CertificateSelectionEventArgs > | Improve this Doc View Source ClientConnectionCountChanged Event occurs when client connection count changed. Declaration public event EventHandler ClientConnectionCountChanged Event Type Type Description EventHandler | Improve this Doc View Source OnClientConnectionCreate Customize TcpClient used for client connection upon create. Declaration public event AsyncEventHandler OnClientConnectionCreate Event Type Type Description AsyncEventHandler < TcpClient > | Improve this Doc View Source OnServerConnectionCreate Customize TcpClient used for server connection upon create. Declaration public event AsyncEventHandler OnServerConnectionCreate Event Type Type Description AsyncEventHandler < TcpClient > | Improve this Doc View Source ServerCertificateValidationCallback Event to override the default verification logic of remote SSL certificate received during authentication. Declaration public event AsyncEventHandler ServerCertificateValidationCallback Event Type Type Description AsyncEventHandler < CertificateValidationEventArgs > | Improve this Doc View Source ServerConnectionCountChanged Event occurs when server connection count changed. Declaration public event EventHandler ServerConnectionCountChanged Event Type Type Description EventHandler Implements System.IDisposable" + "keywords": "Class ProxyServer This class is the backbone of proxy. One can create as many instances as needed. However care should be taken to avoid using the same listening ports across multiple instances. Inheritance Object ProxyServer Implements IDisposable Inherited Members Object.ToString() Object.Equals(Object) Object.Equals(Object, Object) Object.ReferenceEquals(Object, Object) Object.GetHashCode() Object.GetType() Object.MemberwiseClone() Namespace : Titanium.Web.Proxy Assembly : Titanium.Web.Proxy.dll Syntax public class ProxyServer : IDisposable Constructors | Improve this Doc View Source ProxyServer(Boolean, Boolean, Boolean) Initializes a new instance of ProxyServer class with provided parameters. Declaration public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false) Parameters Type Name Description Boolean userTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's user certificate store? Boolean machineTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's certificate store? Boolean trustRootCertificateAsAdmin Should we attempt to trust certificates with elevated permissions by prompting for UAC if required? | Improve this Doc View Source ProxyServer(String, String, Boolean, Boolean, Boolean) Initializes a new instance of ProxyServer class with provided parameters. Declaration public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool trustRootCertificateAsAdmin = false) Parameters Type Name Description String rootCertificateName Name of the root certificate. String rootCertificateIssuerName Name of the root certificate issuer. Boolean userTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's user certificate store? Boolean machineTrustRootCertificate Should fake HTTPS certificate be trusted by this machine's certificate store? Boolean trustRootCertificateAsAdmin Should we attempt to trust certificates with elevated permissions by prompting for UAC if required? Properties | Improve this Doc View Source BufferPool The buffer pool used throughout this proxy instance. Set custom implementations by implementing this interface. By default this uses DefaultBufferPool implementation available in StreamExtended library package. Declaration public IBufferPool BufferPool { get; set; } Property Value Type Description IBufferPool | Improve this Doc View Source BufferSize Buffer size in bytes used throughout this proxy. Default value is 8192 bytes. Declaration public int BufferSize { get; set; } Property Value Type Description Int32 | Improve this Doc View Source CertificateManager Manages certificates used by this proxy. Declaration public CertificateManager CertificateManager { get; } Property Value Type Description CertificateManager | Improve this Doc View Source CheckCertificateRevocation Should we check for certificate revocation during SSL authentication to servers Note: If enabled can reduce performance. Defaults to false. Declaration public X509RevocationMode CheckCertificateRevocation { get; set; } Property Value Type Description X509RevocationMode | Improve this Doc View Source ClientConnectionCount Total number of active client connections. Declaration public int ClientConnectionCount { get; } Property Value Type Description Int32 | Improve this Doc View Source ConnectionTimeOutSeconds Seconds client/server connection are to be kept alive when waiting for read/write to complete. This will also determine the pool eviction time when connection pool is enabled. Default value is 60 seconds. Declaration public int ConnectionTimeOutSeconds { get; set; } Property Value Type Description Int32 | Improve this Doc View Source Enable100ContinueBehaviour Does this proxy uses the HTTP protocol 100 continue behaviour strictly? Broken 100 continue implementations on server/client may cause problems if enabled. Defaults to false. Declaration public bool Enable100ContinueBehaviour { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableConnectionPool Should we enable experimental server connection pool? Defaults to true. Declaration public bool EnableConnectionPool { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableHttp2 Enable disable HTTP/2 support. Warning: HTTP/2 support is very limited only enabled when both client and server supports it (no protocol changing in proxy) cannot modify the request/response (e.g header modifications in BeforeRequest/Response events are ignored) Declaration public bool EnableHttp2 { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableTcpServerConnectionPrefetch Should we enable tcp server connection prefetching? When enabled, as soon as we receive a client connection we concurrently initiate corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request we will have the server connection immediately ready or in the process of getting ready. If a server connection is available in cache then this prefetch task will immediately return with the available connection from cache. Defaults to true. Declaration public bool EnableTcpServerConnectionPrefetch { get; set; } Property Value Type Description Boolean | Improve this Doc View Source EnableWinAuth Enable disable Windows Authentication (NTLM/Kerberos). Note: NTLM/Kerberos will always send local credentials of current user running the proxy process. This is because a man in middle attack with Windows domain authentication is not currently supported. Defaults to false. Declaration public bool EnableWinAuth { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ExceptionFunc Callback for error events in this proxy instance. Declaration public ExceptionHandler ExceptionFunc { get; set; } Property Value Type Description ExceptionHandler | Improve this Doc View Source ForwardToUpstreamGateway Gets or sets a value indicating whether requests will be chained to upstream gateway. Defaults to false. Declaration public bool ForwardToUpstreamGateway { get; set; } Property Value Type Description Boolean | Improve this Doc View Source GetCustomUpStreamProxyFunc A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests. User should return the ExternalProxy object with valid credentials. Declaration public Func> GetCustomUpStreamProxyFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , Task < ExternalProxy >> | Improve this Doc View Source MaxCachedConnections Maximum number of concurrent connections per remote host in cache. Only valid when connection pooling is enabled. Default value is 2. Declaration public int MaxCachedConnections { get; set; } Property Value Type Description Int32 | Improve this Doc View Source NoDelay Gets or sets a Boolean value that specifies whether server and client stream Sockets are using the Nagle algorithm. Defaults to true, no nagle algorithm is used. Declaration public bool NoDelay { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ProxyAuthenticationRealm Realm used during Proxy Basic Authentication. Declaration public string ProxyAuthenticationRealm { get; set; } Property Value Type Description String | Improve this Doc View Source ProxyAuthenticationSchemes A collection of scheme types, e.g. basic, NTLM, Kerberos, Negotiate, to return if scheme authentication is required. Works in relation with ProxySchemeAuthenticateFunc. Declaration public IEnumerable ProxyAuthenticationSchemes { get; set; } Property Value Type Description IEnumerable < String > | Improve this Doc View Source ProxyBasicAuthenticateFunc A callback to authenticate proxy clients via basic authentication. Parameters are username and password as provided by client. Should return true for successful authentication. Declaration public Func> ProxyBasicAuthenticateFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , String , String , Task < Boolean >> | Improve this Doc View Source ProxyEndPoints A list of IpAddress and port this proxy is listening to. Declaration public List ProxyEndPoints { get; set; } Property Value Type Description List < ProxyEndPoint > | Improve this Doc View Source ProxyRunning Is the proxy currently running? Declaration public bool ProxyRunning { get; } Property Value Type Description Boolean | Improve this Doc View Source ProxySchemeAuthenticateFunc A pluggable callback to authenticate clients by scheme instead of requiring basic authentication through ProxyBasicAuthenticateFunc. Parameters are current working session, schemeType, and token as provided by a calling client. Should return success for successful authentication, continuation if the package requests, or failure. Declaration public Func> ProxySchemeAuthenticateFunc { get; set; } Property Value Type Description Func < SessionEventArgsBase , String , String , Task < ProxyAuthenticationContext >> | Improve this Doc View Source ReuseSocket Should we reuse client/server tcp sockets. Default is true (disabled for linux/macOS due to bug in .Net core). Declaration public bool ReuseSocket { get; set; } Property Value Type Description Boolean | Improve this Doc View Source ServerConnectionCount Total number of active server connections. Declaration public int ServerConnectionCount { get; } Property Value Type Description Int32 | Improve this Doc View Source SupportedSslProtocols List of supported Ssl versions. Declaration public SslProtocols SupportedSslProtocols { get; set; } Property Value Type Description SslProtocols | Improve this Doc View Source TcpTimeWaitSeconds Number of seconds to linger when Tcp connection is in TIME_WAIT state. Default value is 30. Declaration public int TcpTimeWaitSeconds { get; set; } Property Value Type Description Int32 | Improve this Doc View Source ThreadPoolWorkerThread Customize the minimum ThreadPool size (increase it on a server) Declaration public int ThreadPoolWorkerThread { get; set; } Property Value Type Description Int32 | Improve this Doc View Source UpStreamEndPoint Local adapter/NIC endpoint where proxy makes request via. Defaults via any IP addresses of this machine. Declaration public IPEndPoint UpStreamEndPoint { get; set; } Property Value Type Description IPEndPoint | Improve this Doc View Source UpStreamHttpProxy External proxy used for Http requests. Declaration public ExternalProxy UpStreamHttpProxy { get; set; } Property Value Type Description ExternalProxy | Improve this Doc View Source UpStreamHttpsProxy External proxy used for Https requests. Declaration public ExternalProxy UpStreamHttpsProxy { get; set; } Property Value Type Description ExternalProxy Methods | Improve this Doc View Source AddEndPoint(ProxyEndPoint) Add a proxy end point. Declaration public void AddEndPoint(ProxyEndPoint endPoint) Parameters Type Name Description ProxyEndPoint endPoint The proxy endpoint. | Improve this Doc View Source DisableAllSystemProxies() Clear all proxy settings for current machine. Declaration public void DisableAllSystemProxies() | Improve this Doc View Source DisableSystemHttpProxy() Clear HTTP proxy settings of current machine. Declaration public void DisableSystemHttpProxy() | Improve this Doc View Source DisableSystemHttpsProxy() Clear HTTPS proxy settings of current machine. Declaration public void DisableSystemHttpsProxy() | Improve this Doc View Source DisableSystemProxy(ProxyProtocolType) Clear the specified proxy setting for current machine. Declaration public void DisableSystemProxy(ProxyProtocolType protocolType) Parameters Type Name Description ProxyProtocolType protocolType | Improve this Doc View Source Dispose() Dispose the Proxy instance. Declaration public void Dispose() | Improve this Doc View Source RemoveEndPoint(ProxyEndPoint) Remove a proxy end point. Will throw error if the end point doesn't exist. Declaration public void RemoveEndPoint(ProxyEndPoint endPoint) Parameters Type Name Description ProxyEndPoint endPoint The existing endpoint to remove. | Improve this Doc View Source SetAsSystemHttpProxy(ExplicitProxyEndPoint) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. | Improve this Doc View Source SetAsSystemHttpsProxy(ExplicitProxyEndPoint) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. | Improve this Doc View Source SetAsSystemProxy(ExplicitProxyEndPoint, ProxyProtocolType) Set the given explicit end point as the default proxy server for current machine. Declaration public void SetAsSystemProxy(ExplicitProxyEndPoint endPoint, ProxyProtocolType protocolType) Parameters Type Name Description ExplicitProxyEndPoint endPoint The explicit endpoint. ProxyProtocolType protocolType The proxy protocol type. | Improve this Doc View Source Start() Start this proxy server instance. Declaration public void Start() | Improve this Doc View Source Stop() Stop this proxy server instance. Declaration public void Stop() Events | Improve this Doc View Source AfterResponse Intercept after response event from server. Declaration public event AsyncEventHandler AfterResponse Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source BeforeRequest Intercept request event to server. Declaration public event AsyncEventHandler BeforeRequest Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source BeforeResponse Intercept response event from server. Declaration public event AsyncEventHandler BeforeResponse Event Type Type Description AsyncEventHandler < SessionEventArgs > | Improve this Doc View Source ClientCertificateSelectionCallback Event to override client certificate selection during mutual SSL authentication. Declaration public event AsyncEventHandler ClientCertificateSelectionCallback Event Type Type Description AsyncEventHandler < CertificateSelectionEventArgs > | Improve this Doc View Source ClientConnectionCountChanged Event occurs when client connection count changed. Declaration public event EventHandler ClientConnectionCountChanged Event Type Type Description EventHandler | Improve this Doc View Source OnClientConnectionCreate Customize TcpClient used for client connection upon create. Declaration public event AsyncEventHandler OnClientConnectionCreate Event Type Type Description AsyncEventHandler < TcpClient > | Improve this Doc View Source OnServerConnectionCreate Customize TcpClient used for server connection upon create. Declaration public event AsyncEventHandler OnServerConnectionCreate Event Type Type Description AsyncEventHandler < TcpClient > | Improve this Doc View Source ServerCertificateValidationCallback Event to override the default verification logic of remote SSL certificate received during authentication. Declaration public event AsyncEventHandler ServerCertificateValidationCallback Event Type Type Description AsyncEventHandler < CertificateValidationEventArgs > | Improve this Doc View Source ServerConnectionCountChanged Event occurs when server connection count changed. Declaration public event EventHandler ServerConnectionCountChanged Event Type Type Description EventHandler Implements System.IDisposable" } } diff --git a/docs/xrefmap.yml b/docs/xrefmap.yml index e76021129..64e7f4b74 100644 --- a/docs/xrefmap.yml +++ b/docs/xrefmap.yml @@ -350,6 +350,19 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgs.GetResponseBodyAsString nameWithType: SessionEventArgs.GetResponseBodyAsString +- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise + name: IsPromise + href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html#Titanium_Web_Proxy_EventArguments_SessionEventArgs_IsPromise + commentId: P:Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise + fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise + nameWithType: SessionEventArgs.IsPromise +- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise* + name: IsPromise + href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html#Titanium_Web_Proxy_EventArguments_SessionEventArgs_IsPromise_ + commentId: Overload:Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise + isSpec: "True" + fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgs.IsPromise + nameWithType: SessionEventArgs.IsPromise - uid: Titanium.Web.Proxy.EventArguments.SessionEventArgs.MultipartRequestPartSent name: MultipartRequestPartSent href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgs.html#Titanium_Web_Proxy_EventArguments_SessionEventArgs_MultipartRequestPartSent @@ -510,18 +523,18 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.SessionEventArgsBase nameWithType: SessionEventArgsBase.SessionEventArgsBase -- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferPool - name: bufferPool - href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_bufferPool - commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferPool - fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferPool - nameWithType: SessionEventArgsBase.bufferPool -- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferSize - name: bufferSize - href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_bufferSize - commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferSize - fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.bufferSize - nameWithType: SessionEventArgsBase.bufferSize +- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferPool + name: BufferPool + href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_BufferPool + commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferPool + fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferPool + nameWithType: SessionEventArgsBase.BufferPool +- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferSize + name: BufferSize + href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_BufferSize + commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferSize + fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.BufferSize + nameWithType: SessionEventArgsBase.BufferSize - uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.ClientEndPoint name: ClientEndPoint href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_ClientEndPoint @@ -586,12 +599,12 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.Exception nameWithType: SessionEventArgsBase.Exception -- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.exceptionFunc - name: exceptionFunc - href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_exceptionFunc - commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.exceptionFunc - fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.exceptionFunc - nameWithType: SessionEventArgsBase.exceptionFunc +- uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.ExceptionFunc + name: ExceptionFunc + href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_ExceptionFunc + commentId: F:Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.ExceptionFunc + fullName: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.ExceptionFunc + nameWithType: SessionEventArgsBase.ExceptionFunc - uid: Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.HttpClient name: HttpClient href: api/Titanium.Web.Proxy.EventArguments.SessionEventArgsBase.html#Titanium_Web_Proxy_EventArguments_SessionEventArgsBase_HttpClient @@ -962,6 +975,19 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.Http.ConnectRequest.ClientHelloInfo nameWithType: ConnectRequest.ClientHelloInfo +- uid: Titanium.Web.Proxy.Http.ConnectRequest.TunnelType + name: TunnelType + href: api/Titanium.Web.Proxy.Http.ConnectRequest.html#Titanium_Web_Proxy_Http_ConnectRequest_TunnelType + commentId: P:Titanium.Web.Proxy.Http.ConnectRequest.TunnelType + fullName: Titanium.Web.Proxy.Http.ConnectRequest.TunnelType + nameWithType: ConnectRequest.TunnelType +- uid: Titanium.Web.Proxy.Http.ConnectRequest.TunnelType* + name: TunnelType + href: api/Titanium.Web.Proxy.Http.ConnectRequest.html#Titanium_Web_Proxy_Http_ConnectRequest_TunnelType_ + commentId: Overload:Titanium.Web.Proxy.Http.ConnectRequest.TunnelType + isSpec: "True" + fullName: Titanium.Web.Proxy.Http.ConnectRequest.TunnelType + nameWithType: ConnectRequest.TunnelType - uid: Titanium.Web.Proxy.Http.ConnectResponse name: ConnectResponse href: api/Titanium.Web.Proxy.Http.ConnectResponse.html @@ -1601,6 +1627,19 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.Http.Request.RequestUri nameWithType: Request.RequestUri +- uid: Titanium.Web.Proxy.Http.Request.RequestUriString + name: RequestUriString + href: api/Titanium.Web.Proxy.Http.Request.html#Titanium_Web_Proxy_Http_Request_RequestUriString + commentId: P:Titanium.Web.Proxy.Http.Request.RequestUriString + fullName: Titanium.Web.Proxy.Http.Request.RequestUriString + nameWithType: Request.RequestUriString +- uid: Titanium.Web.Proxy.Http.Request.RequestUriString* + name: RequestUriString + href: api/Titanium.Web.Proxy.Http.Request.html#Titanium_Web_Proxy_Http_Request_RequestUriString_ + commentId: Overload:Titanium.Web.Proxy.Http.Request.RequestUriString + isSpec: "True" + fullName: Titanium.Web.Proxy.Http.Request.RequestUriString + nameWithType: Request.RequestUriString - uid: Titanium.Web.Proxy.Http.Request.UpgradeToWebSocket name: UpgradeToWebSocket href: api/Titanium.Web.Proxy.Http.Request.html#Titanium_Web_Proxy_Http_Request_UpgradeToWebSocket @@ -2218,12 +2257,12 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.Http2.Hpack.Encoder.Encoder nameWithType: Encoder.Encoder -- uid: Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter,System.String,System.String,System.Boolean) - name: EncodeHeader(BinaryWriter, String, String, Boolean) - href: api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html#Titanium_Web_Proxy_Http2_Hpack_Encoder_EncodeHeader_System_IO_BinaryWriter_System_String_System_String_System_Boolean_ - commentId: M:Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter,System.String,System.String,System.Boolean) - fullName: Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter, System.String, System.String, System.Boolean) - nameWithType: Encoder.EncodeHeader(BinaryWriter, String, String, Boolean) +- uid: Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter,System.String,System.String,System.Boolean,Titanium.Web.Proxy.Http2.Hpack.HpackUtil.IndexType,System.Boolean) + name: EncodeHeader(BinaryWriter, String, String, Boolean, HpackUtil.IndexType, Boolean) + href: api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html#Titanium_Web_Proxy_Http2_Hpack_Encoder_EncodeHeader_System_IO_BinaryWriter_System_String_System_String_System_Boolean_Titanium_Web_Proxy_Http2_Hpack_HpackUtil_IndexType_System_Boolean_ + commentId: M:Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter,System.String,System.String,System.Boolean,Titanium.Web.Proxy.Http2.Hpack.HpackUtil.IndexType,System.Boolean) + fullName: Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader(System.IO.BinaryWriter, System.String, System.String, System.Boolean, Titanium.Web.Proxy.Http2.Hpack.HpackUtil.IndexType, System.Boolean) + nameWithType: Encoder.EncodeHeader(BinaryWriter, String, String, Boolean, HpackUtil.IndexType, Boolean) - uid: Titanium.Web.Proxy.Http2.Hpack.Encoder.EncodeHeader* name: EncodeHeader href: api/Titanium.Web.Proxy.Http2.Hpack.Encoder.html#Titanium_Web_Proxy_Http2_Hpack_Encoder_EncodeHeader_ @@ -2602,6 +2641,12 @@ references: commentId: M:Titanium.Web.Proxy.Models.HttpHeader.#ctor(System.String,System.String) fullName: Titanium.Web.Proxy.Models.HttpHeader.HttpHeader(System.String, System.String) nameWithType: HttpHeader.HttpHeader(String, String) +- uid: Titanium.Web.Proxy.Models.HttpHeader.#ctor(System.String,System.String,System.Boolean) + name: HttpHeader(String, String, Boolean) + href: api/Titanium.Web.Proxy.Models.HttpHeader.html#Titanium_Web_Proxy_Models_HttpHeader__ctor_System_String_System_String_System_Boolean_ + commentId: M:Titanium.Web.Proxy.Models.HttpHeader.#ctor(System.String,System.String,System.Boolean) + fullName: Titanium.Web.Proxy.Models.HttpHeader.HttpHeader(System.String, System.String, System.Boolean) + nameWithType: HttpHeader.HttpHeader(String, String, Boolean) - uid: Titanium.Web.Proxy.Models.HttpHeader.#ctor* name: HttpHeader href: api/Titanium.Web.Proxy.Models.HttpHeader.html#Titanium_Web_Proxy_Models_HttpHeader__ctor_ @@ -3492,6 +3537,19 @@ references: isSpec: "True" fullName: Titanium.Web.Proxy.ProxyServer.EnableConnectionPool nameWithType: ProxyServer.EnableConnectionPool +- uid: Titanium.Web.Proxy.ProxyServer.EnableHttp2 + name: EnableHttp2 + href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableHttp2 + commentId: P:Titanium.Web.Proxy.ProxyServer.EnableHttp2 + fullName: Titanium.Web.Proxy.ProxyServer.EnableHttp2 + nameWithType: ProxyServer.EnableHttp2 +- uid: Titanium.Web.Proxy.ProxyServer.EnableHttp2* + name: EnableHttp2 + href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableHttp2_ + commentId: Overload:Titanium.Web.Proxy.ProxyServer.EnableHttp2 + isSpec: "True" + fullName: Titanium.Web.Proxy.ProxyServer.EnableHttp2 + nameWithType: ProxyServer.EnableHttp2 - uid: Titanium.Web.Proxy.ProxyServer.EnableTcpServerConnectionPrefetch name: EnableTcpServerConnectionPrefetch href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableTcpServerConnectionPrefetch diff --git a/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs b/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs index 2032e19f7..579c92648 100644 --- a/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs +++ b/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs @@ -4,7 +4,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers { /// - /// Adapated from + /// Adapted from /// http://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode /// internal static class ConsoleHelper diff --git a/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs b/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs index 088615c91..04681b95c 100644 --- a/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs +++ b/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs @@ -32,11 +32,11 @@ public ProxyTestController() { if (exception is ProxyHttpException phex) { - await WriteToConsole(exception.Message + ": " + phex.InnerException?.Message, true); + await writeToConsole(exception.Message + ": " + phex.InnerException?.Message, true); } else { - await WriteToConsole(exception.Message, true); + await writeToConsole(exception.Message, true); } }; proxyServer.ForwardToUpstreamGateway = true; @@ -52,8 +52,8 @@ public ProxyTestController() public void StartProxy() { - proxyServer.BeforeRequest += OnRequest; - proxyServer.BeforeResponse += OnResponse; + proxyServer.BeforeRequest += onRequest; + proxyServer.BeforeResponse += onResponse; proxyServer.ServerCertificateValidationCallback += OnCertificateValidation; proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection; @@ -63,8 +63,8 @@ public void StartProxy() explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000); // Fired when a CONNECT request is received - explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest; - explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse; + explicitEndPoint.BeforeTunnelConnectRequest += onBeforeTunnelConnectRequest; + explicitEndPoint.BeforeTunnelConnectResponse += onBeforeTunnelConnectResponse; // An explicit endpoint is where the client knows about the existence of a proxy // So client sends request in a proxy friendly manner @@ -102,11 +102,11 @@ public void StartProxy() public void Stop() { - explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest; - explicitEndPoint.BeforeTunnelConnectResponse -= OnBeforeTunnelConnectResponse; + explicitEndPoint.BeforeTunnelConnectRequest -= onBeforeTunnelConnectRequest; + explicitEndPoint.BeforeTunnelConnectResponse -= onBeforeTunnelConnectResponse; - proxyServer.BeforeRequest -= OnRequest; - proxyServer.BeforeResponse -= OnResponse; + proxyServer.BeforeRequest -= onRequest; + proxyServer.BeforeResponse -= onResponse; proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation; proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection; @@ -116,10 +116,10 @@ public void Stop() //proxyServer.CertificateManager.RemoveTrustedRootCertificates(); } - private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) + private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) { string hostname = e.HttpClient.Request.RequestUri.Host; - await WriteToConsole("Tunnel to: " + hostname); + await writeToConsole("Tunnel to: " + hostname); if (hostname.Contains("dropbox.com")) { @@ -130,16 +130,16 @@ private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSess } } - private Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) + private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) { return Task.FromResult(false); } // intecept & cancel redirect or update requests - private async Task OnRequest(object sender, SessionEventArgs e) + private async Task onRequest(object sender, SessionEventArgs e) { - await WriteToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); - await WriteToConsole(e.HttpClient.Request.Url); + await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); + await writeToConsole(e.HttpClient.Request.Url); // store it in the UserData property // It can be a simple integer, Guid, or any type @@ -177,19 +177,19 @@ private async Task OnRequest(object sender, SessionEventArgs e) } // Modify response - private async Task MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e) + private async Task multipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e) { var session = (SessionEventArgs)sender; - await WriteToConsole("Multipart form data headers:"); + await writeToConsole("Multipart form data headers:"); foreach (var header in e.Headers) { - await WriteToConsole(header.ToString()); + await writeToConsole(header.ToString()); } } - private async Task OnResponse(object sender, SessionEventArgs e) + private async Task onResponse(object sender, SessionEventArgs e) { - await WriteToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount); + await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount); string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath); @@ -261,7 +261,7 @@ public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs return Task.FromResult(0); } - private async Task WriteToConsole(string message, bool useRedColor = false) + private async Task writeToConsole(string message, bool useRedColor = false) { await @lock.WaitAsync(); diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml index c13acfd45..1739dedcf 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml @@ -36,13 +36,20 @@ - + - + + + + + + + + diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs index 6bc523859..9e3ba6f57 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Net; using System.Text; @@ -8,6 +9,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media.Imaging; using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Models; @@ -36,6 +38,9 @@ public partial class MainWindow : Window public MainWindow() { proxyServer = new ProxyServer(); + + proxyServer.EnableHttp2 = true; + //proxyServer.CertificateManager.CertificateEngine = CertificateEngine.DefaultWindows; ////Set a password for the .pfx file @@ -53,6 +58,9 @@ public MainWindow() proxyServer.ForwardToUpstreamGateway = true; + //increase the ThreadPool (for server prod) + //proxyServer.ThreadPoolWorkerThread = Environment.ProcessorCount * 6; + ////if you need Load or Create Certificate now. ////// "true" if you need Enable===> Trust the RootCertificate used by this proxy server //proxyServer.CertificateManager.EnsureRootCertificate(true); @@ -93,7 +101,7 @@ public MainWindow() InitializeComponent(); } - public ObservableCollection Sessions { get; } = new ObservableCollection(); + public ObservableCollectionEx Sessions { get; } = new ObservableCollectionEx(); public SessionListItem SelectedSession { @@ -103,7 +111,7 @@ public SessionListItem SelectedSession if (value != selectedSession) { selectedSession = value; - SelectedSessionChanged(); + selectedSessionChanged(); } } } @@ -128,7 +136,7 @@ private async Task ProxyServer_BeforeTunnelConnectRequest(object sender, TunnelC e.DecryptSsl = false; } - await Dispatcher.InvokeAsync(() => { AddSession(e); }); + await Dispatcher.InvokeAsync(() => { addSession(e); }); } private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) @@ -144,8 +152,20 @@ await Dispatcher.InvokeAsync(() => private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e) { + if (e.HttpClient.ConnectRequest?.TunnelType != TunnelType.Http2) + { + return; + } + SessionListItem item = null; - await Dispatcher.InvokeAsync(() => { item = AddSession(e); }); + await Dispatcher.InvokeAsync(() => { item = addSession(e); }); + + //if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Http2) + //{ + //} + + //if (!e.HttpClient.Request.RequestUri.ToString().Contains("/mail/u/")) + // return; if (e.HttpClient.Request.HasBody) { @@ -156,6 +176,11 @@ private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e) private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e) { + if (e.HttpClient.ConnectRequest?.TunnelType != TunnelType.Http2) + { + return; + } + SessionListItem item = null; await Dispatcher.InvokeAsync(() => { @@ -165,6 +190,10 @@ await Dispatcher.InvokeAsync(() => } }); + //e.HttpClient.Response.Headers.AddHeader("X-Titanium-Header", "HTTP/2 works"); + + //e.SetResponseBody(Encoding.ASCII.GetBytes("TITANIUMMMM!!!!")); + if (item != null) { if (e.HttpClient.Response.HasBody) @@ -188,15 +217,15 @@ await Dispatcher.InvokeAsync(() => }); } - private SessionListItem AddSession(SessionEventArgsBase e) + private SessionListItem addSession(SessionEventArgsBase e) { - var item = CreateSessionListItem(e); + var item = createSessionListItem(e); Sessions.Add(item); sessionDictionary.Add(e.HttpClient, item); return item; } - private SessionListItem CreateSessionListItem(SessionEventArgsBase e) + private SessionListItem createSessionListItem(SessionEventArgsBase e) { lastSessionNumber++; bool isTunnelConnect = e is TunnelConnectSessionEventArgs; @@ -211,18 +240,30 @@ private SessionListItem CreateSessionListItem(SessionEventArgsBase e) { e.DataReceived += (sender, args) => { - var session = (SessionEventArgs)sender; + var session = (SessionEventArgsBase)sender; if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) { + var tunnelType = session.HttpClient.ConnectRequest?.TunnelType ?? TunnelType.Unknown; + if (tunnelType != TunnelType.Unknown) + { + li.Protocol = TunnelTypeToString(tunnelType); + } + li.ReceivedDataCount += args.Count; } }; e.DataSent += (sender, args) => { - var session = (SessionEventArgs)sender; + var session = (SessionEventArgsBase)sender; if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) { + var tunnelType = session.HttpClient.ConnectRequest?.TunnelType ?? TunnelType.Unknown; + if (tunnelType != TunnelType.Unknown) + { + li.Protocol = TunnelTypeToString(tunnelType); + } + li.SentDataCount += args.Count; } }; @@ -232,20 +273,38 @@ private SessionListItem CreateSessionListItem(SessionEventArgsBase e) return item; } + private string TunnelTypeToString(TunnelType tunnelType) + { + switch (tunnelType) + { + case TunnelType.Https: + return "https"; + case TunnelType.Websocket: + return "websocket"; + case TunnelType.Http2: + return "http2"; + } + + return null; + } + private void ListViewSessions_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { var selectedItems = ((ListView)sender).SelectedItems; + Sessions.SuppressNotification = true; foreach (var item in selectedItems.Cast().ToArray()) { Sessions.Remove(item); sessionDictionary.Remove(item.HttpClient); } + + Sessions.SuppressNotification = false; } } - private void SelectedSessionChanged() + private void selectedSessionChanged() { if (SelectedSession == null) { @@ -256,7 +315,8 @@ private void SelectedSessionChanged() var session = SelectedSession.HttpClient; var request = session.Request; - var data = (request.IsBodyRead ? request.Body : null) ?? new byte[0]; + var fullData = (request.IsBodyRead ? request.Body : null) ?? new byte[0]; + var data = fullData; bool truncated = data.Length > truncateLimit; if (truncated) { @@ -272,7 +332,8 @@ private void SelectedSessionChanged() TextBoxRequest.Text = sb.ToString(); var response = session.Response; - data = (response.IsBodyRead ? response.Body : null) ?? new byte[0]; + fullData = (response.IsBodyRead ? response.Body : null) ?? new byte[0]; + data = fullData; truncated = data.Length > truncateLimit; if (truncated) { @@ -292,6 +353,19 @@ private void SelectedSessionChanged() } TextBoxResponse.Text = sb.ToString(); + + try + { + using (MemoryStream stream = new MemoryStream(fullData)) + { + ImageResponse.Source = + BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); + } + } + catch + { + ImageResponse.Source = null; + } } } } diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/ObservableCollectionEx.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/ObservableCollectionEx.cs new file mode 100644 index 000000000..e93175e59 --- /dev/null +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/ObservableCollectionEx.cs @@ -0,0 +1,36 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace Titanium.Web.Proxy.Examples.Wpf +{ + public class ObservableCollectionEx : ObservableCollection + { + private bool notificationSuppressed; + private bool suppressNotification; + + public bool SuppressNotification + { + get => suppressNotification; + set + { + suppressNotification = value; + if (suppressNotification == false && notificationSuppressed) + { + OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + notificationSuppressed = false; + } + } + } + + protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) + { + if (SuppressNotification) + { + notificationSuppressed = true; + return; + } + + base.OnCollectionChanged(e); + } + } +} \ No newline at end of file diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs index cead89589..680d71b38 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs @@ -73,7 +73,7 @@ public sealed class NotNullAttribute : Attribute } /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property /// or of the Lazy.Value property can never be null. /// @@ -85,7 +85,7 @@ public sealed class ItemNotNullAttribute : Attribute } /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property /// or of the Lazy.Value property can be null. /// @@ -251,7 +251,7 @@ public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) /// /// If method has single input parameter, it's name could be omitted.
    /// Using halt (or void/nothing, which is the same) for method output - /// means that the methos doesn't return normally (throws or terminates the process).
    + /// means that the method doesn't return normally (throws or terminates the process).
    /// Value canbenull is only applicable for output parameters.
    /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute /// with rows separated by semicolon. There is no notion of order rows, all rows are checked diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs index c3f54b0fe..7cfd456b2 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs @@ -11,7 +11,7 @@ public class SessionListItem : INotifyPropertyChanged private long? bodySize; private Exception exception; private string host; - private string process; + private int processId; private string protocol; private long receivedDataCount; private long sentDataCount; @@ -54,10 +54,32 @@ public long? BodySize set => SetField(ref bodySize, value); } + public int ProcessId + { + get => processId; + set + { + if (SetField(ref processId, value)) + { + OnPropertyChanged(nameof(Process)); + } + } + } + public string Process { - get => process; - set => SetField(ref process, value); + get + { + try + { + var process = System.Diagnostics.Process.GetProcessById(processId); + return process.ProcessName + ":" + processId; + } + catch (Exception) + { + return string.Empty; + } + } } public long ReceivedDataCount @@ -80,13 +102,16 @@ public Exception Exception public event PropertyChangedEventHandler PropertyChanged; - protected void SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + protected bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) { if (!Equals(field, value)) { field = value; OnPropertyChanged(propertyName); + return true; } + + return false; } [NotifyPropertyChangedInvocator] @@ -132,20 +157,7 @@ public void Update() BodySize = responseSize; } - Process = GetProcessDescription(HttpClient.ProcessId.Value); - } - - private string GetProcessDescription(int processId) - { - try - { - var process = System.Diagnostics.Process.GetProcessById(processId); - return process.ProcessName + ":" + processId; - } - catch (Exception) - { - return string.Empty; - } + ProcessId = HttpClient.ProcessId.Value; } } } diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.NetCore.csproj b/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.NetCore.csproj new file mode 100644 index 000000000..5619d9464 --- /dev/null +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.NetCore.csproj @@ -0,0 +1,17 @@ + + + + WinExe + netcoreapp3.0 + true + + + + + + + + + + + \ No newline at end of file diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj b/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj index 75cd14626..f9d14d6ce 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj @@ -72,9 +72,6 @@ true - - ..\..\src\packages\StreamExtended.1.0.201\lib\net45\StreamExtended.dll - @@ -95,6 +92,7 @@ MSBuild:Compile Designer + @@ -128,7 +126,6 @@ ResXFileCodeGenerator Resources.Designer.cs - SettingsSingleFileGenerator Settings.Designer.cs @@ -145,6 +142,10 @@ + + {61539dc1-ce80-41e6-a696-8f455ace8d15} + StreamExtended + {91018b6d-a7a9-45be-9cb3-79cbb8b169a6} Titanium.Web.Proxy diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/packages.config b/examples/Titanium.Web.Proxy.Examples.Wpf/packages.config deleted file mode 100644 index 9ee587422..000000000 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/StreamExtended/BufferPool/DefaultBufferPool.cs b/src/StreamExtended/BufferPool/DefaultBufferPool.cs new file mode 100644 index 000000000..4d7d8a641 --- /dev/null +++ b/src/StreamExtended/BufferPool/DefaultBufferPool.cs @@ -0,0 +1,47 @@ +using System.Collections.Concurrent; + +namespace StreamExtended +{ + + /// + /// A concrete IBufferPool implementation using a thread-safe stack. + /// Works well when all consumers ask for buffers with the same size. + /// If your application would use variable size buffers consider implementing IBufferPool using System.Buffers library from Microsoft. + /// + public class DefaultBufferPool : IBufferPool + { + private readonly ConcurrentStack buffers = new ConcurrentStack(); + + /// + /// Gets a buffer. + /// + /// Size of the buffer. + /// + public byte[] GetBuffer(int bufferSize) + { + if (!buffers.TryPop(out var buffer) || buffer.Length != bufferSize) + { + buffer = new byte[bufferSize]; + } + + return buffer; + } + + /// + /// Returns the buffer. + /// + /// The buffer. + public void ReturnBuffer(byte[] buffer) + { + if (buffer != null) + { + buffers.Push(buffer); + } + } + + public void Dispose() + { + buffers.Clear(); + } + } +} diff --git a/src/StreamExtended/BufferPool/IBufferPool.cs b/src/StreamExtended/BufferPool/IBufferPool.cs new file mode 100644 index 000000000..f7f1b761c --- /dev/null +++ b/src/StreamExtended/BufferPool/IBufferPool.cs @@ -0,0 +1,14 @@ +using System; + +namespace StreamExtended +{ + /// + /// Use this interface to implement custom buffer pool. + /// To use the default buffer pool implementation use DefaultBufferPool class. + /// + public interface IBufferPool : IDisposable + { + byte[] GetBuffer(int bufferSize); + void ReturnBuffer(byte[] buffer); + } +} diff --git a/src/StreamExtended/ClientHelloInfo.cs b/src/StreamExtended/ClientHelloInfo.cs new file mode 100644 index 000000000..4cf3bd008 --- /dev/null +++ b/src/StreamExtended/ClientHelloInfo.cs @@ -0,0 +1,122 @@ +using StreamExtended.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StreamExtended +{ + /// + /// Wraps up the client SSL hello information. + /// + public class ClientHelloInfo + { + private static readonly string[] compressions = { + "null", + "DEFLATE" + }; + + public int HandshakeVersion { get; set; } + + public int MajorVersion { get; set; } + + public int MinorVersion { get; set; } + + public byte[] Random { get; set; } + + public DateTime Time + { + get + { + DateTime time = DateTime.MinValue; + if (Random.Length > 3) + { + time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) + .AddSeconds(((uint)Random[3] << 24) + ((uint)Random[2] << 16) + ((uint)Random[1] << 8) + (uint)Random[0]).ToLocalTime(); + } + + return time; + } + } + + public byte[] SessionId { get; set; } + + public int[] Ciphers { get; set; } + + public byte[] CompressionData { get; set; } + + internal int ClientHelloLength { get; set; } + + internal int EntensionsStartPosition { get; set; } + + public Dictionary Extensions { get; set; } + + private static string SslVersionToString(int major, int minor) + { + string str = "Unknown"; + if (major == 3 && minor == 3) + str = "TLS/1.2"; + else if (major == 3 && minor == 2) + str = "TLS/1.1"; + else if (major == 3 && minor == 1) + str = "TLS/1.0"; + else if (major == 3 && minor == 0) + str = "SSL/3.0"; + else if (major == 2 && minor == 0) + str = "SSL/2.0"; + + return $"{major}.{minor} ({str})"; + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine($"A SSLv{HandshakeVersion}-compatible ClientHello handshake was found. Titanium extracted the parameters below."); + sb.AppendLine(); + sb.AppendLine($"Version: {SslVersionToString(MajorVersion, MinorVersion)}"); + sb.AppendLine($"Random: {string.Join(" ", Random.Select(x => x.ToString("X2")))}"); + sb.AppendLine($"\"Time\": {Time}"); + sb.AppendLine($"SessionID: {string.Join(" ", SessionId.Select(x => x.ToString("X2")))}"); + + if (Extensions != null) + { + sb.AppendLine("Extensions:"); + foreach (var extension in Extensions.Values.OrderBy(x => x.Position)) + { + sb.AppendLine($"{extension.Name}: {extension.Data}"); + } + } + + if (CompressionData != null && CompressionData.Length > 0) + { + int compressionMethod = CompressionData[0]; + string compression = compressions.Length > compressionMethod + ? compressions[compressionMethod] + : $"unknown [0x{compressionMethod:X2}]"; + sb.AppendLine($"Compression: {compression}"); + } + + if (Ciphers.Length > 0) + { + sb.AppendLine("Ciphers:"); + foreach (int cipherSuite in Ciphers) + { + if (!SslCiphers.Ciphers.TryGetValue(cipherSuite, out string cipherStr)) + { + cipherStr = "unknown"; + } + + sb.AppendLine($"[0x{cipherSuite:X4}] {cipherStr}"); + } + } + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/src/StreamExtended/Models/SslCiphers.cs b/src/StreamExtended/Models/SslCiphers.cs new file mode 100644 index 000000000..ea3200f74 --- /dev/null +++ b/src/StreamExtended/Models/SslCiphers.cs @@ -0,0 +1,413 @@ +using System.Collections.Generic; + +namespace StreamExtended.Models +{ + internal static class SslCiphers + { + internal static readonly Dictionary Ciphers = new Dictionary + { + { 0x0000, "TLS_NULL_WITH_NULL_NULL" }, + { 0x0001, "TLS_RSA_WITH_NULL_MD5" }, + { 0x0002, "TLS_RSA_WITH_NULL_SHA" }, + { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" }, + { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" }, + { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" }, + { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" }, + { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" }, + { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" }, + { 0x000A, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0x000B, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x000C, "TLS_DH_DSS_WITH_DES_CBC_SHA" }, + { 0x000D, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" }, + { 0x000E, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x000F, "TLS_DH_RSA_WITH_DES_CBC_SHA" }, + { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" }, + { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" }, + { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" }, + { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" }, + { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" }, + { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" }, + { 0x001A, "TLS_DH_anon_WITH_DES_CBC_SHA" }, + { 0x001B, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" }, + { 0x001C, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" }, + { 0x001D, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" }, + //{ 0x001E, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" }, + // RFC 2712 + { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" }, + { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" }, + { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" }, + { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" }, + { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" }, + { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" }, + { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" }, + { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" }, + { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" }, + { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" }, + { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" }, + { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" }, + { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" }, + { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" }, + // RFC 4785 + { 0x002C, "TLS_PSK_WITH_NULL_SHA" }, + { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" }, + { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" }, + // RFC 5246 + { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" }, + { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" }, + { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" }, + { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" }, + { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" }, + { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" }, + { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" }, + { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" }, + { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" }, + { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" }, + { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" }, + { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" }, + { 0x003B, "TLS_RSA_WITH_NULL_SHA256" }, + { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" }, + { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" }, + { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" }, + { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" }, + { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" }, + { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" }, + { 0x0047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" }, + { 0x0048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" }, + { 0x0049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" }, + { 0x004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" }, + { 0x004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" }, + { 0x004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" }, + { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" }, + { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" }, + { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" }, + { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" }, + { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" }, + { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" }, + { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" }, + { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" }, + { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" }, + { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" }, + { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" }, + { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" }, + { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" }, + { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" }, + { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" }, + { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" }, + { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" }, + { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" }, + { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" }, + { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" }, + // RFC 4279 + { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" }, + { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" }, + { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" }, + { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" }, + { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" }, + { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" }, + { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" }, + { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" }, + { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" }, + { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" }, + { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" }, + { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" }, + // RFC 4162 + { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" }, + { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" }, + { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" }, + { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" }, + { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" }, + { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" }, + // RFC 5288 + { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" }, + { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" }, + { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" }, + { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" }, + { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" }, + { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" }, + { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" }, + { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" }, + { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" }, + { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" }, + { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" }, + { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" }, + // RFC 5487 + { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" }, + { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" }, + { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" }, + { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" }, + { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" }, + { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" }, + { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" }, + { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" }, + { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" }, + { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" }, + { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" }, + { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" }, + { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" }, + { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" }, + { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" }, + { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" }, + { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" }, + { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" }, + // RFC 5932 + { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" }, + { 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" }, + { 0x5600, "TLS_FALLBACK_SCSV" }, + // RFC 4492 + { 0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" }, + { 0xC002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" }, + { 0xC003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" }, + { 0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" }, + { 0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" }, + { 0xC007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" }, + { 0xC008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" }, + { 0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" }, + { 0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA" }, + { 0xC00C, "TLS_ECDH_RSA_WITH_RC4_128_SHA" }, + { 0xC00D, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" }, + { 0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" }, + { 0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA" }, + { 0xC011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" }, + { 0xC012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" }, + { 0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" }, + { 0xC015, "TLS_ECDH_anon_WITH_NULL_SHA" }, + { 0xC016, "TLS_ECDH_anon_WITH_RC4_128_SHA" }, + { 0xC017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" }, + { 0xC018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" }, + { 0xC019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" }, + // RFC 5054 + { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" }, + { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" }, + { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" }, + { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" }, + { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" }, + { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" }, + { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" }, + { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" }, + // RFC 5589 + { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" }, + { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" }, + { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" }, + { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" }, + { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }, + { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" }, + { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" }, + { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" }, + { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" }, + { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" }, + { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" }, + { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" }, + { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" }, + { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" }, + { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" }, + { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" }, + // RFC 5489 + { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" }, + { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" }, + { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" }, + { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" }, + { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" }, + { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" }, + { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" }, + { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" }, + { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" }, + { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" }, + { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" }, + { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" }, + { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" }, + { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" }, + { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" }, + { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" }, + { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" }, + { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" }, + { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" }, + { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" }, + { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" }, + { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" }, + { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" }, + { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" }, + { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" }, + { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" }, + { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" }, + { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" }, + { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" }, + { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" }, + { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" }, + { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" }, + { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" }, + { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" }, + { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" }, + { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" }, + { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" }, + { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" }, + { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" }, + { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" }, + { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" }, + { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" }, + { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" }, + { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" }, + { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" }, + { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" }, + { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" }, + { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" }, + { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" }, + { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" }, + { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" }, + { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" }, + { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" }, + { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" }, + { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" }, + { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" }, + { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" }, + { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" }, + { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" }, + { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" }, + { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" }, + { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" }, + { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" }, + // old numbers used in the beginning http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 + { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }, + // http://tools.ietf.org/html/draft-ietf-tls-chacha20-poly1305 + { 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" }, + { 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" }, + // http://tools.ietf.org/html/draft-josefsson-salsa20-tls + { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" }, + { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" }, + { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" }, + { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" }, + { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" }, + { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" }, + { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" }, + { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" }, + { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" }, + // these from http://www.mozilla.org/projects/security/pki/nss/ssl/fips-ssl-ciphersuites.html + { 0xFEFE, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"}, + { 0xFEFF, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" }, + { 0xFFE0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" }, + { 0xFFE1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"}, + // note that ciphersuites of {0x00????} are TLS cipher suites in + // a sslv2 client hello message; the ???? above is the two-byte + // tls cipher suite id + { 0x010080, "SSL2_RC4_128_WITH_MD5" }, + { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" }, + { 0x030080, "SSL2_RC2_128_CBC_WITH_MD5" }, + { 0x040080, "SSL2_RC2_128_CBC_EXPORT40_WITH_MD5" }, + { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" }, + { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" }, + { 0x0700C0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" }, + { 0x080080, "SSL2_RC4_64_WITH_MD5" }, + // Microsoft's old PCT protocol. These are from Eric Rescorla's book "SSL and TLS" + { 0x800001, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509" }, + { 0x800003, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509_CHAIN" }, + { 0x810001, "PCT_SSL_HASH_TYPE | PCT1_HASH_MD5" }, + { 0x810003, "PCT_SSL_HASH_TYPE | PCT1_HASH_SHA" }, + { 0x820001, "PCT_SSL_EXCH_TYPE | PCT1_EXCH_RSA_PKCS1" }, + { 0x830004, "PCT_SSL_CIPHER_TYPE_1ST_HALF | PCT1_CIPHER_RC4" }, + { 0x842840, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_40 | PCT1_MAC_BITS_128" }, + { 0x848040, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_128 | PCT1_MAC_BITS_128" }, + { 0x8F8001, "PCT_SSL_COMPAT | PCT_VERSION_1" }, + }; + } +} diff --git a/src/StreamExtended/Models/SslExtension.cs b/src/StreamExtended/Models/SslExtension.cs new file mode 100644 index 000000000..9c3fe9d49 --- /dev/null +++ b/src/StreamExtended/Models/SslExtension.cs @@ -0,0 +1,55 @@ +namespace StreamExtended.Models +{ + /// + /// The SSL extension information. + /// + public class SslExtension + { + /// + /// Gets the value. + /// + /// + /// The value. + /// + public int Value { get; } + + /// + /// Gets the name. + /// + /// + /// The name. + /// + public string Name { get; } + + /// + /// Gets the data. + /// + /// + /// The data. + /// + public string Data { get; } + + /// + /// Gets the position. + /// + /// + /// The position. + /// + public int Position { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The value. + /// The name. + /// The data. + /// The position. + public SslExtension(int value, string name, string data, int position) + { + Value = value; + Name = name; + Data = data; + Position = position; + } + } +} \ No newline at end of file diff --git a/src/StreamExtended/Network/ClientHelloAlpnAdderStream.cs b/src/StreamExtended/Network/ClientHelloAlpnAdderStream.cs new file mode 100644 index 000000000..e057b5903 --- /dev/null +++ b/src/StreamExtended/Network/ClientHelloAlpnAdderStream.cs @@ -0,0 +1,137 @@ +using System.Diagnostics; +using System.IO; +using System.Threading; + +namespace StreamExtended.Network +{ + public class ClientHelloAlpnAdderStream : Stream + { + private readonly CustomBufferedStream stream; + private readonly IBufferPool bufferPool; + + private bool called; + + public ClientHelloAlpnAdderStream(CustomBufferedStream stream, IBufferPool bufferPool) + { + this.stream = stream; + } + + public override void Flush() + { + stream.Flush(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + return stream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + stream.SetLength(value); + } + + [DebuggerStepThrough] + public override int Read(byte[] buffer, int offset, int count) + { + return stream.Read(buffer, offset, count); + } + + public override void Write(byte[] buffer, int offset, int count) + { + if (called) + { + stream.Write(buffer, offset, count); + return; + } + + called = true; + var ms = new MemoryStream(buffer, offset, count); + + //this can be non async, because reads from a memory stream + var cts = new CancellationTokenSource(); + var clientHello = SslTools.PeekClientHello(new CustomBufferedStream(ms, bufferPool, (int)ms.Length), bufferPool, cts.Token).Result; + if (clientHello != null) + { + // 0x00 0x10: ALPN identifier + // 0x00 0x0e: length of ALPN data + // 0x00 0x0c: length of ALPN data again:) + var dataToAdd = new byte[] + { + 0x0, 0x10, 0x0, 0xE, 0x0, 0xC, + 2, (byte)'h', (byte)'2', + 8, (byte)'h', (byte)'t', (byte)'t', (byte)'p', (byte)'/', (byte)'1', (byte)'.', (byte)'1' + }; + + int newByteCount = clientHello.Extensions == null ? dataToAdd.Length + 2 : dataToAdd.Length; + var buffer2 = new byte[buffer.Length + newByteCount]; + + for (int i = 0; i < buffer.Length; i++) + { + buffer2[i] = buffer[i]; + } + + //this is a hacky solution, but works + int length = (buffer[offset + 3] << 8) + buffer[offset + 4]; + length += newByteCount; + buffer2[offset + 3] = (byte)(length >> 8); + buffer2[offset + 4] = (byte)length; + + length = (buffer[offset + 6] << 16) + (buffer[offset + 7] << 8) + buffer[offset + 8]; + length += newByteCount; + buffer2[offset + 6] = (byte)(length >> 16); + buffer2[offset + 7] = (byte)(length >> 8); + buffer2[offset + 8] = (byte)length; + + int pos = offset + clientHello.EntensionsStartPosition; + int endPos = offset + clientHello.ClientHelloLength; + if (clientHello.Extensions != null) + { + // update ALPN length + length = (buffer[pos] << 8) + buffer[pos + 1]; + length += newByteCount; + buffer2[pos] = (byte)(length >> 8); + buffer2[pos + 1] = (byte)length; + } + else + { + // add ALPN length + length = dataToAdd.Length; + buffer2[pos] = (byte)(length >> 8); + buffer2[pos + 1] = (byte)length; + endPos += 2; + } + + for (int i = 0; i < dataToAdd.Length; i++) + { + buffer2[endPos + i] = dataToAdd[i]; + } + + // copy the reamining data if any + for (int i = clientHello.ClientHelloLength; i < count; i++) + { + buffer2[offset + newByteCount + i] = buffer[offset + i]; + } + + buffer = buffer2; + count += newByteCount; + } + + stream.Write(buffer, offset, count); + } + + public override bool CanRead => stream.CanRead; + + public override bool CanSeek => stream.CanSeek; + + public override bool CanWrite => stream.CanWrite; + + public override long Length => stream.Length; + + public override long Position + { + get => stream.Position; + set => stream.Position = value; + } + } +} \ No newline at end of file diff --git a/src/StreamExtended/Network/CopyStream.cs b/src/StreamExtended/Network/CopyStream.cs new file mode 100644 index 000000000..a337c11fb --- /dev/null +++ b/src/StreamExtended/Network/CopyStream.cs @@ -0,0 +1,145 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended.Network +{ + /// + /// Copies the source stream to destination stream. + /// But this let users to peek and read the copying process. + /// + public class CopyStream : ICustomStreamReader, IDisposable + { + private readonly ICustomStreamReader reader; + + private readonly ICustomStreamWriter writer; + + private readonly IBufferPool bufferPool; + + public int BufferSize { get; } + + private int bufferLength; + + private byte[] buffer; + + private bool disposed; + + public int Available => reader.Available; + + public bool DataAvailable => reader.DataAvailable; + + public long ReadBytes { get; private set; } + + public CopyStream(ICustomStreamReader reader, ICustomStreamWriter writer, IBufferPool bufferPool, int bufferSize) + { + this.reader = reader; + this.writer = writer; + BufferSize = bufferSize; + buffer = bufferPool.GetBuffer(bufferSize); + this.bufferPool = bufferPool; + } + + public async Task FillBufferAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + await FlushAsync(cancellationToken); + return await reader.FillBufferAsync(cancellationToken); + } + + public byte PeekByteFromBuffer(int index) + { + return reader.PeekByteFromBuffer(index); + } + + public Task PeekByteAsync(int index, CancellationToken cancellationToken = default(CancellationToken)) + { + return reader.PeekByteAsync(index, cancellationToken); + } + + public Task PeekBytesAsync(byte[] buffer, int offset, int index, int size, CancellationToken cancellationToken = default(CancellationToken)) + { + return reader.PeekBytesAsync(buffer, offset, index, size, cancellationToken); + } + + public void Flush() + { + //send out the current data from from the buffer + if (bufferLength > 0) + { + writer.Write(buffer, 0, bufferLength); + bufferLength = 0; + } + } + + public async Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + //send out the current data from from the buffer + if (bufferLength > 0) + { + await writer.WriteAsync(buffer, 0, bufferLength, cancellationToken); + bufferLength = 0; + } + } + + public byte ReadByteFromBuffer() + { + byte b = reader.ReadByteFromBuffer(); + buffer[bufferLength++] = b; + ReadBytes++; + return b; + } + + public int Read(byte[] buffer, int offset, int count) + { + int result = reader.Read(buffer, offset, count); + if (result > 0) + { + if (bufferLength + result > BufferSize) + { + Flush(); + } + + Buffer.BlockCopy(buffer, offset, this.buffer, bufferLength, result); + bufferLength += result; + ReadBytes += result; + Flush(); + } + + return result; + } + + public async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default(CancellationToken)) + { + int result = await reader.ReadAsync(buffer, offset, count, cancellationToken); + if (result > 0) + { + if (bufferLength + result > BufferSize) + { + await FlushAsync(cancellationToken); + } + + Buffer.BlockCopy(buffer, offset, this.buffer, bufferLength, result); + bufferLength += result; + ReadBytes += result; + await FlushAsync(cancellationToken); + } + + return result; + } + + public Task ReadLineAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return CustomBufferedStream.ReadLineInternalAsync(this, bufferPool, cancellationToken); + } + + public void Dispose() + { + if (!disposed) + { + disposed = true; + var b = buffer; + buffer = null; + bufferPool.ReturnBuffer(b); + } + } + } +} diff --git a/src/StreamExtended/Network/CustomBufferedPeekStream.cs b/src/StreamExtended/Network/CustomBufferedPeekStream.cs new file mode 100644 index 000000000..43a9d2ace --- /dev/null +++ b/src/StreamExtended/Network/CustomBufferedPeekStream.cs @@ -0,0 +1,151 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended.Network +{ + internal class CustomBufferedPeekStream : ICustomStreamReader + { + private readonly IBufferPool bufferPool; + private readonly ICustomStreamReader baseStream; + + internal int Position { get; private set; } + + internal CustomBufferedPeekStream(ICustomStreamReader baseStream, IBufferPool bufferPool, int startPosition = 0) + { + this.bufferPool = bufferPool; + this.baseStream = baseStream; + Position = startPosition; + } + + int ICustomStreamReader.BufferSize => baseStream.BufferSize; + + /// + /// Gets a value indicating whether data is available. + /// + bool ICustomStreamReader.DataAvailable => Available > 0; + + /// + /// Gets the available data size. + /// + public int Available => baseStream.Available - Position; + + internal async Task EnsureBufferLength(int length, CancellationToken cancellationToken) + { + var val = await baseStream.PeekByteAsync(Position + length - 1, cancellationToken); + return val != -1; + } + + internal byte ReadByte() + { + return baseStream.PeekByteFromBuffer(Position++); + } + + internal int ReadInt16() + { + int i1 = ReadByte(); + int i2 = ReadByte(); + return (i1 << 8) + i2; + } + + internal int ReadInt24() + { + int i1 = ReadByte(); + int i2 = ReadByte(); + int i3 = ReadByte(); + return (i1 << 16) + (i2 << 8) + i3; + } + + internal byte[] ReadBytes(int length) + { + var buffer = new byte[length]; + for (int i = 0; i < buffer.Length; i++) + { + buffer[i] = ReadByte(); + } + + return buffer; + } + + /// + /// Fills the buffer asynchronous. + /// + /// + Task ICustomStreamReader.FillBufferAsync(CancellationToken cancellationToken) + { + return baseStream.FillBufferAsync(cancellationToken); + } + + /// + /// Peeks a byte from buffer. + /// + /// The index. + /// + byte ICustomStreamReader.PeekByteFromBuffer(int index) + { + return baseStream.PeekByteFromBuffer(index); + } + + /// + /// Peeks bytes asynchronous. + /// + /// The buffer to copy. + /// The offset where copying. + /// The index. + /// The cancellation token. + /// + Task ICustomStreamReader.PeekBytesAsync(byte[] buffer, int offset, int index, int size, CancellationToken cancellationToken) + { + return baseStream.PeekBytesAsync(buffer, offset, index, size, cancellationToken); + } + + /// + /// Peeks a byte asynchronous. + /// + /// The index. + /// The cancellation token. + /// + Task ICustomStreamReader.PeekByteAsync(int index, CancellationToken cancellationToken) + { + return baseStream.PeekByteAsync(index, cancellationToken); + } + + /// + /// Reads a byte from buffer. + /// + /// + /// Buffer is empty + byte ICustomStreamReader.ReadByteFromBuffer() + { + return ReadByte(); + } + + int ICustomStreamReader.Read(byte[] buffer, int offset, int count) + { + return baseStream.Read(buffer, offset, count); + } + + /// + /// Reads the asynchronous. + /// + /// The buffer. + /// The offset. + /// The count. + /// The cancellation token. + /// + Task ICustomStreamReader.ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return baseStream.ReadAsync(buffer, offset, count, cancellationToken); + } + + /// + /// Read a line from the byte stream + /// + /// + /// + Task ICustomStreamReader.ReadLineAsync(CancellationToken cancellationToken) + { + return CustomBufferedStream.ReadLineInternalAsync(this, bufferPool, cancellationToken); + } + + } +} diff --git a/src/StreamExtended/Network/CustomBufferedStream.cs b/src/StreamExtended/Network/CustomBufferedStream.cs new file mode 100644 index 000000000..11451485d --- /dev/null +++ b/src/StreamExtended/Network/CustomBufferedStream.cs @@ -0,0 +1,671 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended.Network +{ + /// + /// A custom network stream inherited from stream + /// with an underlying read buffer supporting both read/write + /// of UTF-8 encoded string or raw bytes asynchronously from last read position. + /// + /// + public class CustomBufferedStream : Stream, ICustomStreamReader + { + private readonly Stream baseStream; + private readonly bool leaveOpen; + private byte[] streamBuffer; + + // default to UTF-8 + private static readonly Encoding encoding = Encoding.UTF8; + + private int bufferLength; + + private int bufferPos; + + private bool disposed; + + private bool closed; + + private readonly IBufferPool bufferPool; + + public int BufferSize { get; } + + public event EventHandler DataRead; + + public event EventHandler DataWrite; + + public bool IsClosed => closed; + + /// + /// Initializes a new instance of the class. + /// + /// The base stream. + /// Bufferpool. + /// Size of the buffer. + /// to leave the stream open after disposing the object; otherwise, . + public CustomBufferedStream(Stream baseStream, IBufferPool bufferPool, int bufferSize, bool leaveOpen = false) + { + this.baseStream = baseStream; + BufferSize = bufferSize; + this.leaveOpen = leaveOpen; + streamBuffer = bufferPool.GetBuffer(bufferSize); + this.bufferPool = bufferPool; + } + + /// + /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device. + /// + public override void Flush() + { + baseStream.Flush(); + } + + /// + /// When overridden in a derived class, sets the position within the current stream. + /// + /// A byte offset relative to the parameter. + /// A value of type indicating the reference point used to obtain the new position. + /// + /// The new position within the current stream. + /// + public override long Seek(long offset, SeekOrigin origin) + { + bufferLength = 0; + bufferPos = 0; + return baseStream.Seek(offset, origin); + } + + /// + /// When overridden in a derived class, sets the length of the current stream. + /// + /// The desired length of the current stream in bytes. + public override void SetLength(long value) + { + baseStream.SetLength(value); + } + + /// + /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. + /// + /// An array of bytes. When this method returns, the buffer contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source. + /// The zero-based byte offset in at which to begin storing the data read from the current stream. + /// The maximum number of bytes to be read from the current stream. + /// + /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached. + /// + public override int Read(byte[] buffer, int offset, int count) + { + if (bufferLength == 0) + { + FillBuffer(); + } + + int available = Math.Min(bufferLength, count); + if (available > 0) + { + Buffer.BlockCopy(streamBuffer, bufferPos, buffer, offset, available); + bufferPos += available; + bufferLength -= available; + } + + return available; + } + + /// + /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. + /// + /// An array of bytes. This method copies bytes from to the current stream. + /// The zero-based byte offset in at which to begin copying bytes to the current stream. + /// The number of bytes to be written to the current stream. + [DebuggerStepThrough] + public override void Write(byte[] buffer, int offset, int count) + { + OnDataWrite(buffer, offset, count); + baseStream.Write(buffer, offset, count); + } + + /// + /// Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. + /// + /// The stream to which the contents of the current stream will be copied. + /// The size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920. + /// The token to monitor for cancellation requests. The default value is . + /// + /// A task that represents the asynchronous copy operation. + /// + public override async Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken = default(CancellationToken)) + { + if (bufferLength > 0) + { + await destination.WriteAsync(streamBuffer, bufferPos, bufferLength, cancellationToken); + + bufferLength = 0; + } + + await base.CopyToAsync(destination, bufferSize, cancellationToken); + } + + /// + /// Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests. + /// + /// The token to monitor for cancellation requests. The default value is . + /// + /// A task that represents the asynchronous flush operation. + /// + public override Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return baseStream.FlushAsync(cancellationToken); + } + + /// + /// Asynchronously reads a sequence of bytes from the current stream, + /// advances the position within the stream by the number of bytes read, + /// and monitors cancellation requests. + /// + /// The buffer to write the data into. + /// The byte offset in at which + /// to begin writing data from the stream. + /// The maximum number of bytes to read. + /// The token to monitor for cancellation requests. + /// The default value is . + /// + /// A task that represents the asynchronous read operation. + /// The value of the parameter contains the total + /// number of bytes read into the buffer. + /// The result value can be less than the number of bytes + /// requested if the number of bytes currently available is + /// less than the requested number, or it can be 0 (zero) + /// if the end of the stream has been reached. + /// + public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default(CancellationToken)) + { + if (bufferLength == 0) + { + await FillBufferAsync(cancellationToken); + } + + int available = Math.Min(bufferLength, count); + if (available > 0) + { + Buffer.BlockCopy(streamBuffer, bufferPos, buffer, offset, available); + bufferPos += available; + bufferLength -= available; + } + + return available; + } + + /// + /// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. + /// + /// + /// The unsigned byte cast to an Int32, or -1 if at the end of the stream. + /// + public override int ReadByte() + { + if (bufferLength == 0) + { + FillBuffer(); + } + + if (bufferLength == 0) + { + return -1; + } + + bufferLength--; + return streamBuffer[bufferPos++]; + } + + /// + /// Peeks a byte asynchronous. + /// + /// The index. + /// The cancellation token. + /// + public async Task PeekByteAsync(int index, CancellationToken cancellationToken = default(CancellationToken)) + { + if (Available <= index) + { + await FillBufferAsync(cancellationToken); + } + + //When index is greater than the buffer size + if (streamBuffer.Length <= index) + { + throw new Exception("Requested Peek index exceeds the buffer size. Consider increasing the buffer size."); + } + + //When index is greater than the buffer size + if (Available <= index) + { + return -1; + } + + return streamBuffer[bufferPos + index]; + } + + /// + /// Peeks bytes asynchronous. + /// + /// The buffer to copy. + /// The offset where copying. + /// The index. + /// The cancellation token. + /// + public async Task PeekBytesAsync(byte[] buffer, int offset, int index, int size, CancellationToken cancellationToken = default(CancellationToken)) + { + if (Available <= index) + { + await FillBufferAsync(cancellationToken); + } + + //When index is greater than the buffer size + if (streamBuffer.Length <= (index + size)) + { + throw new Exception("Requested Peek index and size exceeds the buffer size. Consider increasing the buffer size."); + } + + if (Available <= (index + size)) + { + return -1; + } + + Buffer.BlockCopy(streamBuffer, index, buffer, offset, size); + + return size; + } + + /// + /// Peeks a byte from buffer. + /// + /// The index. + /// + /// Index is out of buffer size + public byte PeekByteFromBuffer(int index) + { + if (bufferLength <= index) + { + throw new Exception("Index is out of buffer size"); + } + + return streamBuffer[bufferPos + index]; + } + + /// + /// Reads a byte from buffer. + /// + /// + /// Buffer is empty + public byte ReadByteFromBuffer() + { + if (bufferLength == 0) + { + throw new Exception("Buffer is empty"); + } + + bufferLength--; + return streamBuffer[bufferPos++]; + } + + /// + /// Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests. + /// + /// The buffer to write data from. + /// The zero-based byte offset in from which to begin copying bytes to the stream. + /// The maximum number of bytes to write. + /// The token to monitor for cancellation requests. The default value is . + /// + /// A task that represents the asynchronous write operation. + /// + [DebuggerStepThrough] + public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default(CancellationToken)) + { + OnDataWrite(buffer, offset, count); + + await baseStream.WriteAsync(buffer, offset, count, cancellationToken); + } + + /// + /// Writes a byte to the current position in the stream and advances the position within the stream by one byte. + /// + /// The byte to write to the stream. + public override void WriteByte(byte value) + { + var buffer = bufferPool.GetBuffer(BufferSize); + try + { + buffer[0] = value; + OnDataWrite(buffer, 0, 1); + baseStream.Write(buffer, 0, 1); + } + finally + { + bufferPool.ReturnBuffer(buffer); + } + } + + protected virtual void OnDataWrite(byte[] buffer, int offset, int count) + { + DataWrite?.Invoke(this, new DataEventArgs(buffer, offset, count)); + } + + protected virtual void OnDataRead(byte[] buffer, int offset, int count) + { + DataRead?.Invoke(this, new DataEventArgs(buffer, offset, count)); + } + + /// + /// Releases the unmanaged resources used by the and optionally releases the managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + closed = true; + if (!leaveOpen) + { + baseStream.Dispose(); + } + + var buffer = streamBuffer; + streamBuffer = null; + bufferPool.ReturnBuffer(buffer); + } + } + + /// + /// When overridden in a derived class, gets a value indicating whether the current stream supports reading. + /// + public override bool CanRead => baseStream.CanRead; + + /// + /// When overridden in a derived class, gets a value indicating whether the current stream supports seeking. + /// + public override bool CanSeek => baseStream.CanSeek; + + /// + /// When overridden in a derived class, gets a value indicating whether the current stream supports writing. + /// + public override bool CanWrite => baseStream.CanWrite; + + /// + /// Gets a value that determines whether the current stream can time out. + /// + public override bool CanTimeout => baseStream.CanTimeout; + + /// + /// When overridden in a derived class, gets the length in bytes of the stream. + /// + public override long Length => baseStream.Length; + + /// + /// Gets a value indicating whether data is available. + /// + public bool DataAvailable => bufferLength > 0; + + /// + /// Gets the available data size. + /// + public int Available => bufferLength; + + /// + /// When overridden in a derived class, gets or sets the position within the current stream. + /// + public override long Position + { + get => baseStream.Position; + set => baseStream.Position = value; + } + + /// + /// Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. + /// + public override int ReadTimeout + { + get => baseStream.ReadTimeout; + set => baseStream.ReadTimeout = value; + } + + /// + /// Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. + /// + public override int WriteTimeout + { + get => baseStream.WriteTimeout; + set => baseStream.WriteTimeout = value; + } + + /// + /// Fills the buffer. + /// + public bool FillBuffer() + { + if (closed) + { + return false; + } + + if (bufferLength > 0) + { + //normally we fill the buffer only when it is empty, but sometimes we need more data + //move the remanining data to the beginning of the buffer + Buffer.BlockCopy(streamBuffer, bufferPos, streamBuffer, 0, bufferLength); + } + + bufferPos = 0; + + int readBytes = baseStream.Read(streamBuffer, bufferLength, streamBuffer.Length - bufferLength); + bool result = readBytes > 0; + if (result) + { + OnDataRead(streamBuffer, bufferLength, readBytes); + bufferLength += readBytes; + } + else + { + closed = true; + throw new EndOfStreamException(); + } + + return result; + + } + + /// + /// Fills the buffer asynchronous. + /// + /// The cancellation token. + /// + public async Task FillBufferAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + if (closed) + { + return false; + } + + if (bufferLength > 0) + { + //normally we fill the buffer only when it is empty, but sometimes we need more data + //move the remaining data to the beginning of the buffer + Buffer.BlockCopy(streamBuffer, bufferPos, streamBuffer, 0, bufferLength); + } + + int bytesToRead = streamBuffer.Length - bufferLength; + if (bytesToRead == 0) + { + return false; + } + + bufferPos = 0; + + int readBytes = await baseStream.ReadAsync(streamBuffer, bufferLength, bytesToRead, cancellationToken); + bool result = readBytes > 0; + if (result) + { + OnDataRead(streamBuffer, bufferLength, readBytes); + bufferLength += readBytes; + } + else + { + closed = true; + throw new EndOfStreamException(); + } + + return result; + } + + /// + /// Read a line from the byte stream + /// + /// + public Task ReadLineAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + return ReadLineInternalAsync(this, bufferPool, cancellationToken); + } + + /// + /// Read a line from the byte stream + /// + /// + internal static async Task ReadLineInternalAsync(ICustomStreamReader reader, IBufferPool bufferPool, CancellationToken cancellationToken = default(CancellationToken)) + { + byte lastChar = default(byte); + + int bufferDataLength = 0; + + // try to use buffer from the buffer pool, usually it is enough + var bufferPoolBuffer = bufferPool.GetBuffer(reader.BufferSize); + var buffer = bufferPoolBuffer; + + try + { + while (reader.DataAvailable || await reader.FillBufferAsync(cancellationToken)) + { + byte newChar = reader.ReadByteFromBuffer(); + buffer[bufferDataLength] = newChar; + + //if new line + if (newChar == '\n') + { + if (lastChar == '\r') + { + return encoding.GetString(buffer, 0, bufferDataLength - 1); + } + + return encoding.GetString(buffer, 0, bufferDataLength); + } + + bufferDataLength++; + + //store last char for new line comparison + lastChar = newChar; + + if (bufferDataLength == buffer.Length) + { + ResizeBuffer(ref buffer, bufferDataLength * 2); + } + } + } + finally + { + bufferPool.ReturnBuffer(bufferPoolBuffer); + } + + if (bufferDataLength == 0) + { + return null; + } + + return encoding.GetString(buffer, 0, bufferDataLength); + } + + /// + /// Read until the last new line, ignores the result + /// + /// + public async Task ReadAndIgnoreAllLinesAsync(CancellationToken cancellationToken = default(CancellationToken)) + { + while (!string.IsNullOrEmpty(await ReadLineAsync(cancellationToken))) + { + } + } + + /// + /// Increase size of buffer and copy existing content to new buffer + /// + /// + /// + private static void ResizeBuffer(ref byte[] buffer, long size) + { + var newBuffer = new byte[size]; + Buffer.BlockCopy(buffer, 0, newBuffer, 0, buffer.Length); + buffer = newBuffer; + } + +#if NET45 || NETSTANDARD2_0 + + /// + /// Base Stream.BeginRead will call this.Read and block thread (we don't want this, Network stream handles async) + /// In order to really async Reading Launch this.ReadAsync as Task will fire NetworkStream.ReadAsync + /// See Threads here : + /// https://github.com/justcoding121/Stream-Extended/pull/43 + /// https://github.com/justcoding121/Titanium-Web-Proxy/issues/575 + /// + /// + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var vAsyncResult = this.ReadAsync(buffer, offset, count); + + vAsyncResult.ContinueWith(pAsyncResult => + { + //use TaskExtended to pass State as AsyncObject + //callback will call EndRead (otherwise, it will block) + callback?.Invoke(new TaskResult(pAsyncResult, state)); + }); + + return vAsyncResult; + } + + /// + /// override EndRead to handle async Reading (see BeginRead comment) + /// + /// + public override int EndRead(IAsyncResult asyncResult) + { + return ((TaskResult)asyncResult).Result; + } + + + /// + /// Fix the .net bug with SslStream slow WriteAsync + /// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495 + /// Stream.BeginWrite + Stream.BeginRead uses the same SemaphoreSlim(1) + /// That's why we need to call NetworkStream.BeginWrite only (while read is waiting SemaphoreSlim) + /// + /// + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + var vAsyncResult = this.WriteAsync(buffer, offset, count); + + vAsyncResult.ContinueWith(pAsyncResult => + { + callback?.Invoke(new TaskResult(pAsyncResult, state)); + }); + + return vAsyncResult; + } + public override void EndWrite(IAsyncResult asyncResult) + { + ((TaskResult)asyncResult).GetResult(); + } + +#endif + } +} diff --git a/src/StreamExtended/Network/DataEventArgs.cs b/src/StreamExtended/Network/DataEventArgs.cs new file mode 100644 index 000000000..e12bc9d07 --- /dev/null +++ b/src/StreamExtended/Network/DataEventArgs.cs @@ -0,0 +1,32 @@ +using System; + +namespace StreamExtended.Network +{ + /// + /// Wraps the data sent/received event argument. + /// + public class DataEventArgs : EventArgs + { + public DataEventArgs(byte[] buffer, int offset, int count) + { + Buffer = buffer; + Offset = offset; + Count = count; + } + + /// + /// The buffer with data. + /// + public byte[] Buffer { get; } + + /// + /// Offset in buffer from which valid data begins. + /// + public int Offset { get; } + + /// + /// Length from offset in buffer with valid data. + /// + public int Count { get; } + } +} diff --git a/src/StreamExtended/Network/ICustomStreamReader.cs b/src/StreamExtended/Network/ICustomStreamReader.cs new file mode 100644 index 000000000..3d9848e34 --- /dev/null +++ b/src/StreamExtended/Network/ICustomStreamReader.cs @@ -0,0 +1,80 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended.Network +{ + /// + /// This concrete implemetation of interface acts as the source stream for CopyStream class. + /// + public interface ICustomStreamReader + { + int BufferSize { get; } + + int Available { get; } + + bool DataAvailable { get; } + + /// + /// Fills the buffer asynchronous. + /// + /// + Task FillBufferAsync(CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Peeks a byte from buffer. + /// + /// The index. + /// + /// Index is out of buffer size + byte PeekByteFromBuffer(int index); + + /// + /// Peeks a byte asynchronous. + /// + /// The index. + /// The cancellation token. + /// + Task PeekByteAsync(int index, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Peeks bytes asynchronous. + /// + /// The buffer to copy. + /// The offset where copying. + /// The index. + /// The cancellation token. + /// + Task PeekBytesAsync(byte[] buffer, int offset, int index, int size, CancellationToken cancellationToken = default(CancellationToken)); + + byte ReadByteFromBuffer(); + + /// + /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. + /// + /// An array of bytes. When this method returns, the buffer contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source. + /// The zero-based byte offset in at which to begin storing the data read from the current stream. + /// The maximum number of bytes to be read from the current stream. + /// + /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached. + /// + int Read(byte[] buffer, int offset, int count); + + /// + /// Read the specified number (or less) of raw bytes from the base stream to the given buffer to the specified offset + /// + /// + /// + /// + /// + /// The number of bytes read + Task ReadAsync(byte[] buffer, int offset, int bytesToRead, + CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Read a line from the byte stream + /// + /// + Task ReadLineAsync(CancellationToken cancellationToken = default(CancellationToken)); + } +} \ No newline at end of file diff --git a/src/StreamExtended/Network/ICustomStreamWriter.cs b/src/StreamExtended/Network/ICustomStreamWriter.cs new file mode 100644 index 000000000..8c73d0fac --- /dev/null +++ b/src/StreamExtended/Network/ICustomStreamWriter.cs @@ -0,0 +1,15 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended.Network +{ + /// + /// A concrete implementation of this interface is required when calling CopyStream. + /// + public interface ICustomStreamWriter + { + void Write(byte[] buffer, int i, int bufferLength); + + Task WriteAsync(byte[] buffer, int i, int bufferLength, CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/StreamExtended/Network/ServerHelloAlpnAdderStream.cs b/src/StreamExtended/Network/ServerHelloAlpnAdderStream.cs new file mode 100644 index 000000000..c4920bc7b --- /dev/null +++ b/src/StreamExtended/Network/ServerHelloAlpnAdderStream.cs @@ -0,0 +1,137 @@ +using System.Diagnostics; +using System.IO; +using System.Threading; + +namespace StreamExtended.Network +{ + public class ServerHelloAlpnAdderStream : Stream + { + private readonly IBufferPool bufferPool; + private readonly CustomBufferedStream stream; + + private bool called; + + public ServerHelloAlpnAdderStream(CustomBufferedStream stream, IBufferPool bufferPool) + { + this.bufferPool = bufferPool; + this.stream = stream; + } + + public override void Flush() + { + stream.Flush(); + } + + public override long Seek(long offset, SeekOrigin origin) + { + return stream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + stream.SetLength(value); + } + + [DebuggerStepThrough] + public override int Read(byte[] buffer, int offset, int count) + { + return stream.Read(buffer, offset, count); + } + + public override void Write(byte[] buffer, int offset, int count) + { + if (called) + { + stream.Write(buffer, offset, count); + return; + } + + called = true; + var ms = new MemoryStream(buffer, offset, count); + + //this can be non async, because reads from a memory stream + var cts = new CancellationTokenSource(); + var serverHello = SslTools.PeekServerHello(new CustomBufferedStream(ms, bufferPool, (int)ms.Length), bufferPool, cts.Token).Result; + if (serverHello != null) + { + // 0x00 0x10: ALPN identifier + // 0x00 0x0e: length of ALPN data + // 0x00 0x0c: length of ALPN data again:) + var dataToAdd = new byte[] + { + 0x0, 0x10, 0x0, 0x5, 0x0, 0x3, + 2, (byte)'h', (byte)'2' + }; + + int newByteCount = serverHello.Extensions == null ? dataToAdd.Length + 2 : dataToAdd.Length; + var buffer2 = new byte[buffer.Length + newByteCount]; + + for (int i = 0; i < buffer.Length; i++) + { + buffer2[i] = buffer[i]; + } + + //this is a hacky solution, but works + int length = (buffer[offset + 3] << 8) + buffer[offset + 4]; + length += newByteCount; + buffer2[offset + 3] = (byte)(length >> 8); + buffer2[offset + 4] = (byte)length; + + length = (buffer[offset + 6] << 16) + (buffer[offset + 7] << 8) + buffer[offset + 8]; + length += newByteCount; + buffer2[offset + 6] = (byte)(length >> 16); + buffer2[offset + 7] = (byte)(length >> 8); + buffer2[offset + 8] = (byte)length; + + int pos = offset + serverHello.EntensionsStartPosition; + int endPos = offset + serverHello.ServerHelloLength; + if (serverHello.Extensions != null) + { + // update ALPN length + length = (buffer[pos] << 8) + buffer[pos + 1]; + length += newByteCount; + buffer2[pos] = (byte)(length >> 8); + buffer2[pos + 1] = (byte)length; + } + else + { + // add ALPN length + length = dataToAdd.Length; + buffer2[pos] = (byte)(length >> 8); + buffer2[pos + 1] = (byte)length; + endPos += 2; + } + + for (int i = 0; i < dataToAdd.Length; i++) + { + buffer2[endPos + i] = dataToAdd[i]; + } + + // copy the reamining data if any + for (int i = serverHello.ServerHelloLength; i < count; i++) + { + buffer2[offset + newByteCount + i] = buffer[offset + i]; + } + + buffer = buffer2; + count += newByteCount; + } + + stream.Write(buffer, offset, count); + } + + public override bool CanRead => stream.CanRead; + + public override bool CanSeek => stream.CanSeek; + + public override bool CanWrite => stream.CanWrite; + + public override long Length => stream.Length; + + public override long Position + { + get => stream.Position; + set => stream.Position = value; + } + } +} \ No newline at end of file diff --git a/src/StreamExtended/Properties/AssemblyInfo.cs b/src/StreamExtended/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1faa07207 --- /dev/null +++ b/src/StreamExtended/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("StreamExtended.Properties")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StreamExtended.Properties")] +[assembly: AssemblyCopyright("Copyright © Titanium 2015-2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("5036e0b7-a0d0-4070-8eb0-72c129dee9a3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// + +[assembly: AssemblyVersion("1.0.1")] +[assembly: AssemblyFileVersion("1.0.1")] diff --git a/src/StreamExtended/ServerHelloInfo.cs b/src/StreamExtended/ServerHelloInfo.cs new file mode 100644 index 000000000..e7adc727b --- /dev/null +++ b/src/StreamExtended/ServerHelloInfo.cs @@ -0,0 +1,112 @@ +using StreamExtended.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StreamExtended +{ + /// + /// Wraps up the server SSL hello information. + /// + public class ServerHelloInfo + { + private static readonly string[] compressions = { + "null", + "DEFLATE" + }; + + public int HandshakeVersion { get; set; } + + public int MajorVersion { get; set; } + + public int MinorVersion { get; set; } + + public byte[] Random { get; set; } + + public DateTime Time + { + get + { + DateTime time = DateTime.MinValue; + if (Random.Length > 3) + { + time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) + .AddSeconds(((uint)Random[3] << 24) + ((uint)Random[2] << 16) + ((uint)Random[1] << 8) + (uint)Random[0]).ToLocalTime(); + } + + return time; + } + } + + public byte[] SessionId { get; set; } + + public int CipherSuite { get; set; } + + public byte CompressionMethod { get; set; } + + internal int ServerHelloLength { get; set; } + + internal int EntensionsStartPosition { get; set; } + + public Dictionary Extensions { get; set; } + + private static string SslVersionToString(int major, int minor) + { + string str = "Unknown"; + if (major == 3 && minor == 3) + str = "TLS/1.2"; + else if (major == 3 && minor == 2) + str = "TLS/1.1"; + else if (major == 3 && minor == 1) + str = "TLS/1.0"; + else if (major == 3 && minor == 0) + str = "SSL/3.0"; + else if (major == 2 && minor == 0) + str = "SSL/2.0"; + + return $"{major}.{minor} ({str})"; + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine($"A SSLv{HandshakeVersion}-compatible ServerHello handshake was found. Titanium extracted the parameters below."); + sb.AppendLine(); + sb.AppendLine($"Version: {SslVersionToString(MajorVersion, MinorVersion)}"); + sb.AppendLine($"Random: {string.Join(" ", Random.Select(x => x.ToString("X2")))}"); + sb.AppendLine($"\"Time\": {Time}"); + sb.AppendLine($"SessionID: {string.Join(" ", SessionId.Select(x => x.ToString("X2")))}"); + + if (Extensions != null) + { + sb.AppendLine("Extensions:"); + foreach (var extension in Extensions.Values.OrderBy(x => x.Position)) + { + sb.AppendLine($"{extension.Name}: {extension.Data}"); + } + } + + string compression = compressions.Length > CompressionMethod + ? compressions[CompressionMethod] + : $"unknown [0x{CompressionMethod:X2}]"; + sb.AppendLine($"Compression: {compression}"); + + sb.Append("Cipher:"); + if (!SslCiphers.Ciphers.TryGetValue(CipherSuite, out string cipherStr)) + { + cipherStr = "unknown"; + } + + sb.AppendLine($"[0x{CipherSuite:X4}] {cipherStr}"); + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/src/StreamExtended/SslExtensions.cs b/src/StreamExtended/SslExtensions.cs new file mode 100644 index 000000000..4bab3ce34 --- /dev/null +++ b/src/StreamExtended/SslExtensions.cs @@ -0,0 +1,440 @@ +using StreamExtended.Models; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StreamExtended +{ + internal class SslExtensions + { + internal static SslExtension GetExtension(int value, byte[] data, int position) + { + string name = GetExtensionName(value); + string dataStr = GetExtensionData(value, data); + return new SslExtension(value, name, dataStr, position); + } + + private static string GetExtensionData(int value, byte[] data) + { + //https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml + switch (value) + { + case 0: + var stringBuilder = new StringBuilder(); + int index = 2; + while (index < data.Length) + { + int nameType = data[index]; + int count = (data[index + 1] << 8) + data[index + 2]; + string str = Encoding.ASCII.GetString(data, index + 3, count); + if (nameType == 0) + { + stringBuilder.AppendFormat("{0}{1}", stringBuilder.Length > 1 ? "; " : string.Empty, str); + } + + index += 3 + count; + } + return stringBuilder.ToString(); + case 5: + if (data.Length == 5 && data[0] == 1 && data[1] == 0 && data[2] == 0 && data[3] == 0 && data[4] == 0) + { + return "OCSP - Implicit Responder"; + } + + return ByteArrayToString(data); + case 10: + return GetSupportedGroup(data); + case 11: + return GetEcPointFormats(data); + case 13: + return GetSignatureAlgorithms(data); + case 16: + return GetApplicationLayerProtocolNegotiation(data); + case 35655: + return $"{data.Length} bytes"; + default: + return ByteArrayToString(data); + } + } + + private static string GetSupportedGroup(byte[] data) + { + //https://datatracker.ietf.org/doc/draft-ietf-tls-rfc4492bis/?include_text=1 + List list = new List(); + if (data.Length < 2) + { + return string.Empty; + } + + int i = 2; + while (i < data.Length - 1) + { + int namedCurve = (data[i] << 8) + data[i + 1]; + switch (namedCurve) + { + case 1: + list.Add("sect163k1 [0x1]"); //deprecated + break; + case 2: + list.Add("sect163r1 [0x2]"); //deprecated + break; + case 3: + list.Add("sect163r2 [0x3]"); //deprecated + break; + case 4: + list.Add("sect193r1 [0x4]"); //deprecated + break; + case 5: + list.Add("sect193r2 [0x5]"); //deprecated + break; + case 6: + list.Add("sect233k1 [0x6]"); //deprecated + break; + case 7: + list.Add("sect233r1 [0x7]"); //deprecated + break; + case 8: + list.Add("sect239k1 [0x8]"); //deprecated + break; + case 9: + list.Add("sect283k1 [0x9]"); //deprecated + break; + case 10: + list.Add("sect283r1 [0xA]"); //deprecated + break; + case 11: + list.Add("sect409k1 [0xB]"); //deprecated + break; + case 12: + list.Add("sect409r1 [0xC]"); //deprecated + break; + case 13: + list.Add("sect571k1 [0xD]"); //deprecated + break; + case 14: + list.Add("sect571r1 [0xE]"); //deprecated + break; + case 15: + list.Add("secp160k1 [0xF]"); //deprecated + break; + case 16: + list.Add("secp160r1 [0x10]"); //deprecated + break; + case 17: + list.Add("secp160r2 [0x11]"); //deprecated + break; + case 18: + list.Add("secp192k1 [0x12]"); //deprecated + break; + case 19: + list.Add("secp192r1 [0x13]"); //deprecated + break; + case 20: + list.Add("secp224k1 [0x14]"); //deprecated + break; + case 21: + list.Add("secp224r1 [0x15]"); //deprecated + break; + case 22: + list.Add("secp256k1 [0x16]"); //deprecated + break; + case 23: + list.Add("secp256r1 [0x17]"); + break; + case 24: + list.Add("secp384r1 [0x18]"); + break; + case 25: + list.Add("secp521r1 [0x19]"); + break; + case 26: + list.Add("brainpoolP256r1 [0x1A]"); + break; + case 27: + list.Add("brainpoolP384r1 [0x1B]"); + break; + case 28: + list.Add("brainpoolP512r1 [0x1C]"); + break; + case 29: + list.Add("x25519 [0x1D]"); + break; + case 30: + list.Add("x448 [0x1E]"); + break; + case 256: + list.Add("ffdhe2048 [0x0100]"); + break; + case 257: + list.Add("ffdhe3072 [0x0101]"); + break; + case 258: + list.Add("ffdhe4096 [0x0102]"); + break; + case 259: + list.Add("ffdhe6144 [0x0103]"); + break; + case 260: + list.Add("ffdhe8192 [0x0104]"); + break; + case 65281: + list.Add("arbitrary_explicit_prime_curves [0xFF01]"); //deprecated + break; + case 65282: + list.Add("arbitrary_explicit_char2_curves [0xFF02]"); //deprecated + break; + default: + list.Add($"unknown [0x{namedCurve:X4}]"); + break; + } + + i += 2; + } + + return string.Join(", ", list.ToArray()); + } + + private static string GetEcPointFormats(byte[] data) + { + List list = new List(); + if (data.Length < 1) + { + return string.Empty; + } + + int i = 1; + while (i < data.Length) + { + switch (data[i]) + { + case 0: + list.Add("uncompressed [0x0]"); + break; + case 1: + list.Add("ansiX962_compressed_prime [0x1]"); + break; + case 2: + list.Add("ansiX962_compressed_char2 [0x2]"); + break; + default: + list.Add($"unknown [0x{data[i]:X2}]"); + break; + } + + i += 2; + } + + return string.Join(", ", list.ToArray()); + } + + private static string GetSignatureAlgorithms(byte[] data) + { + // https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml + int num = (data[0] << 8) + data[1]; + var sb = new StringBuilder(); + int index = 2; + while (index < num + 2) + { + switch (data[index]) + { + case 0: + sb.Append("none"); + break; + case 1: + sb.Append("md5"); + break; + case 2: + sb.Append("sha1"); + break; + case 3: + sb.Append("sha224"); + break; + case 4: + sb.Append("sha256"); + break; + case 5: + sb.Append("sha384"); + break; + case 6: + sb.Append("sha512"); + break; + case 8: + sb.Append("Intrinsic"); + break; + default: + sb.AppendFormat("Unknown[0x{0:X2}]", data[index]); + break; + } + + sb.AppendFormat("_"); + switch (data[index + 1]) + { + case 0: + sb.Append("anonymous"); + break; + case 1: + sb.Append("rsa"); + break; + case 2: + sb.Append("dsa"); + break; + case 3: + sb.Append("ecdsa"); + break; + case 7: + sb.Append("ed25519"); + break; + case 8: + sb.Append("ed448"); + break; + default: + sb.AppendFormat("Unknown[0x{0:X2}]", data[index + 1]); + break; + } + + sb.AppendFormat(", "); + index += 2; + } + + if (sb.Length > 1) + sb.Length -= 2; + + return sb.ToString(); + } + + private static string GetApplicationLayerProtocolNegotiation(byte[] data) + { + List stringList = new List(); + int index = 2; + while (index < data.Length) + { + int count = data[index]; + stringList.Add(Encoding.ASCII.GetString(data, index + 1, count)); + index += 1 + count; + } + + return string.Join(", ", stringList.ToArray()); + } + + private static string GetExtensionName(int value) + { + //https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml + switch (value) + { + case 0: + return "server_name"; + case 1: + return "max_fragment_length"; + case 2: + return "client_certificate_url"; + case 3: + return "trusted_ca_keys"; + case 4: + return "truncated_hmac"; + case 5: + return "status_request"; + case 6: + return "user_mapping"; + case 7: + return "client_authz"; + case 8: + return "server_authz"; + case 9: + return "cert_type"; + case 10: + return "supported_groups"; // renamed from "elliptic_curves" (RFC 7919 / TLS 1.3) + case 11: + return "ec_point_formats"; + case 12: + return "srp"; + case 13: + return "signature_algorithms"; + case 14: + return "use_srtp"; + case 15: + return "heartbeat"; + case 16: + return "ALPN"; // application_layer_protocol_negotiation + case 17: + return "status_request_v2"; + case 18: + return "signed_certificate_timestamp"; + case 19: + return "client_certificate_type"; + case 20: + return "server_certificate_type"; + case 21: + return "padding"; + case 22: + return "encrypt_then_mac"; + case 23: + return "extended_master_secret"; + case 24: + return "token_binding"; // TEMPORARY - registered 2016-02-04, extension registered 2017-01-12, expires 2018-02-04 + case 25: + return "cached_info"; + case 26: + return "quic_transports_parameters"; // Not yet assigned by IANA (QUIC-TLS Draft04) + case 35: + return "SessionTicket TLS"; + // TLS 1.3 draft: https://tools.ietf.org/html/draft-ietf-tls-tls13 + case 40: + return "key_share"; + case 41: + return "pre_shared_key"; + case 42: + return "early_data"; + case 43: + return "supported_versions"; + case 44: + return "cookie"; + case 45: + return "psk_key_exchange_modes"; + case 46: + return "ticket_early_data_info"; + case 47: + return "certificate_authorities"; + case 48: + return "oid_filters"; + case 49: + return "post_handshake_auth"; + case 2570: // 0a0a + case 6682: // 1a1a + case 10794: // 2a2a + case 14906: // 3a3a + case 19018: // 4a4a + case 23130: // 5a5a + case 27242: // 6a6a + case 31354: // 7a7a + case 35466: // 8a8a + case 39578: // 9a9a + case 43690: // aaaa + case 47802: // baba + case 51914: // caca + case 56026: // dada + case 60138: // eaea + case 64250: // fafa + return "Reserved (GREASE)"; + case 13172: + return "next_protocol_negotiation"; + case 30031: + return "channel_id_old"; // Google + case 30032: + return "channel_id"; // Google + case 35655: + return "draft-agl-tls-padding"; + case 65281: + return "renegotiation_info"; + case 65282: + return "Draft version of TLS 1.3"; // for experimentation only https://www.ietf.org/mail-archive/web/tls/current/msg20853.html + default: + return $"unknown_{value:x2}"; + } + } + + private static string ByteArrayToString(byte[] data) + { + return string.Join(" ", data.Select(x => x.ToString("X2"))); + } + } +} diff --git a/src/StreamExtended/SslTools.cs b/src/StreamExtended/SslTools.cs new file mode 100644 index 000000000..cd2ccdbec --- /dev/null +++ b/src/StreamExtended/SslTools.cs @@ -0,0 +1,383 @@ +using StreamExtended.Models; +using StreamExtended.Network; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended +{ + /// + /// Use this class to peek SSL client/server hello information. + /// + public class SslTools + { + /// + /// Is the given stream starts with an SSL client hello? + /// + /// + /// + /// + /// + public static async Task IsClientHello(CustomBufferedStream stream, IBufferPool bufferPool, CancellationToken cancellationToken) + { + var clientHello = await PeekClientHello(stream, bufferPool, cancellationToken); + return clientHello != null; + } + + /// + /// Peek the SSL client hello information. + /// + /// + /// + /// + /// + public static async Task PeekClientHello(CustomBufferedStream clientStream, IBufferPool bufferPool, CancellationToken cancellationToken = default (CancellationToken)) + { + //detects the HTTPS ClientHello message as it is described in the following url: + //https://stackoverflow.com/questions/3897883/how-to-detect-an-incoming-ssl-https-handshake-ssl-wire-format + + int recordType = await clientStream.PeekByteAsync(0, cancellationToken); + if (recordType == -1) + { + return null; + } + + if ((recordType & 0x80) == 0x80) + { + //SSL 2 + var peekStream = new CustomBufferedPeekStream(clientStream, bufferPool, 1); + + // length value + minimum length + if (!await peekStream.EnsureBufferLength(10, cancellationToken)) + { + return null; + } + + int recordLength = ((recordType & 0x7f) << 8) + peekStream.ReadByte(); + if (recordLength < 9) + { + // Message body too short. + return null; + } + + if (peekStream.ReadByte() != 0x01) + { + // should be ClientHello + return null; + } + + int majorVersion = peekStream.ReadByte(); + int minorVersion = peekStream.ReadByte(); + + int ciphersCount = peekStream.ReadInt16() / 3; + int sessionIdLength = peekStream.ReadInt16(); + int randomLength = peekStream.ReadInt16(); + + if (!await peekStream.EnsureBufferLength(ciphersCount * 3 + sessionIdLength + randomLength, cancellationToken)) + { + return null; + } + + int[] ciphers = new int[ciphersCount]; + for (int i = 0; i < ciphers.Length; i++) + { + ciphers[i] = (peekStream.ReadByte() << 16) + (peekStream.ReadByte() << 8) + peekStream.ReadByte(); + } + + byte[] sessionId = peekStream.ReadBytes(sessionIdLength); + byte[] random = peekStream.ReadBytes(randomLength); + + var clientHelloInfo = new ClientHelloInfo + { + HandshakeVersion = 2, + MajorVersion = majorVersion, + MinorVersion = minorVersion, + Random = random, + SessionId = sessionId, + Ciphers = ciphers, + ClientHelloLength = peekStream.Position, + }; + + return clientHelloInfo; + } + else if (recordType == 0x16) + { + var peekStream = new CustomBufferedPeekStream(clientStream, bufferPool, 1); + + //should contain at least 43 bytes + // 2 version + 2 length + 1 type + 3 length(?) + 2 version + 32 random + 1 sessionid length + if (!await peekStream.EnsureBufferLength(43, cancellationToken)) + { + return null; + } + + //SSL 3.0 or TLS 1.0, 1.1 and 1.2 + int majorVersion = peekStream.ReadByte(); + int minorVersion = peekStream.ReadByte(); + + int recordLength = peekStream.ReadInt16(); + + if (peekStream.ReadByte() != 0x01) + { + // should be ClientHello + return null; + } + + var length = peekStream.ReadInt24(); + + majorVersion = peekStream.ReadByte(); + minorVersion = peekStream.ReadByte(); + + byte[] random = peekStream.ReadBytes(32); + length = peekStream.ReadByte(); + + // sessionid + 2 ciphersData length + if (!await peekStream.EnsureBufferLength(length + 2, cancellationToken)) + { + return null; + } + + byte[] sessionId = peekStream.ReadBytes(length); + + length = peekStream.ReadInt16(); + + // ciphersData + compressionData length + if (!await peekStream.EnsureBufferLength(length + 1, cancellationToken)) + { + return null; + } + + byte[] ciphersData = peekStream.ReadBytes(length); + int[] ciphers = new int[ciphersData.Length / 2]; + for (int i = 0; i < ciphers.Length; i++) + { + ciphers[i] = (ciphersData[2 * i] << 8) + ciphersData[2 * i + 1]; + } + + length = peekStream.ReadByte(); + if (length < 1) + { + return null; + } + + // compressionData + if (!await peekStream.EnsureBufferLength(length, cancellationToken)) + { + return null; + } + + byte[] compressionData = peekStream.ReadBytes(length); + + int extenstionsStartPosition = peekStream.Position; + + Dictionary extensions = null; + + if(extenstionsStartPosition < recordLength + 5) + { + extensions = await ReadExtensions(majorVersion, minorVersion, peekStream, bufferPool, cancellationToken); + } + + var clientHelloInfo = new ClientHelloInfo + { + HandshakeVersion = 3, + MajorVersion = majorVersion, + MinorVersion = minorVersion, + Random = random, + SessionId = sessionId, + Ciphers = ciphers, + CompressionData = compressionData, + ClientHelloLength = peekStream.Position, + EntensionsStartPosition = extenstionsStartPosition, + Extensions = extensions, + }; + + return clientHelloInfo; + } + + return null; + } + + + /// + /// Is the given stream starts with an SSL client hello? + /// + /// + /// + /// + /// + public static async Task IsServerHello(CustomBufferedStream stream, IBufferPool bufferPool, CancellationToken cancellationToken) + { + var serverHello = await PeekServerHello(stream, bufferPool, cancellationToken); + return serverHello != null; + } + /// + /// Peek the SSL client hello information. + /// + /// + /// + /// + /// + public static async Task PeekServerHello(CustomBufferedStream serverStream, IBufferPool bufferPool, CancellationToken cancellationToken = default(CancellationToken)) + { + //detects the HTTPS ClientHello message as it is described in the following url: + //https://stackoverflow.com/questions/3897883/how-to-detect-an-incoming-ssl-https-handshake-ssl-wire-format + + int recordType = await serverStream.PeekByteAsync(0, cancellationToken); + if (recordType == -1) + { + return null; + } + + if ((recordType & 0x80) == 0x80) + { + //SSL 2 + // not tested. SSL2 is deprecated + var peekStream = new CustomBufferedPeekStream(serverStream, bufferPool, 1); + + // length value + minimum length + if (!await peekStream.EnsureBufferLength(39, cancellationToken)) + { + return null; + } + + int recordLength = ((recordType & 0x7f) << 8) + peekStream.ReadByte(); + if (recordLength < 38) + { + // Message body too short. + return null; + } + + if (peekStream.ReadByte() != 0x04) + { + // should be ServerHello + return null; + } + + int majorVersion = peekStream.ReadByte(); + int minorVersion = peekStream.ReadByte(); + + // 32 bytes random + 1 byte sessionId + 2 bytes cipherSuite + if (!await peekStream.EnsureBufferLength(35, cancellationToken)) + { + return null; + } + + byte[] random = peekStream.ReadBytes(32); + byte[] sessionId = peekStream.ReadBytes(1); + int cipherSuite = peekStream.ReadInt16(); + + var serverHelloInfo = new ServerHelloInfo + { + HandshakeVersion = 2, + MajorVersion = majorVersion, + MinorVersion = minorVersion, + Random = random, + SessionId = sessionId, + CipherSuite = cipherSuite, + ServerHelloLength = peekStream.Position, + }; + + return serverHelloInfo; + } + else if (recordType == 0x16) + { + var peekStream = new CustomBufferedPeekStream(serverStream, bufferPool, 1); + + //should contain at least 43 bytes + // 2 version + 2 length + 1 type + 3 length(?) + 2 version + 32 random + 1 sessionid length + if (!await peekStream.EnsureBufferLength(43, cancellationToken)) + { + return null; + } + + //SSL 3.0 or TLS 1.0, 1.1 and 1.2 + int majorVersion = peekStream.ReadByte(); + int minorVersion = peekStream.ReadByte(); + + int recordLength = peekStream.ReadInt16(); + + if (peekStream.ReadByte() != 0x02) + { + // should be ServerHello + return null; + } + + var length = peekStream.ReadInt24(); + + majorVersion = peekStream.ReadByte(); + minorVersion = peekStream.ReadByte(); + + byte[] random = peekStream.ReadBytes(32); + length = peekStream.ReadByte(); + + // sessionid + cipherSuite + compressionMethod + if (!await peekStream.EnsureBufferLength(length + 2 + 1, cancellationToken)) + { + return null; + } + + byte[] sessionId = peekStream.ReadBytes(length); + + int cipherSuite = peekStream.ReadInt16(); + byte compressionMethod = peekStream.ReadByte(); + + int extenstionsStartPosition = peekStream.Position; + + Dictionary extensions = null; + + if (extenstionsStartPosition < recordLength + 5) + { + extensions = await ReadExtensions(majorVersion, minorVersion, peekStream, bufferPool, cancellationToken); + } + + var serverHelloInfo = new ServerHelloInfo + { + HandshakeVersion = 3, + MajorVersion = majorVersion, + MinorVersion = minorVersion, + Random = random, + SessionId = sessionId, + CipherSuite = cipherSuite, + CompressionMethod = compressionMethod, + ServerHelloLength = peekStream.Position, + EntensionsStartPosition = extenstionsStartPosition, + Extensions = extensions, + }; + + return serverHelloInfo; + } + + return null; + } + + private static async Task> ReadExtensions(int majorVersion, int minorVersion, CustomBufferedPeekStream peekStream, IBufferPool bufferPool, CancellationToken cancellationToken) + { + Dictionary extensions = null; + if (majorVersion > 3 || majorVersion == 3 && minorVersion >= 1) + { + if (await peekStream.EnsureBufferLength(2, cancellationToken)) + { + int extensionsLength = peekStream.ReadInt16(); + + if (await peekStream.EnsureBufferLength(extensionsLength, cancellationToken)) + { + extensions = new Dictionary(); + int idx = 0; + while (extensionsLength > 3) + { + int id = peekStream.ReadInt16(); + int length = peekStream.ReadInt16(); + byte[] data = peekStream.ReadBytes(length); + var extension = SslExtensions.GetExtension(id, data, idx++); + extensions[extension.Name] = extension; + extensionsLength -= 4 + length; + } + } + } + } + + return extensions; + } + } +} diff --git a/src/StreamExtended/StreamExtended.csproj b/src/StreamExtended/StreamExtended.csproj new file mode 100644 index 000000000..6d76ef985 --- /dev/null +++ b/src/StreamExtended/StreamExtended.csproj @@ -0,0 +1,21 @@ + + + + net45;netstandard2.0 + True + StrongKey.snk + 1.0.0 + false + Package Description + + + + + + + + + + + + \ No newline at end of file diff --git a/src/StreamExtended/StrongKey.snk b/src/StreamExtended/StrongKey.snk new file mode 100644 index 000000000..c7279e84f Binary files /dev/null and b/src/StreamExtended/StrongKey.snk differ diff --git a/src/StreamExtended/TaskExtended.cs b/src/StreamExtended/TaskExtended.cs new file mode 100644 index 000000000..7b362c02c --- /dev/null +++ b/src/StreamExtended/TaskExtended.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace StreamExtended +{ + /// + /// Mimic a Task but you can set AsyncState + /// + /// + public class TaskResult : IAsyncResult + { + Task Task; + object mAsyncState; + + public TaskResult(Task pTask, object state) + { + Task = pTask; + mAsyncState = state; + } + + public object AsyncState => mAsyncState; + public WaitHandle AsyncWaitHandle => ((IAsyncResult)Task).AsyncWaitHandle; + public bool CompletedSynchronously => ((IAsyncResult)Task).CompletedSynchronously; + public bool IsCompleted => Task.IsCompleted; + public void GetResult() { this.Task.GetAwaiter().GetResult(); } + } + + /// + /// Mimic a Task but you can set AsyncState + /// + /// + public class TaskResult : IAsyncResult + { + Task Task; + object mAsyncState; + + public TaskResult(Task pTask, object state) + { + Task = pTask; + mAsyncState = state; + } + + public object AsyncState => mAsyncState; + public WaitHandle AsyncWaitHandle => ((IAsyncResult)Task).AsyncWaitHandle; + public bool CompletedSynchronously => ((IAsyncResult)Task).CompletedSynchronously; + public bool IsCompleted => Task.IsCompleted; + public T Result => Task.Result; + } + + +} diff --git a/src/Titanium.Web.Proxy.sln b/src/Titanium.Web.Proxy.sln index 982c03221..496d621a8 100644 --- a/src/Titanium.Web.Proxy.sln +++ b/src/Titanium.Web.Proxy.sln @@ -23,7 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BC1E0789 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Titanium.Web.Proxy", "Titanium.Web.Proxy\Titanium.Web.Proxy.csproj", "{91018B6D-A7A9-45BE-9CB3-79CBB8B169A6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.Web.Proxy.UnitTests", "..\tests\Titanium.Web.Proxy.UnitTests\Titanium.Web.Proxy.UnitTests.csproj", "{B517E3D0-D03B-436F-AB03-34BA0D5321AF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Titanium.Web.Proxy.UnitTests", "..\tests\Titanium.Web.Proxy.UnitTests\Titanium.Web.Proxy.UnitTests.csproj", "{B517E3D0-D03B-436F-AB03-34BA0D5321AF}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Titanium.Web.Proxy.Examples.Basic", "..\examples\Titanium.Web.Proxy.Examples.Basic\Titanium.Web.Proxy.Examples.Basic.csproj", "{1FAC4205-4445-4F2B-BB8F-618E8A0C15FD}" EndProject @@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.Web.Proxy.Examples EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Titanium.Web.Proxy.IntegrationTests", "..\tests\Titanium.Web.Proxy.IntegrationTests\Titanium.Web.Proxy.IntegrationTests.csproj", "{1D053D72-DCB4-4517-ACDD-D35ADC186950}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamExtended", "StreamExtended\StreamExtended.csproj", "{61539DC1-CE80-41E6-A696-8F455ACE8D15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +81,14 @@ Global {1D053D72-DCB4-4517-ACDD-D35ADC186950}.Release|Any CPU.Build.0 = Release|Any CPU {1D053D72-DCB4-4517-ACDD-D35ADC186950}.Release|x64.ActiveCfg = Release|Any CPU {1D053D72-DCB4-4517-ACDD-D35ADC186950}.Release|x64.Build.0 = Release|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Debug|x64.ActiveCfg = Debug|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Debug|x64.Build.0 = Debug|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Release|Any CPU.Build.0 = Release|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Release|x64.ActiveCfg = Release|Any CPU + {61539DC1-CE80-41E6-A696-8F455ACE8D15}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -90,7 +100,7 @@ Global {1D053D72-DCB4-4517-ACDD-D35ADC186950} = {BC1E0789-D348-49CF-8B67-5E99D50EDF64} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {625C1EB5-44CF-47DE-A85A-B4C8C40ED90A} EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35 + SolutionGuid = {625C1EB5-44CF-47DE-A85A-B4C8C40ED90A} EndGlobalSection EndGlobal diff --git a/src/Titanium.Web.Proxy.sln.DotSettings b/src/Titanium.Web.Proxy.sln.DotSettings index d0c946856..1b03ebb37 100644 --- a/src/Titanium.Web.Proxy.sln.DotSettings +++ b/src/Titanium.Web.Proxy.sln.DotSettings @@ -19,16 +19,19 @@ MTA OID OIDS + False <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"><ElementKinds><Kind Name="METHOD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> True True True True + True True True True diff --git a/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs index 90f22abb5..5dda6dd5d 100644 --- a/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs @@ -29,7 +29,7 @@ public class CertificateSelectionEventArgs : EventArgs public X509Certificate RemoteCertificate { get; internal set; } /// - /// Acceptable issuers as listed by remoted server. + /// Acceptable issuers as listed by remote server. /// public string[] AcceptableIssuers { get; internal set; } diff --git a/src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs b/src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs index 175b0974b..cd4d7ae9b 100644 --- a/src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs +++ b/src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using StreamExtended; using StreamExtended.Network; +using Titanium.Web.Proxy.Exceptions; namespace Titanium.Web.Proxy.EventArguments { @@ -60,7 +61,11 @@ private void getNextChunk() chunkHead = chunkHead.Substring(0, idx); } - int chunkSize = int.Parse(chunkHead, NumberStyles.HexNumber); + if (!int.TryParse(chunkHead, NumberStyles.HexNumber, null, out int chunkSize)) + { + throw new ProxyHttpException($"Invalid chunk length: '{chunkHead}'", null, null); + } + bytesRemaining = chunkSize; if (chunkSize == 0) diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs index f4d38dec1..e93a417c6 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs @@ -28,6 +28,11 @@ public class SessionEventArgs : SessionEventArgsBase /// private bool reRequest; + /// + /// Is this session a HTTP/2 promise? + /// + public bool IsPromise { get; internal set; } + /// /// Constructor to initialize the proxy /// @@ -89,13 +94,35 @@ private async Task readRequestBodyAsync(CancellationToken cancellationToken) // If not already read (not cached yet) if (!request.IsBodyRead) { - var body = await readBodyAsync(true, cancellationToken); - request.Body = body; + if (request.HttpVersion == HttpHeader.Version20) + { + // do not send to the remote endpoint + request.Http2IgnoreBodyFrames = true; + + request.Http2BodyData = new MemoryStream(); + + var tcs = new TaskCompletionSource(); + request.ReadHttp2BodyTaskCompletionSource = tcs; + + // signal to HTTP/2 copy frame method to continue + request.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true); + + await tcs.Task; + + // Now set the flag to true + // So that next time we can deliver body from cache + request.IsBodyRead = true; + } + else + { + var body = await readBodyAsync(true, cancellationToken); + request.Body = body; - // Now set the flag to true - // So that next time we can deliver body from cache - request.IsBodyRead = true; - OnDataSent(body, 0, body.Length); + // Now set the flag to true + // So that next time we can deliver body from cache + request.IsBodyRead = true; + OnDataSent(body, 0, body.Length); + } } } @@ -117,7 +144,7 @@ internal void OnMultipartRequestPartSent(string boundary, HeaderCollection heade } catch (Exception ex) { - exceptionFunc(new Exception("Exception thrown in user event", ex)); + ExceptionFunc(new Exception("Exception thrown in user event", ex)); } } @@ -140,13 +167,35 @@ private async Task readResponseBodyAsync(CancellationToken cancellationToken) // If not already read (not cached yet) if (!response.IsBodyRead) { - var body = await readBodyAsync(false, cancellationToken); - response.Body = body; + if (response.HttpVersion == HttpHeader.Version20) + { + // do not send to the remote endpoint + response.Http2IgnoreBodyFrames = true; + + response.Http2BodyData = new MemoryStream(); + + var tcs = new TaskCompletionSource(); + response.ReadHttp2BodyTaskCompletionSource = tcs; + + // signal to HTTP/2 copy frame method to continue + response.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true); + + await tcs.Task; - // Now set the flag to true - // So that next time we can deliver body from cache - response.IsBodyRead = true; - OnDataReceived(body, 0, body.Length); + // Now set the flag to true + // So that next time we can deliver body from cache + response.IsBodyRead = true; + } + else + { + var body = await readBodyAsync(false, cancellationToken); + response.Body = body; + + // Now set the flag to true + // So that next time we can deliver body from cache + response.IsBodyRead = true; + OnDataReceived(body, 0, body.Length); + } } } @@ -154,7 +203,7 @@ private async Task readBodyAsync(bool isRequest, CancellationToken cance { using (var bodyStream = new MemoryStream()) { - var writer = new HttpWriter(bodyStream, bufferPool, bufferSize); + var writer = new HttpWriter(bodyStream, BufferPool, BufferSize); if (isRequest) { @@ -186,7 +235,7 @@ internal async Task SyphonOutBodyAsync(bool isRequest, CancellationToken cancell using (var bodyStream = new MemoryStream()) { - var writer = new HttpWriter(bodyStream, bufferPool, bufferSize); + var writer = new HttpWriter(bodyStream, BufferPool, BufferSize); await copyBodyAsync(isRequest, true, writer, TransformationMode.None, null, cancellationToken); } } @@ -207,7 +256,7 @@ internal async Task CopyRequestBodyAsync(HttpWriter writer, TransformationMode t var reader = getStreamReader(true); string boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType); - using (var copyStream = new CopyStream(reader, writer, bufferPool, bufferSize)) + using (var copyStream = new CopyStream(reader, writer, BufferPool, BufferSize)) { while (contentLength > copyStream.ReadBytes) { @@ -259,7 +308,7 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H string contentEncoding = useOriginalHeaderValues ? requestResponse.OriginalContentEncoding : requestResponse.ContentEncoding; - Stream s = limitedStream = new LimitedStream(stream, bufferPool, isChunked, contentLength); + Stream s = limitedStream = new LimitedStream(stream, BufferPool, isChunked, contentLength); if (transformation == TransformationMode.Uncompress && contentEncoding != null) { @@ -268,7 +317,7 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H try { - using (var bufStream = new CustomBufferedStream(s, bufferPool, bufferSize, true)) + using (var bufStream = new CustomBufferedStream(s, BufferPool, BufferSize, true)) { await writer.CopyBodyAsync(bufStream, false, -1, onCopy, cancellationToken); } @@ -290,7 +339,7 @@ private async Task readUntilBoundaryAsync(ICustomStreamReader reader, long { int bufferDataLength = 0; - var buffer = bufferPool.GetBuffer(bufferSize); + var buffer = BufferPool.GetBuffer(BufferSize); try { int boundaryLength = boundary.Length + 4; @@ -340,7 +389,7 @@ private async Task readUntilBoundaryAsync(ICustomStreamReader reader, long } finally { - bufferPool.ReturnBuffer(buffer); + BufferPool.ReturnBuffer(buffer); } } diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs index dc627e3f6..e3792dde8 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs @@ -24,14 +24,14 @@ public abstract class SessionEventArgsBase : EventArgs, IDisposable internal TcpServerConnection ServerConnection => HttpClient.Connection; internal TcpClientConnection ClientConnection => ProxyClient.Connection; - protected readonly int bufferSize; - protected readonly IBufferPool bufferPool; - protected readonly ExceptionHandler exceptionFunc; + protected readonly int BufferSize; + protected readonly IBufferPool BufferPool; + protected readonly ExceptionHandler ExceptionFunc; /// /// Relative milliseconds for various events. /// - public Dictionary TimeLine { get; set; } = new Dictionary(); + public Dictionary TimeLine { get; } = new Dictionary(); /// /// Initializes a new instance of the class. @@ -39,9 +39,9 @@ public abstract class SessionEventArgsBase : EventArgs, IDisposable private SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, CancellationTokenSource cancellationTokenSource) { - bufferSize = server.BufferSize; - bufferPool = server.BufferPool; - exceptionFunc = server.ExceptionFunc; + BufferSize = server.BufferSize; + BufferPool = server.BufferPool; + ExceptionFunc = server.ExceptionFunc; TimeLine["Session Created"] = DateTime.Now; } @@ -55,25 +55,7 @@ protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, HttpClient = new HttpWebClient(request); LocalEndPoint = endPoint; - HttpClient.ProcessId = new Lazy(() => - { - if (RunTime.IsWindows) - { - var remoteEndPoint = ClientEndPoint; - - // If client is localhost get the process id - if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address)) - { - var ipVersion = endPoint.IpV6Enabled ? IpVersion.Ipv6 : IpVersion.Ipv4; - return TcpHelper.GetProcessIdByLocalPort(ipVersion, remoteEndPoint.Port); - } - - // can't access process Id of remote request from remote machine - return -1; - } - - throw new PlatformNotSupportedException(); - }); + HttpClient.ProcessId = new Lazy(() => ProxyClient.Connection.GetProcessId(endPoint)); } /// @@ -161,7 +143,7 @@ internal void OnDataSent(byte[] buffer, int offset, int count) } catch (Exception ex) { - exceptionFunc(new Exception("Exception thrown in user event", ex)); + ExceptionFunc(new Exception("Exception thrown in user event", ex)); } } @@ -173,7 +155,7 @@ internal void OnDataReceived(byte[] buffer, int offset, int count) } catch (Exception ex) { - exceptionFunc(new Exception("Exception thrown in user event", ex)); + ExceptionFunc(new Exception("Exception thrown in user event", ex)); } } diff --git a/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs index 47ffd896a..a4615ef39 100644 --- a/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs @@ -31,12 +31,12 @@ internal TunnelConnectSessionEventArgs(ProxyServer server, ProxyEndPoint endPoin public bool DenyConnect { get; set; } /// - /// Is this a connect request to secure HTTP server? Or is it to someother protocol. + /// Is this a connect request to secure HTTP server? Or is it to some other protocol. /// public bool IsHttpsConnect { get => isHttpsConnect ?? - throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event"); + throw new Exception("The value of this property is known in the BeforeTunnelConnectResponse event"); internal set => isHttpsConnect = value; } diff --git a/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs b/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs index 61696d8d6..e38435287 100644 --- a/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs +++ b/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs @@ -20,7 +20,7 @@ protected ProxyException(string message) : base(message) /// Initializes a new instance of the class. /// - must be invoked by derived classes' constructors /// - /// Excception message + /// Exception message /// Inner exception associated protected ProxyException(string message, Exception innerException) : base(message, innerException) { diff --git a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs index d2562ff49..a4fd23498 100644 --- a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs +++ b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs @@ -47,10 +47,9 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect { string connectHostname = null; TunnelConnectSessionEventArgs connectArgs = null; - - + // Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request) - if (await HttpHelper.IsConnectMethod(clientStream) == 1) + if (await HttpHelper.IsConnectMethod(clientStream, BufferPool, BufferSize, cancellationToken) == 1) { // read the first line HTTP command string httpCmd = await clientStream.ReadLineAsync(cancellationToken); @@ -103,7 +102,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, if (await checkAuthorization(connectArgs) == false) { - await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc); + await endPoint.InvokeBeforeTunnelConnectResponse(this, connectArgs, ExceptionFunc); // send the response await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, @@ -111,8 +110,8 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, return; } - // write back successfull CONNECT response - var response = ConnectResponse.CreateSuccessfullConnectResponse(version); + // write back successful CONNECT response + var response = ConnectResponse.CreateSuccessfulConnectResponse(version); // Set ContentLength explicitly to properly handle HTTP 1.0 response.ContentLength = 0; @@ -126,10 +125,11 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, bool isClientHello = clientHelloInfo != null; if (isClientHello) { + connectRequest.TunnelType = TunnelType.Https; connectRequest.ClientHelloInfo = clientHelloInfo; } - await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc, isClientHello); + await endPoint.InvokeBeforeTunnelConnectResponse(this, connectArgs, ExceptionFunc, isClientHello); if (decryptSsl && isClientHello) { @@ -141,15 +141,22 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, if (alpn != null && alpn.Contains(SslApplicationProtocol.Http2)) { // test server HTTP/2 support - // todo: this is a hack, because Titanium does not support HTTP protocol changing currently - var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs, - isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList, - noCache: true, cancellationToken: cancellationToken); - - http2Supported = connection.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2; - - //release connection back to pool intead of closing when connection pool is enabled. - await tcpConnectionFactory.Release(connection, true); + try + { + // todo: this is a hack, because Titanium does not support HTTP protocol changing currently + var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs, + isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList, + noCache: true, cancellationToken: cancellationToken); + + http2Supported = connection.NegotiatedApplicationProtocol == + SslApplicationProtocol.Http2; + //release connection back to pool instead of closing when connection pool is enabled. + await tcpConnectionFactory.Release(connection, true); + } + catch (Exception) + { + // ignore + } } if (EnableTcpServerConnectionPrefetch) @@ -175,7 +182,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, X509Certificate2 certificate = null; try { - sslStream = new SslStream(clientStream, true); + sslStream = new SslStream(clientStream, false); string certName = HttpHelper.GetWildCardDomainName(connectHostname); certificate = endPoint.GenericCertificate ?? @@ -183,7 +190,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, // Successfully managed to authenticate the client using the fake certificate var options = new SslServerAuthenticationOptions(); - if (http2Supported) + if (EnableHttp2 && http2Supported) { options.ApplicationProtocols = clientHelloInfo.GetAlpn(); if (options.ApplicationProtocols == null || options.ApplicationProtocols.Count == 0) @@ -208,12 +215,12 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, } catch (Exception e) { - var certname = certificate?.GetNameInfo(X509NameType.SimpleName, false); + var certName = certificate?.GetNameInfo(X509NameType.SimpleName, false); throw new ProxyConnectException( - $"Couldn't authenticate host '{connectHostname}' with certificate '{certname}'.", e, connectArgs); + $"Couldn't authenticate host '{connectHostname}' with certificate '{certName}'.", e, connectArgs); } - if (await HttpHelper.IsConnectMethod(clientStream) == -1) + if (await HttpHelper.IsConnectMethod(clientStream, BufferPool, BufferSize, cancellationToken) == -1) { decryptSsl = false; } @@ -233,6 +240,11 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, // Hostname is excluded or it is not an HTTPS connect if (!decryptSsl || !isClientHello) { + if (!isClientHello) + { + connectRequest.TunnelType = TunnelType.Websocket; + } + // create new connection to server. // If we detected that client tunnel CONNECTs without SSL by checking for empty client hello then // this connection should not be HTTPS. @@ -253,7 +265,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, try { await clientStream.ReadAsync(data, 0, available, cancellationToken); - // clientStream.Available sbould be at most BufferSize because it is using the same buffer size + // clientStream.Available should be at most BufferSize because it is using the same buffer size await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken); } finally @@ -280,12 +292,14 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize, } } - if (connectArgs != null && await HttpHelper.IsPriMethod(clientStream) == 1) + if (connectArgs != null && await HttpHelper.IsPriMethod(clientStream, BufferPool, BufferSize, cancellationToken) == 1) { // todo string httpCmd = await clientStream.ReadLineAsync(cancellationToken); if (httpCmd == "PRI * HTTP/2.0") { + connectArgs.HttpClient.ConnectRequest.TunnelType = TunnelType.Http2; + // HTTP/2 Connection Preface string line = await clientStream.ReadLineAsync(cancellationToken); if (line != string.Empty) @@ -318,9 +332,16 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize, await Http2Helper.SendHttp2(clientStream, connection.Stream, BufferSize, (buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); }, + () => new SessionEventArgs(this, endPoint, cancellationTokenSource) + { + ProxyClient = { Connection = clientConnection }, + HttpClient = { ConnectRequest = connectArgs?.HttpClient.ConnectRequest }, + UserData = connectArgs?.UserData + }, + async args => { await invokeBeforeRequest(args); }, + async args => { await invokeBeforeResponse(args); }, connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc); #endif - } finally { diff --git a/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs b/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs index c95545746..a8adcc89d 100644 --- a/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs +++ b/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs @@ -17,6 +17,7 @@ internal static class StreamExtensions /// /// /// + /// /// internal static Task CopyToAsync(this Stream input, Stream output, Action onCopy, IBufferPool bufferPool, int bufferSize) @@ -30,6 +31,7 @@ internal static Task CopyToAsync(this Stream input, Stream output, Action /// /// + /// /// /// internal static async Task CopyToAsync(this Stream input, Stream output, Action onCopy, diff --git a/src/Titanium.Web.Proxy/Helpers/HttpHelper.cs b/src/Titanium.Web.Proxy/Helpers/HttpHelper.cs index bfcc6c86a..73d738a6c 100644 --- a/src/Titanium.Web.Proxy/Helpers/HttpHelper.cs +++ b/src/Titanium.Web.Proxy/Helpers/HttpHelper.cs @@ -1,6 +1,9 @@ using System; using System.Text; +using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; +using StreamExtended; using StreamExtended.Network; using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Http; @@ -120,9 +123,9 @@ internal static string GetWildCardDomainName(string hostname) /// /// The client stream reader. /// 1: when CONNECT, 0: when valid HTTP method, -1: otherwise - internal static Task IsConnectMethod(ICustomStreamReader clientStreamReader) + internal static Task IsConnectMethod(ICustomStreamReader clientStreamReader, IBufferPool bufferPool, int bufferSize, CancellationToken cancellationToken = default(CancellationToken)) { - return startsWith(clientStreamReader, "CONNECT"); + return startsWith(clientStreamReader, bufferPool, bufferSize, "CONNECT", cancellationToken); } /// @@ -130,9 +133,9 @@ internal static Task IsConnectMethod(ICustomStreamReader clientStreamReader /// /// The client stream reader. /// 1: when PRI, 0: when valid HTTP method, -1: otherwise - internal static Task IsPriMethod(ICustomStreamReader clientStreamReader) + internal static Task IsPriMethod(ICustomStreamReader clientStreamReader, IBufferPool bufferPool, int bufferSize, CancellationToken cancellationToken = default(CancellationToken)) { - return startsWith(clientStreamReader, "PRI"); + return startsWith(clientStreamReader, bufferPool, bufferSize, "PRI", cancellationToken); } /// @@ -143,37 +146,47 @@ internal static Task IsPriMethod(ICustomStreamReader clientStreamReader) /// /// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise /// - private static async Task startsWith(ICustomStreamReader clientStreamReader, string expectedStart) + private static async Task startsWith(ICustomStreamReader clientStreamReader, IBufferPool bufferPool, int bufferSize, string expectedStart, CancellationToken cancellationToken = default(CancellationToken)) { - bool isExpected = true; - int legthToCheck = 10; - for (int i = 0; i < legthToCheck; i++) + int iRet = -1; + const int lengthToCheck = 10; + byte[] buffer = null; + try { - int b = await clientStreamReader.PeekByteAsync(i); - if (b == -1) - { - return -1; - } + buffer = bufferPool.GetBuffer(Math.Max(bufferSize, lengthToCheck)); - if (b == ' ' && i > 2) - { - return isExpected ? 1 : 0; - } + int peeked = await clientStreamReader.PeekBytesAsync(buffer, 0, 0, lengthToCheck, cancellationToken); - char ch = (char)b; - if (!char.IsLetter(ch)) + if (peeked > 0) { - return -1; - } + bool isExpected = true; - if (i >= expectedStart.Length || ch != expectedStart[i]) - { - isExpected = false; + for (int i = 0; i < lengthToCheck; i++) + { + int b = buffer[i]; + + if (b == ' ' && i > 2) + return isExpected ? 1 : 0; + else + { + char ch = (char)b; + if (!char.IsLetter(ch)) + return -1; + else if (i >= expectedStart.Length || ch != expectedStart[i]) + isExpected = false; + } + } + + // only letters + iRet = isExpected ? 1 : 0; } } - - // only letters - return isExpected ? 1 : 0; + finally + { + bufferPool.ReturnBuffer(buffer); + buffer = null; + } + return iRet; } } } diff --git a/src/Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs b/src/Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs index f9e5b80ab..5883761bc 100644 --- a/src/Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs +++ b/src/Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs @@ -23,7 +23,7 @@ internal HttpRequestWriter(Stream stream, IBufferPool bufferPool, int bufferSize internal async Task WriteRequestAsync(Request request, bool flush = true, CancellationToken cancellationToken = default) { - await WriteLineAsync(Request.CreateRequestLine(request.Method, request.OriginalUrl, request.HttpVersion), + await WriteLineAsync(Request.CreateRequestLine(request.Method, request.RequestUriString, request.HttpVersion), cancellationToken); await WriteAsync(request, flush, cancellationToken); } diff --git a/src/Titanium.Web.Proxy/Helpers/Ref.cs b/src/Titanium.Web.Proxy/Helpers/Ref.cs deleted file mode 100644 index 0bd3e6ac9..000000000 --- a/src/Titanium.Web.Proxy/Helpers/Ref.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Titanium.Web.Proxy.Helpers -{ - internal class Ref - { - internal Ref() - { - } - - internal Ref(T value) - { - Value = value; - } - - internal T Value { get; set; } - - public override string ToString() - { - var value = Value; - return value == null ? string.Empty : value.ToString(); - } - - public static implicit operator T(Ref r) - { - return r.Value; - } - - public static implicit operator Ref(T value) - { - return new Ref(value); - } - } -} diff --git a/src/Titanium.Web.Proxy/Helpers/RunTime.cs b/src/Titanium.Web.Proxy/Helpers/RunTime.cs index 66da024ad..52a1c3720 100644 --- a/src/Titanium.Web.Proxy/Helpers/RunTime.cs +++ b/src/Titanium.Web.Proxy/Helpers/RunTime.cs @@ -70,7 +70,7 @@ private class UwpHelper internal static bool IsRunningAsUwp() { - if (IsWindows7OrLower) + if (isWindows7OrLower) { return false; } @@ -87,7 +87,7 @@ internal static bool IsRunningAsUwp() } } - private static bool IsWindows7OrLower + private static bool isWindows7OrLower { get { diff --git a/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs b/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs index 11cd5f8f9..5e3833328 100644 --- a/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs +++ b/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs @@ -80,7 +80,7 @@ public SystemProxyManager() /// internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -127,7 +127,7 @@ internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType /// internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfig = true) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -168,7 +168,7 @@ internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfi /// internal void DisableAllProxy() { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -186,7 +186,7 @@ internal void DisableAllProxy() internal void SetAutoProxyUrl(string url) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -201,7 +201,7 @@ internal void SetAutoProxyUrl(string url) internal void SetProxyOverride(string proxyOverride) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -286,7 +286,7 @@ internal void RestoreOriginalSettings() internal ProxyInfo GetProxyInfoFromRegistry() { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -347,7 +347,7 @@ private static void refresh() /// /// Opens the registry key with the internet settings /// - private static RegistryKey OpenInternetSettingsKey() + private static RegistryKey openInternetSettingsKey() { return Registry.CurrentUser.OpenSubKey(regKeyInternetSettings, true); } diff --git a/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs b/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs index f321c2e24..b16d81b58 100644 --- a/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs +++ b/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Runtime.InteropServices; using System.Threading; @@ -96,11 +96,12 @@ private static uint toNetworkByteOrder(uint port) /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// Task-based Asynchronous Pattern /// /// /// + /// /// /// /// @@ -128,10 +129,11 @@ private static async Task sendRawTap(Stream clientStream, Stream serverStream, /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// /// /// + /// /// /// /// diff --git a/src/Titanium.Web.Proxy/Http/ConnectRequest.cs b/src/Titanium.Web.Proxy/Http/ConnectRequest.cs index 25496a0bd..9b1400df1 100644 --- a/src/Titanium.Web.Proxy/Http/ConnectRequest.cs +++ b/src/Titanium.Web.Proxy/Http/ConnectRequest.cs @@ -12,6 +12,8 @@ public ConnectRequest() Method = "CONNECT"; } + public TunnelType TunnelType { get; internal set; } + public ClientHelloInfo ClientHelloInfo { get; set; } } } diff --git a/src/Titanium.Web.Proxy/Http/ConnectResponse.cs b/src/Titanium.Web.Proxy/Http/ConnectResponse.cs index 9398c7396..56748d504 100644 --- a/src/Titanium.Web.Proxy/Http/ConnectResponse.cs +++ b/src/Titanium.Web.Proxy/Http/ConnectResponse.cs @@ -12,11 +12,11 @@ public class ConnectResponse : Response public ServerHelloInfo ServerHelloInfo { get; set; } /// - /// Creates a successfull CONNECT response + /// Creates a successful CONNECT response /// /// /// - internal static ConnectResponse CreateSuccessfullConnectResponse(Version httpVersion) + internal static ConnectResponse CreateSuccessfulConnectResponse(Version httpVersion) { var response = new ConnectResponse { diff --git a/src/Titanium.Web.Proxy/Http/HeaderCollection.cs b/src/Titanium.Web.Proxy/Http/HeaderCollection.cs index e1c2fda2a..991d839fb 100644 --- a/src/Titanium.Web.Proxy/Http/HeaderCollection.cs +++ b/src/Titanium.Web.Proxy/Http/HeaderCollection.cs @@ -67,7 +67,7 @@ public bool HeaderExists(string name) /// /// Returns all headers with given name if exists - /// Returns null if does'nt exist + /// Returns null if doesn't exist /// /// /// diff --git a/src/Titanium.Web.Proxy/Http/HttpWebClient.cs b/src/Titanium.Web.Proxy/Http/HttpWebClient.cs index 129380b9d..c22c9f218 100644 --- a/src/Titanium.Web.Proxy/Http/HttpWebClient.cs +++ b/src/Titanium.Web.Proxy/Http/HttpWebClient.cs @@ -99,7 +99,7 @@ internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTranspar // prepare the request & headers await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method, - useUpstreamProxy || isTransparent ? Request.OriginalUrl : Request.RequestUri.PathAndQuery, + useUpstreamProxy || isTransparent ? Request.RequestUriString : Request.RequestUri.PathAndQuery, Request.HttpVersion), cancellationToken); var headerBuilder = new StringBuilder(); diff --git a/src/Titanium.Web.Proxy/Http/KnownHeaders.cs b/src/Titanium.Web.Proxy/Http/KnownHeaders.cs index 9636a1fdd..79bf37a9b 100644 --- a/src/Titanium.Web.Proxy/Http/KnownHeaders.cs +++ b/src/Titanium.Web.Proxy/Http/KnownHeaders.cs @@ -6,28 +6,28 @@ public static class KnownHeaders { // Both - public const string Connection = "connection"; + public const string Connection = "Connection"; public const string ConnectionClose = "close"; public const string ConnectionKeepAlive = "keep-alive"; - public const string ContentLength = "content-length"; + public const string ContentLength = "Content-Length"; - public const string ContentType = "content-type"; + public const string ContentType = "Content-Type"; public const string ContentTypeCharset = "charset"; public const string ContentTypeBoundary = "boundary"; - public const string Upgrade = "upgrade"; + public const string Upgrade = "Upgrade"; public const string UpgradeWebsocket = "websocket"; // Request headers - public const string AcceptEncoding = "accept-encoding"; + public const string AcceptEncoding = "Accept-Encoding"; public const string Authorization = "Authorization"; - public const string Expect = "expect"; + public const string Expect = "Expect"; public const string Expect100Continue = "100-continue"; - public const string Host = "host"; + public const string Host = "Host"; public const string ProxyAuthorization = "Proxy-Authorization"; public const string ProxyAuthorizationBasic = "basic"; @@ -36,7 +36,7 @@ public static class KnownHeaders public const string ProxyConnectionClose = "close"; // Response headers - public const string ContentEncoding = "content-encoding"; + public const string ContentEncoding = "Content-Encoding"; public const string ContentEncodingDeflate = "deflate"; public const string ContentEncodingGzip = "gzip"; public const string ContentEncodingBrotli = "br"; @@ -45,7 +45,7 @@ public static class KnownHeaders public const string ProxyAuthenticate = "Proxy-Authenticate"; - public const string TransferEncoding = "transfer-encoding"; + public const string TransferEncoding = "Transfer-Encoding"; public const string TransferEncodingChunked = "chunked"; } } diff --git a/src/Titanium.Web.Proxy/Http/Request.cs b/src/Titanium.Web.Proxy/Http/Request.cs index e5965b532..6a80ede9d 100644 --- a/src/Titanium.Web.Proxy/Http/Request.cs +++ b/src/Titanium.Web.Proxy/Http/Request.cs @@ -14,6 +14,8 @@ namespace Titanium.Web.Proxy.Http [TypeConverter(typeof(ExpandableObjectConverter))] public class Request : RequestResponseBase { + private string originalUrl; + /// /// Request Method. /// @@ -32,7 +34,20 @@ public class Request : RequestResponseBase /// /// The original request Url. /// - public string OriginalUrl { get; set; } + public string OriginalUrl + { + get => originalUrl; + internal set + { + originalUrl = value; + RequestUriString = value; + } + } + + /// + /// The request uri as it is in the HTTP header + /// + public string RequestUriString { get; set; } /// /// Has request body? @@ -140,7 +155,7 @@ public override string HeaderText get { var sb = new StringBuilder(); - sb.Append($"{CreateRequestLine(Method, OriginalUrl, HttpVersion)}{ProxyConstants.NewLine}"); + sb.Append($"{CreateRequestLine(Method, RequestUriString, HttpVersion)}{ProxyConstants.NewLine}"); foreach (var header in Headers) { sb.Append($"{header.ToString()}{ProxyConstants.NewLine}"); diff --git a/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs b/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs index 474856326..e8134f735 100644 --- a/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs +++ b/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; +using System.Threading.Tasks; using Titanium.Web.Proxy.Compression; using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Helpers; @@ -49,6 +50,21 @@ public abstract class RequestResponseBase /// internal string OriginalContentEncoding { get; set; } + internal TaskCompletionSource ReadHttp2BeforeHandlerTaskCompletionSource; + + internal TaskCompletionSource ReadHttp2BodyTaskCompletionSource; + + internal MemoryStream Http2BodyData; + + internal bool Http2IgnoreBodyFrames; + + internal Task Http2BeforeHandlerTask; + + /// + /// Priority used only in HTTP/2 + /// + internal long? Priority; + /// /// Keeps the body data after the session is finished. /// @@ -189,11 +205,13 @@ internal set public bool IsBodyRead { get; internal set; } /// - /// Is the request/response no more modifyable by user (user callbacks complete?) + /// Is the request/response no more modifiable by user (user callbacks complete?) /// Also if user set this as a custom response then this should be true. /// internal bool Locked { get; set; } + internal bool BodyAvailable => BodyInternal != null; + internal abstract void EnsureBodyAvailable(bool throwWhenNotReadYet = true); /// diff --git a/src/Titanium.Web.Proxy/Http/TunnelType.cs b/src/Titanium.Web.Proxy/Http/TunnelType.cs new file mode 100644 index 000000000..d907914b0 --- /dev/null +++ b/src/Titanium.Web.Proxy/Http/TunnelType.cs @@ -0,0 +1,10 @@ +namespace Titanium.Web.Proxy.Http +{ + public enum TunnelType + { + Unknown, + Https, + Websocket, + Http2, + } +} diff --git a/src/Titanium.Web.Proxy/Http2/Hpack/Encoder.cs b/src/Titanium.Web.Proxy/Http2/Hpack/Encoder.cs index 5a90913cf..cf503a4d8 100644 --- a/src/Titanium.Web.Proxy/Http2/Hpack/Encoder.cs +++ b/src/Titanium.Web.Proxy/Http2/Hpack/Encoder.cs @@ -61,7 +61,9 @@ public Encoder(int maxHeaderTableSize) /// Name. /// Value. /// If set to true sensitive. - public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false) + /// Index type. + /// Use static name. + public void EncodeHeader(BinaryWriter output, string name, string value, bool sensitive = false, HpackUtil.IndexType indexType = HpackUtil.IndexType.Incremental, bool useStaticName = true) { // If the header value is sensitive then it must never be indexed if (sensitive) @@ -116,10 +118,9 @@ public void EncodeHeader(BinaryWriter output, string name, string value, bool se } else { - int nameIndex = getNameIndex(name); + int nameIndex = useStaticName ? getNameIndex(name) : -1; ensureCapacity(headerSize); - var indexType = HpackUtil.IndexType.Incremental; encodeLiteral(output, name, value, indexType, nameIndex); add(name, value); } @@ -309,7 +310,7 @@ private HeaderEntry getEntry(string name, string value) int i = index(h); for (var e = headerFields[i]; e != null; e = e.Next) { - if (e.Hash == h && Equals(name, e.Name) && Equals(value, e.Value)) + if (e.Hash == h && name.Equals(e.Name, StringComparison.OrdinalIgnoreCase) && Equals(value, e.Value)) { return e; } @@ -336,7 +337,7 @@ private int getIndex(string name) int index = -1; for (var e = headerFields[i]; e != null; e = e.Next) { - if (e.Hash == h && HpackUtil.Equals(name, e.Name)) + if (e.Hash == h && name.Equals(e.Name, StringComparison.OrdinalIgnoreCase)) { index = e.Index; break; @@ -513,7 +514,7 @@ private class HeaderEntry : HttpHeader /// Value. /// Index. /// Next. - public HeaderEntry(int hash, string name, string value, int index, HeaderEntry next) : base(name, value) + public HeaderEntry(int hash, string name, string value, int index, HeaderEntry next) : base(name, value, true) { Index = index; Hash = hash; diff --git a/src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs b/src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs index 3d3f6c78f..3198a3c34 100644 --- a/src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs +++ b/src/Titanium.Web.Proxy/Http2/Hpack/StaticTable.cs @@ -59,102 +59,102 @@ public static class StaticTable /* 14 */ new HttpHeader(":status", "500"), /* 15 */ - new HttpHeader("accept-charset", string.Empty), + new HttpHeader("Accept-Charset", string.Empty), /* 16 */ - new HttpHeader("accept-encoding", "gzip, deflate"), + new HttpHeader("Accept-Encoding", "gzip, deflate"), /* 17 */ - new HttpHeader("accept-language", string.Empty), + new HttpHeader("Accept-Language", string.Empty), /* 18 */ - new HttpHeader("accept-ranges", string.Empty), + new HttpHeader("Accept-Ranges", string.Empty), /* 19 */ - new HttpHeader("accept", string.Empty), + new HttpHeader("Accept", string.Empty), /* 20 */ - new HttpHeader("access-control-allow-origin", string.Empty), + new HttpHeader("Access-Control-Allow-Origin", string.Empty), /* 21 */ - new HttpHeader("age", string.Empty), + new HttpHeader("Age", string.Empty), /* 22 */ - new HttpHeader("allow", string.Empty), + new HttpHeader("Allow", string.Empty), /* 23 */ - new HttpHeader("authorization", string.Empty), + new HttpHeader("Authorization", string.Empty), /* 24 */ - new HttpHeader("cache-control", string.Empty), + new HttpHeader("Cache-Control", string.Empty), /* 25 */ - new HttpHeader("content-disposition", string.Empty), + new HttpHeader("Content-Disposition", string.Empty), /* 26 */ - new HttpHeader("content-encoding", string.Empty), + new HttpHeader("Content-Encoding", string.Empty), /* 27 */ - new HttpHeader("content-language", string.Empty), + new HttpHeader("Content-Language", string.Empty), /* 28 */ - new HttpHeader("content-length", string.Empty), + new HttpHeader("Content-Length", string.Empty), /* 29 */ - new HttpHeader("content-location", string.Empty), + new HttpHeader("Content-Location", string.Empty), /* 30 */ - new HttpHeader("content-range", string.Empty), + new HttpHeader("Content-Range", string.Empty), /* 31 */ - new HttpHeader("content-type", string.Empty), + new HttpHeader("Content-Type", string.Empty), /* 32 */ - new HttpHeader("cookie", string.Empty), + new HttpHeader("Cookie", string.Empty), /* 33 */ - new HttpHeader("date", string.Empty), + new HttpHeader("Date", string.Empty), /* 34 */ - new HttpHeader("etag", string.Empty), + new HttpHeader("ETag", string.Empty), /* 35 */ - new HttpHeader("expect", string.Empty), + new HttpHeader("Expect", string.Empty), /* 36 */ - new HttpHeader("expires", string.Empty), + new HttpHeader("Expires", string.Empty), /* 37 */ - new HttpHeader("from", string.Empty), + new HttpHeader("From", string.Empty), /* 38 */ - new HttpHeader("host", string.Empty), + new HttpHeader("Host", string.Empty), /* 39 */ - new HttpHeader("if-match", string.Empty), + new HttpHeader("If-Match", string.Empty), /* 40 */ - new HttpHeader("if-modified-since", string.Empty), + new HttpHeader("If-Modified-Since", string.Empty), /* 41 */ - new HttpHeader("if-none-match", string.Empty), + new HttpHeader("If-None-Match", string.Empty), /* 42 */ - new HttpHeader("if-range", string.Empty), + new HttpHeader("If-Range", string.Empty), /* 43 */ - new HttpHeader("if-unmodified-since", string.Empty), + new HttpHeader("If-Unmodified-Since", string.Empty), /* 44 */ - new HttpHeader("last-modified", string.Empty), + new HttpHeader("Last-Modified", string.Empty), /* 45 */ - new HttpHeader("link", string.Empty), + new HttpHeader("Link", string.Empty), /* 46 */ - new HttpHeader("location", string.Empty), + new HttpHeader("Location", string.Empty), /* 47 */ - new HttpHeader("max-forwards", string.Empty), + new HttpHeader("Max-Forwards", string.Empty), /* 48 */ - new HttpHeader("proxy-authenticate", string.Empty), + new HttpHeader("Proxy-Authenticate", string.Empty), /* 49 */ - new HttpHeader("proxy-authorization", string.Empty), + new HttpHeader("Proxy-Authorization", string.Empty), /* 50 */ - new HttpHeader("range", string.Empty), + new HttpHeader("Range", string.Empty), /* 51 */ - new HttpHeader("referer", string.Empty), + new HttpHeader("Referer", string.Empty), /* 52 */ - new HttpHeader("refresh", string.Empty), + new HttpHeader("Refresh", string.Empty), /* 53 */ - new HttpHeader("retry-after", string.Empty), + new HttpHeader("Retry-After", string.Empty), /* 54 */ - new HttpHeader("server", string.Empty), + new HttpHeader("Server", string.Empty), /* 55 */ - new HttpHeader("set-cookie", string.Empty), + new HttpHeader("Set-Cookie", string.Empty), /* 56 */ - new HttpHeader("strict-transport-security", string.Empty), + new HttpHeader("Strict-Transport-Security", string.Empty), /* 57 */ - new HttpHeader("transfer-encoding", string.Empty), + new HttpHeader("Transfer-Encoding", string.Empty), /* 58 */ - new HttpHeader("user-agent", string.Empty), + new HttpHeader("User-Agent", string.Empty), /* 59 */ - new HttpHeader("vary", string.Empty), + new HttpHeader("Vary", string.Empty), /* 60 */ - new HttpHeader("via", string.Empty), + new HttpHeader("Via", string.Empty), /* 61 */ - new HttpHeader("www-authenticate", string.Empty) + new HttpHeader("WWW-Authenticate", string.Empty) }; - private static readonly Dictionary staticIndexByName = CreateMap(); + private static readonly Dictionary staticIndexByName = createMap(); /// /// The number of header fields in the static table. @@ -180,12 +180,12 @@ public static HttpHeader Get(int index) /// Name. public static int GetIndex(string name) { - if (!staticIndexByName.ContainsKey(name)) + if (!staticIndexByName.TryGetValue(name, out int index)) { return -1; } - return staticIndexByName[name]; + return index; } /// @@ -207,7 +207,7 @@ public static int GetIndex(string name, string value) while (index <= Length) { var entry = Get(index); - if (!HpackUtil.Equals(name, entry.Name)) + if (!name.Equals(entry.Name, StringComparison.OrdinalIgnoreCase)) { break; } @@ -227,7 +227,7 @@ public static int GetIndex(string name, string value) /// create a map of header name to index value to allow quick lookup /// /// The map. - private static Dictionary CreateMap() + private static Dictionary createMap() { int length = staticTable.Count; var ret = new Dictionary(length); @@ -237,11 +237,11 @@ private static Dictionary CreateMap() for (int index = length; index > 0; index--) { var entry = Get(index); - string name = entry.Name; + string name = entry.Name.ToLower(); ret[name] = index; } return ret; } } -} \ No newline at end of file +} diff --git a/src/Titanium.Web.Proxy/Http2/Http2FrameFlag.cs b/src/Titanium.Web.Proxy/Http2/Http2FrameFlag.cs new file mode 100644 index 000000000..ba7eea53b --- /dev/null +++ b/src/Titanium.Web.Proxy/Http2/Http2FrameFlag.cs @@ -0,0 +1,14 @@ +using System; + +namespace Titanium.Web.Proxy.Http2 +{ + [Flags] + internal enum Http2FrameFlag : byte + { + Ack = 0x01, + EndStream = 0x01, + EndHeaders = 0x04, + Padded = 0x08, + Priority = 0x20, + } +} \ No newline at end of file diff --git a/src/Titanium.Web.Proxy/Http2/Http2FrameHeader.cs b/src/Titanium.Web.Proxy/Http2/Http2FrameHeader.cs new file mode 100644 index 000000000..f211511d5 --- /dev/null +++ b/src/Titanium.Web.Proxy/Http2/Http2FrameHeader.cs @@ -0,0 +1,32 @@ +namespace Titanium.Web.Proxy.Http2 +{ + internal class Http2FrameHeader + { + public int Length; + + public Http2FrameType Type; + + public Http2FrameFlag Flags; + + public int StreamId; + + public byte[] Buffer; + + public byte[] CopyToBuffer() + { + int length = Length; + var buf = /*new byte[9];*/Buffer; + buf[0] = (byte)((length >> 16) & 0xff); + buf[1] = (byte)((length >> 8) & 0xff); + buf[2] = (byte)(length & 0xff); + buf[3] = (byte)Type; + buf[4] = (byte)Flags; + int streamId = StreamId; + //buf[5] = (byte)((streamId >> 24) & 0xff); + //buf[6] = (byte)((streamId >> 16) & 0xff); + //buf[7] = (byte)((streamId >> 8) & 0xff); + //buf[8] = (byte)(streamId & 0xff); + return buf; + } + } +} diff --git a/src/Titanium.Web.Proxy/Http2/Http2FrameType.cs b/src/Titanium.Web.Proxy/Http2/Http2FrameType.cs new file mode 100644 index 000000000..a6dcbadf4 --- /dev/null +++ b/src/Titanium.Web.Proxy/Http2/Http2FrameType.cs @@ -0,0 +1,16 @@ +namespace Titanium.Web.Proxy.Http2 +{ + internal enum Http2FrameType : byte + { + Data = 0x00, + Headers = 0x01, + Priority = 0x02, + RstStream = 0x03, + Settings = 0x04, + PushPromise = 0x05, + Ping = 0x06, + GoAway = 0x07, + WindowUpdate = 0x08, + Continuation = 0x09, + } +} \ No newline at end of file diff --git a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs index e8af3fcb7..2fe85d194 100644 --- a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs +++ b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs @@ -1,51 +1,50 @@ -#if NETCOREAPP2_1 +#if NETCOREAPP2_1 using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using System.Net; using System.Threading; using System.Threading.Tasks; +using Titanium.Web.Proxy.Compression; +using Titanium.Web.Proxy.EventArguments; +using Titanium.Web.Proxy.Exceptions; +using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Http2.Hpack; namespace Titanium.Web.Proxy.Http2 { - [Flags] - internal enum Http2FrameFlag - { - Ack = 0x01, - EndStream = 0x01, - EndHeaders = 0x04, - Padded = 0x08, - Priority = 0x20, - } - internal class Http2Helper { /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// Task-based Asynchronous Pattern /// - /// - /// - /// - /// - /// - /// - /// - /// /// internal static async Task SendHttp2(Stream clientStream, Stream serverStream, int bufferSize, Action onDataSend, Action onDataReceive, + Func sessionFactory, + Func onBeforeRequest, Func onBeforeResponse, CancellationTokenSource cancellationTokenSource, Guid connectionId, ExceptionHandler exceptionFunc) { + var clientSettings = new Http2Settings(); + var serverSettings = new Http2Settings(); + + var sessions = new ConcurrentDictionary(); + // Now async relay all server=>client & client=>server data var sendRelay = - CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId, - true, cancellationTokenSource.Token); + copyHttp2FrameAsync(clientStream, serverStream, onDataSend, clientSettings, serverSettings, + sessionFactory, sessions, onBeforeRequest, + bufferSize, connectionId, true, cancellationTokenSource.Token, exceptionFunc); var receiveRelay = - CopyHttp2FrameAsync(serverStream, clientStream, onDataReceive, bufferSize, connectionId, - false, cancellationTokenSource.Token); + copyHttp2FrameAsync(serverStream, clientStream, onDataReceive, serverSettings, clientSettings, + sessionFactory, sessions, onBeforeResponse, + bufferSize, connectionId, false, cancellationTokenSource.Token, exceptionFunc); await Task.WhenAny(sendRelay, receiveRelay); cancellationTokenSource.Cancel(); @@ -53,77 +52,366 @@ internal static async Task SendHttp2(Stream clientStream, Stream serverStream, i await Task.WhenAll(sendRelay, receiveRelay); } - private static async Task CopyHttp2FrameAsync(Stream input, Stream output, Action onCopy, - int bufferSize, Guid connectionId, bool isClient, CancellationToken cancellationToken) + private static async Task copyHttp2FrameAsync(Stream input, Stream output, Action onCopy, + Http2Settings localSettings, Http2Settings remoteSettings, + Func sessionFactory, ConcurrentDictionary sessions, + Func onBeforeRequestResponse, + int bufferSize, Guid connectionId, bool isClient, CancellationToken cancellationToken, + ExceptionHandler exceptionFunc) { - var decoder = new Decoder(8192, 4096); + int headerTableSize = 0; + Decoder decoder = null; - var headerBuffer = new byte[9]; - var buffer = new byte[32768]; + var frameHeader = new Http2FrameHeader(); + frameHeader.Buffer = new byte[9]; + byte[] buffer = null; while (true) { - int read = await ForceRead(input, headerBuffer, 0, 9, cancellationToken); + var frameHeaderBuffer = frameHeader.Buffer; + int read = await forceRead(input, frameHeaderBuffer, 0, 9, cancellationToken); + onCopy(frameHeaderBuffer, 0, read); if (read != 9) { return; } - int length = (headerBuffer[0] << 16) + (headerBuffer[1] << 8) + headerBuffer[2]; - byte type = headerBuffer[3]; - byte flags = headerBuffer[4]; - int streamId = ((headerBuffer[5] & 0x7f) << 24) + (headerBuffer[6] << 16) + (headerBuffer[7] << 8) + - headerBuffer[8]; + int length = (frameHeaderBuffer[0] << 16) + (frameHeaderBuffer[1] << 8) + frameHeaderBuffer[2]; + var type = (Http2FrameType)frameHeaderBuffer[3]; + var flags = (Http2FrameFlag)frameHeaderBuffer[4]; + int streamId = ((frameHeaderBuffer[5] & 0x7f) << 24) + (frameHeaderBuffer[6] << 16) + + (frameHeaderBuffer[7] << 8) + frameHeaderBuffer[8]; - read = await ForceRead(input, buffer, 0, length, cancellationToken); + frameHeader.Length = length; + frameHeader.Type = type; + frameHeader.Flags = flags; + frameHeader.StreamId = streamId; + + if (buffer == null || buffer.Length < localSettings.MaxFrameSize) + { + buffer = new byte[localSettings.MaxFrameSize]; + } + + read = await forceRead(input, buffer, 0, length, cancellationToken); + onCopy(buffer, 0, read); if (read != length) { return; } - if (isClient) + bool sendPacket = true; + bool endStream = false; + + SessionEventArgs args = null; + RequestResponseBase rr = null; + if (type == Http2FrameType.Data || type == Http2FrameType.Headers/* || type == Http2FrameType.PushPromise*/) + { + if (!sessions.TryGetValue(streamId, out args)) + { + //if (type == Http2FrameType.Data) + //{ + // throw new ProxyHttpException("HTTP Body data received before any header frame.", null, args); + //} + + //if (type == Http2FrameType.Headers && !isClient) + //{ + // throw new ProxyHttpException("HTTP Response received before any Request header frame.", null, args); + //} + + if (type == Http2FrameType.PushPromise && isClient) + { + throw new ProxyHttpException("HTTP Push promise received from the client.", null, args); + } + } + } + + //System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type); + if (type == Http2FrameType.Data && args != null) { - if (type == 1 /*headers*/) + rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response; + + bool padded = (flags & Http2FrameFlag.Padded) != 0; + bool endStreamFlag = (flags & Http2FrameFlag.EndStream) != 0; + if (endStreamFlag) + { + endStream = true; + } + + if (rr.Http2IgnoreBodyFrames) { - bool endHeaders = (flags & (int)Http2FrameFlag.EndHeaders) != 0; - bool padded = (flags & (int)Http2FrameFlag.Padded) != 0; - bool priority = (flags & (int)Http2FrameFlag.Priority) != 0; + sendPacket = false; + } - System.Diagnostics.Debug.WriteLine("HEADER: " + streamId + " end: " + endHeaders); + if (rr.ReadHttp2BodyTaskCompletionSource != null) + { + // Get body method was called in the "before" event handler + var data = rr.Http2BodyData; int offset = 0; if (padded) { - offset = 1; + offset++; + length--; + length -= buffer[0]; + } + + data.Write(buffer, offset, length); + } + } + else if (type == Http2FrameType.Headers/* || type == Http2FrameType.PushPromise*/) + { + bool endHeaders = (flags & Http2FrameFlag.EndHeaders) != 0; + bool padded = (flags & Http2FrameFlag.Padded) != 0; + bool priority = (flags & Http2FrameFlag.Priority) != 0; + bool endStreamFlag = (flags & Http2FrameFlag.EndStream) != 0; + if (endStreamFlag) + { + endStream = true; + } + + int offset = 0; + if (padded) + { + offset = 1; + breakpoint(); + } + + if (type == Http2FrameType.PushPromise) + { + int promisedStreamId = (buffer[offset++] << 24) + (buffer[offset++] << 16) + (buffer[offset++] << 8) + buffer[offset++]; + if (!sessions.TryGetValue(streamId, out args)) + { + args = sessionFactory(); + args.IsPromise = true; + sessions.TryAdd(streamId, args); + sessions.TryAdd(promisedStreamId, args); + } + + System.Diagnostics.Debug.WriteLine("PROMISE STREAM: " + streamId + ", " + promisedStreamId + + ", CONN: " + connectionId); + rr = args.HttpClient.Request; + + if (isClient) + { + // push_promise from client??? + breakpoint(); + } + } + else + { + if (!sessions.TryGetValue(streamId, out args)) + { + args = sessionFactory(); + sessions.TryAdd(streamId, args); } + rr = isClient ? (RequestResponseBase)args.HttpClient.Request : args.HttpClient.Response; if (priority) { - offset += 5; + var priorityData = ((long)buffer[offset++] << 32) + ((long)buffer[offset++] << 24) + + (buffer[offset++] << 16) + (buffer[offset++] << 8) + buffer[offset++]; + rr.Priority = priorityData; + } + } + + + int dataLength = length - offset; + if (padded) + { + dataLength -= buffer[0]; + } + + var headerListener = new MyHeaderListener( + (name, value) => + { + var headers = isClient ? args.HttpClient.Request.Headers : args.HttpClient.Response.Headers; + headers.AddHeader(name, value); + }); + try + { + // recreate the decoder when new value is bigger + // should we recreate when smaller, too? + if (decoder == null || headerTableSize < localSettings.HeaderTableSize) + { + headerTableSize = localSettings.HeaderTableSize; + decoder = new Decoder(8192, headerTableSize); } - int dataLength = length - offset; - if (padded) + decoder.Decode(new BinaryReader(new MemoryStream(buffer, offset, dataLength)), + headerListener); + decoder.EndHeaderBlock(); + + if (rr is Request request) + { + request.HttpVersion = HttpVersion.Version20; + request.Method = headerListener.Method; + request.OriginalUrl = headerListener.Path; + + request.RequestUri = headerListener.GetUri(); + } + else + { + var response = (Response)rr; + response.HttpVersion = HttpVersion.Version20; + int.TryParse(headerListener.Status, out int statusCode); + response.StatusCode = statusCode; + } + } + catch (Exception ex) + { + exceptionFunc(new ProxyHttpException("Failed to decode HTTP/2 headers", ex, args)); + } + + if (!endHeaders) + { + breakpoint(); + } + + if (endHeaders) + { + var tcs = new TaskCompletionSource(); + rr.ReadHttp2BeforeHandlerTaskCompletionSource = tcs; + + var handler = onBeforeRequestResponse(args); + rr.Http2BeforeHandlerTask = handler; + + if (handler == await Task.WhenAny(tcs.Task, handler)) + { + rr.ReadHttp2BeforeHandlerTaskCompletionSource = null; + tcs.SetResult(true); + await sendHeader(remoteSettings, frameHeader, rr, endStream, output, args.IsPromise); + } + else + { + rr.Http2IgnoreBodyFrames = true; + } + + rr.Locked = true; + } + + sendPacket = false; + } + else if (type == Http2FrameType.Continuation) + { + // todo: implementing this type is mandatory for multi-part headers + breakpoint(); + } + else if (type == Http2FrameType.Settings) + { + if (length % 6 != 0) + { + // https://httpwg.org/specs/rfc7540.html#SETTINGS + // 6.5. SETTINGS + // A SETTINGS frame with a length other than a multiple of 6 octets MUST be treated as a connection error (Section 5.4.1) of type FRAME_SIZE_ERROR + throw new ProxyHttpException("Invalid settings length", null, null); + } + + int pos = 0; + while (pos < length) + { + int identifier = (buffer[pos++] << 8) + buffer[pos++]; + int value = (buffer[pos++] << 24) + (buffer[pos++] << 16) + (buffer[pos++] << 8) + buffer[pos++]; + if (identifier == 1 /*SETTINGS_HEADER_TABLE_SIZE*/) + { + //System.Diagnostics.Debug.WriteLine("HEADER SIZE CONN: " + connectionId + ", CLIENT: " + isClient + ", value: " + value); + remoteSettings.HeaderTableSize = value; + } + else if (identifier == 5 /*SETTINGS_MAX_FRAME_SIZE*/) { - dataLength -= buffer[0]; + remoteSettings.MaxFrameSize = value; } + } + } + + if (type == Http2FrameType.RstStream) + { + int errorCode = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3]; + if (streamId == 0) + { + // connection error + exceptionFunc(new ProxyHttpException("HTTP/2 connection error. Error code: " + errorCode, null, args)); + return; + } + else + { + // stream error + sessions.TryRemove(streamId, out _); - var headerListener = new MyHeaderListener(); - try + if (errorCode != 8 /*cancel*/) { - decoder.Decode(new BinaryReader(new MemoryStream(buffer, offset, dataLength)), - headerListener); - decoder.EndHeaderBlock(); + exceptionFunc(new ProxyHttpException("HTTP/2 stream error. Error code: " + errorCode, null, args)); } - catch (Exception) + } + } + + if (endStream && rr.ReadHttp2BodyTaskCompletionSource != null) + { + if (!rr.BodyAvailable) + { + var data = rr.Http2BodyData; + var body = data.ToArray(); + + if (rr.ContentEncoding != null) { + using (var ms = new MemoryStream()) + { + using (var zip = + DecompressionFactory.Create(rr.ContentEncoding, new MemoryStream(body))) + { + zip.CopyTo(ms); + } + + body = ms.ToArray(); + } } + + rr.Body = body; + } + + rr.IsBodyRead = true; + + var tcs = rr.ReadHttp2BodyTaskCompletionSource; + rr.ReadHttp2BodyTaskCompletionSource = null; + + if (!tcs.Task.IsCompleted) + { + tcs.SetResult(true); + } + + rr.Http2BodyData = null; + + if (rr.Http2BeforeHandlerTask != null) + { + await rr.Http2BeforeHandlerTask; + } + + if (args.IsPromise) + { + breakpoint(); } + + await sendBody(remoteSettings, rr, frameHeader, buffer, output); + } + + if (!isClient && endStream) + { + sessions.TryRemove(streamId, out _); + System.Diagnostics.Debug.WriteLine("REMOVED CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type); + } + + if (sendPacket) + { + // do not cancel the write operation + var buf = frameHeader.CopyToBuffer(); + await output.WriteAsync(buf, 0, buf.Length/*, cancellationToken*/); + await output.WriteAsync(buffer, 0, length /*, cancellationToken*/); } - await output.WriteAsync(headerBuffer, 0, headerBuffer.Length, cancellationToken); - await output.WriteAsync(buffer, 0, length, cancellationToken); + if (cancellationToken.IsCancellationRequested) + { + return; + } - /*using (var fs = new System.IO.FileStream($@"c:\11\{connectionId}.{streamId}.dat", FileMode.Append)) + /*using (var fs = new System.IO.FileStream($@"c:\temp\{connectionId}.{streamId}.dat", FileMode.Append)) { fs.Write(headerBuffer, 0, headerBuffer.Length); fs.Write(buffer, 0, length); @@ -131,14 +419,112 @@ private static async Task CopyHttp2FrameAsync(Stream input, Stream output, Actio } } - private static async Task ForceRead(Stream input, byte[] buffer, int offset, int bytesToRead, + [Conditional("DEBUG")] + private static void breakpoint() + { + // when this method is called something received which is not yet implemented + ; + } + + private static async Task sendHeader(Http2Settings settings, Http2FrameHeader frameHeader, RequestResponseBase rr, bool endStream, Stream output, bool pushPromise) + { + var encoder = new Encoder(settings.HeaderTableSize); + var ms = new MemoryStream(); + var writer = new BinaryWriter(ms); + if (rr.Priority.HasValue) + { + long p = rr.Priority.Value; + writer.Write((byte)((p >> 32) & 0xff)); + writer.Write((byte)((p >> 24) & 0xff)); + writer.Write((byte)((p >> 16) & 0xff)); + writer.Write((byte)((p >> 8) & 0xff)); + writer.Write((byte)(p & 0xff)); + } + + if (rr is Request request) + { + encoder.EncodeHeader(writer, ":method", request.Method); + encoder.EncodeHeader(writer, ":authority", request.RequestUri.Host); + encoder.EncodeHeader(writer, ":scheme", request.RequestUri.Scheme); + encoder.EncodeHeader(writer, ":path", request.RequestUriString, false, + HpackUtil.IndexType.None, false); + } + else + { + var response = (Response)rr; + encoder.EncodeHeader(writer, ":status", response.StatusCode.ToString()); + } + + foreach (var header in rr.Headers) + { + encoder.EncodeHeader(writer, header.Name.ToLower(), header.Value); + } + + var data = ms.ToArray(); + int newLength = data.Length; + + frameHeader.Length = newLength; + frameHeader.Type = pushPromise ? Http2FrameType.PushPromise : Http2FrameType.Headers; + + var flags = Http2FrameFlag.EndHeaders; + if (endStream) + { + flags |= Http2FrameFlag.EndStream; + } + + if (rr.Priority.HasValue) + { + flags |= Http2FrameFlag.Priority; + } + + frameHeader.Flags = flags; + + // clear the padding flag + //headerBuffer[4] = (byte)(flags & ~((int)Http2FrameFlag.Padded)); + + // send the header + var buf = frameHeader.CopyToBuffer(); + await output.WriteAsync(buf, 0, buf.Length/*, cancellationToken*/); + await output.WriteAsync(data, 0, data.Length /*, cancellationToken*/); + } + + private static async Task sendBody(Http2Settings settings, RequestResponseBase rr, Http2FrameHeader frameHeader, byte[] buffer, Stream output) + { + var body = rr.CompressBodyAndUpdateContentLength(); + await sendHeader(settings, frameHeader, rr, !(rr.HasBody && rr.IsBodyRead), output, false); + + if (rr.HasBody && rr.IsBodyRead) + { + int pos = 0; + while (pos < body.Length) + { + int bodyFrameLength = Math.Min(buffer.Length, body.Length - pos); + Buffer.BlockCopy(body, pos, buffer, 0, bodyFrameLength); + pos += bodyFrameLength; + + frameHeader.Length = bodyFrameLength; + frameHeader.Type = Http2FrameType.Data; + frameHeader.Flags = pos < body.Length ? (Http2FrameFlag)0 : Http2FrameFlag.EndStream; + + var buf = frameHeader.CopyToBuffer(); + await output.WriteAsync(buf, 0, buf.Length/*, cancellationToken*/); + await output.WriteAsync(buffer, 0, bodyFrameLength /*, cancellationToken*/); + } + } + else + { + ; + } + } + + private static async Task forceRead(Stream input, byte[] buffer, int offset, int bytesToRead, CancellationToken cancellationToken) { int totalRead = 0; while (bytesToRead > 0) { int read = await input.ReadAsync(buffer, offset, bytesToRead, cancellationToken); - if (read == -1) + if (read == 0) { break; } @@ -151,13 +537,71 @@ private static async Task ForceRead(Stream input, byte[] buffer, int offset return totalRead; } + + class Http2Settings + { + public int HeaderTableSize { get; set; } = 4096; + + public int MaxFrameSize { get; set; } = 16384; + } + class MyHeaderListener : IHeaderListener { + private readonly Action addHeaderFunc; + + public string Method { get; private set; } + + public string Status { get; private set; } + + private string authority; + + private string scheme; + + public string Path { get; private set; } + + public MyHeaderListener(Action addHeaderFunc) + { + this.addHeaderFunc = addHeaderFunc; + } + public void AddHeader(string name, string value, bool sensitive) { - Console.WriteLine(name + ": " + value + " " + sensitive); + if (name[0] == ':') + { + switch (name) + { + case ":method": + Method = value; + return; + case ":authority": + authority = value; + return; + case ":scheme": + scheme = value; + return; + case ":path": + Path = value; + return; + case ":status": + Status = value; + return; + } + } + + addHeaderFunc(name, value); + } + + public Uri GetUri() + { + if (authority == null) + { + // todo + authority = "abc.abc"; + } + + return new Uri(scheme + "://" + authority + Path); } } } } -#endif \ No newline at end of file +#endif diff --git a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs index 4684653f2..84ca63448 100644 --- a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs +++ b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs @@ -31,7 +31,7 @@ public ExplicitProxyEndPoint(IPAddress ipAddress, int port, bool decryptSsl = tr /// Intercept tunnel connect request. /// Valid only for explicit endpoints. /// Set the property to false if this HTTP connect request - /// should'nt be decrypted and instead be relayed. + /// shouldn't be decrypted and instead be relayed. /// public event AsyncEventHandler BeforeTunnelConnectRequest; @@ -50,7 +50,7 @@ internal async Task InvokeBeforeTunnelConnectRequest(ProxyServer proxyServer, } } - internal async Task InvokeBeforeTunnectConnectResponse(ProxyServer proxyServer, + internal async Task InvokeBeforeTunnelConnectResponse(ProxyServer proxyServer, TunnelConnectSessionEventArgs connectArgs, ExceptionHandler exceptionFunc, bool isClientHello = false) { if (BeforeTunnelConnectResponse != null) diff --git a/src/Titanium.Web.Proxy/Models/ExternalProxy.cs b/src/Titanium.Web.Proxy/Models/ExternalProxy.cs index 865fc4bc9..d84fd88ce 100644 --- a/src/Titanium.Web.Proxy/Models/ExternalProxy.cs +++ b/src/Titanium.Web.Proxy/Models/ExternalProxy.cs @@ -70,7 +70,7 @@ public string Password public int Port { get; set; } /// - /// Get cache key for Tcp connection cahe. + /// Get cache key for Tcp connection cache. /// /// internal string GetCacheKey() diff --git a/src/Titanium.Web.Proxy/Models/HttpHeader.cs b/src/Titanium.Web.Proxy/Models/HttpHeader.cs index d9612b55c..02383fab7 100644 --- a/src/Titanium.Web.Proxy/Models/HttpHeader.cs +++ b/src/Titanium.Web.Proxy/Models/HttpHeader.cs @@ -35,17 +35,24 @@ public HttpHeader(string name, string value) { if (string.IsNullOrEmpty(name)) { - throw new Exception("Name cannot be null"); + throw new Exception("Name cannot be null or empty"); } Name = name.Trim(); Value = value.Trim(); } + protected HttpHeader(string name, string value, bool headerEntry) + { + // special header entry created in inherited class with empty name + Name = name.Trim(); + Value = value.Trim(); + } + /// /// Header Name. /// - public string Name { get; set; } + public string Name { get; } /// /// Header Value. diff --git a/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs b/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs index ad621492d..65da36de7 100644 --- a/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs +++ b/src/Titanium.Web.Proxy/Network/Certificate/BCCertificateMaker.cs @@ -143,8 +143,16 @@ private static X509Certificate2 generateCertificate(string hostName, #if NET45 // Set private key onto certificate instance - var x509Certificate = new X509Certificate2(certificate.GetEncoded()); - x509Certificate.PrivateKey = DotNetUtilities.ToRSA(rsaparams); + X509Certificate2 x509Certificate; + if (RunTime.IsRunningOnMono) + { + x509Certificate = withPrivateKey(certificate, rsaparams); + } + else + { + x509Certificate = new X509Certificate2(certificate.GetEncoded()); + x509Certificate.PrivateKey = DotNetUtilities.ToRSA(rsaparams); + } #else var x509Certificate = withPrivateKey(certificate, rsaparams); #endif diff --git a/src/Titanium.Web.Proxy/Network/CertificateManager.cs b/src/Titanium.Web.Proxy/Network/CertificateManager.cs index c7ee521e0..ab4655f31 100644 --- a/src/Titanium.Web.Proxy/Network/CertificateManager.cs +++ b/src/Titanium.Web.Proxy/Network/CertificateManager.cs @@ -49,7 +49,7 @@ private readonly ConcurrentDictionary cachedCertifica /// /// A list of pending certificate creation tasks. - /// Usefull to prevent multiple threads working on same certificate generation + /// Useful to prevent multiple threads working on same certificate generation /// when burst certificate generation requests happen for same certificate. /// private readonly ConcurrentDictionary> pendingCertificateCreationTasks diff --git a/src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs b/src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs index 0a2aa7289..0445d9398 100644 --- a/src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs +++ b/src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs @@ -7,6 +7,8 @@ using System.Net.Sockets; using System.Threading.Tasks; using Titanium.Web.Proxy.Extensions; +using Titanium.Web.Proxy.Helpers; +using Titanium.Web.Proxy.Models; namespace Titanium.Web.Proxy.Network.Tcp { @@ -34,11 +36,42 @@ internal TcpClientConnection(ProxyServer proxyServer, TcpClient tcpClient) private readonly TcpClient tcpClient; + private int? processId; + public Stream GetStream() { return tcpClient.GetStream(); } + public int GetProcessId(ProxyEndPoint endPoint) + { + if (processId.HasValue) + { + return processId.Value; + } + + if (RunTime.IsWindows) + { + var remoteEndPoint = (IPEndPoint)RemoteEndPoint; + + // If client is localhost get the process id + if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address)) + { + var ipVersion = endPoint.IpV6Enabled ? IpVersion.Ipv6 : IpVersion.Ipv4; + processId = TcpHelper.GetProcessIdByLocalPort(ipVersion, remoteEndPoint.Port); + } + else + { + // can't access process Id of remote request from remote machine + processId = -1; + } + + return processId.Value; + } + + throw new PlatformNotSupportedException(); + } + /// /// Dispose. /// diff --git a/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs b/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs index 2f726bf21..fa687c7a9 100644 --- a/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs +++ b/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs @@ -38,11 +38,11 @@ private readonly ConcurrentDictionary await clearOutdatedConnections()); } - internal ProxyServer server { get; set; } + internal ProxyServer Server { get; } internal string GetConnectionCacheKey(string remoteHostName, int remotePort, bool isHttps, List applicationProtocols, @@ -50,7 +50,7 @@ internal string GetConnectionCacheKey(string remoteHostName, int remotePort, { //http version is ignored since its an application level decision b/w HTTP 1.0/1.1 //also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response. - //That can create cache miss for same server connection unneccessarily expecially when prefetcing with Connect. + //That can create cache miss for same server connection unnecessarily especially when prefetching with Connect. //http version 2 is separated using applicationProtocols below. var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}-" + //when creating Tcp client isConnect won't matter @@ -232,7 +232,7 @@ private async Task createServerConnection(string remoteHost CancellationToken cancellationToken) { //deny connection to proxy end points to avoid infinite connection loop. - if (server.ProxyEndPoints.Any(x => x.Port == remotePort) + if (Server.ProxyEndPoints.Any(x => x.Port == remotePort) && NetworkHelper.IsLocalIpAddress(remoteHostName)) { throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}"); @@ -240,7 +240,7 @@ private async Task createServerConnection(string remoteHost if (externalProxy != null) { - if (server.ProxyEndPoints.Any(x => x.Port == externalProxy.Port) + if (Server.ProxyEndPoints.Any(x => x.Port == externalProxy.Port) && NetworkHelper.IsLocalIpAddress(externalProxy.HostName)) { throw new Exception($"A client is making HTTP request via external proxy to one of the listening ports of this proxy {remoteHostName}:{remotePort}"); @@ -271,7 +271,7 @@ private async Task createServerConnection(string remoteHost { tcpClient = new TcpClient(upStreamEndPoint) { - NoDelay = proxyServer.NoDelay, + NoDelay = proxyServer.NoDelay, ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000, SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000, LingerState = new LingerOption(true, proxyServer.TcpTimeWaitSeconds) @@ -416,7 +416,7 @@ internal async Task Release(TcpServerConnection connection, bool close = false) return; } - if (close || connection.IsWinAuthenticated || !server.EnableConnectionPool) + if (close || connection.IsWinAuthenticated || !Server.EnableConnectionPool || connection.IsClosed) { disposalBag.Add(connection); return; @@ -432,7 +432,7 @@ internal async Task Release(TcpServerConnection connection, bool close = false) { if (cache.TryGetValue(connection.CacheKey, out var existingConnections)) { - while (existingConnections.Count >= server.MaxCachedConnections) + while (existingConnections.Count >= Server.MaxCachedConnections) { if (existingConnections.TryDequeue(out var staleConnection)) { @@ -489,16 +489,17 @@ private async Task clearOutdatedConnections() { if (queue.TryDequeue(out var connection)) { - var cutOff = DateTime.Now.AddSeconds(-1 * server.ConnectionTimeOutSeconds); - if (!server.EnableConnectionPool + var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds); + if (!Server.EnableConnectionPool || connection.LastAccess < cutOff) { disposalBag.Add(connection); - continue; } - - queue.Enqueue(connection); - break; + else + { + queue.Enqueue(connection); + break; + } } } } @@ -529,7 +530,7 @@ private async Task clearOutdatedConnections() } catch (Exception e) { - server.ExceptionFunc(new Exception("An error occurred when disposing server connections.", e)); + Server.ExceptionFunc(new Exception("An error occurred when disposing server connections.", e)); } finally { diff --git a/src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs b/src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs index 341c10242..a45e679f3 100644 --- a/src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs +++ b/src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs @@ -27,6 +27,8 @@ internal TcpServerConnection(ProxyServer proxyServer, TcpClient tcpClient) private ProxyServer proxyServer { get; } + internal bool IsClosed => Stream.IsClosed; + internal ExternalProxy UpStreamProxy { get; set; } internal string HostName { get; set; } diff --git a/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs b/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs index 01bb69856..7d67f1d5c 100644 --- a/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs +++ b/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs @@ -1,4 +1,4 @@ -// +// // Mono.Security.BitConverterLE.cs // Like System.BitConverter but always little endian // diff --git a/src/Titanium.Web.Proxy/ProxyServer.cs b/src/Titanium.Web.Proxy/ProxyServer.cs index dad9ac007..c668333b7 100644 --- a/src/Titanium.Web.Proxy/ProxyServer.cs +++ b/src/Titanium.Web.Proxy/ProxyServer.cs @@ -144,9 +144,17 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, /// Defaults to false. /// public bool EnableWinAuth { get; set; } + + /// + /// Enable disable HTTP/2 support. + /// Warning: HTTP/2 support is very limited + /// - only enabled when both client and server supports it (no protocol changing in proxy) + /// - cannot modify the request/response (e.g header modifications in BeforeRequest/Response events are ignored) + /// + public bool EnableHttp2 { get; set; } = false; /// - /// Should we check for certificare revocation during SSL authentication to servers + /// Should we check for certificate revocation during SSL authentication to servers /// Note: If enabled can reduce performance. Defaults to false. /// public X509RevocationMode CheckCertificateRevocation { get; set; } @@ -169,7 +177,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, /// When enabled, as soon as we receive a client connection we concurrently initiate /// corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request /// we will have the server connection immediately ready or in the process of getting ready. - /// If a server connection is available in cache then this prefetch task will immediatly return with the available connection from cache. + /// If a server connection is available in cache then this prefetch task will immediately return with the available connection from cache. /// Defaults to true. /// public bool EnableTcpServerConnectionPrefetch { get; set; } = true; @@ -380,7 +388,7 @@ public void AddEndPoint(ProxyEndPoint endPoint) /// /// Remove a proxy end point. - /// Will throw error if the end point does'nt exist. + /// Will throw error if the end point doesn't exist. /// /// The existing endpoint to remove. public void RemoveEndPoint(ProxyEndPoint endPoint) @@ -743,13 +751,11 @@ private void onAcceptConnection(IAsyncResult asyn) /// /// Change the ThreadPool.WorkerThread minThread /// - /// minimum Threads allocated in the ThreadPool + /// minimum Threads allocated in the ThreadPool private void setThreadPoolMinThread(int workerThreads) { - int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads; - - ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads); - ThreadPool.GetMaxThreads(out maxWorkerThreads, out _); + ThreadPool.GetMinThreads(out int minWorkerThreads, out int minCompletionPortThreads); + ThreadPool.GetMaxThreads(out int maxWorkerThreads, out _); minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount)); diff --git a/src/Titanium.Web.Proxy/RequestHandler.cs b/src/Titanium.Web.Proxy/RequestHandler.cs index 1800cc2aa..785639f28 100644 --- a/src/Titanium.Web.Proxy/RequestHandler.cs +++ b/src/Titanium.Web.Proxy/RequestHandler.cs @@ -44,7 +44,7 @@ public partial class ProxyServer /// The https hostname as appeared in CONNECT request if this is a HTTPS request from /// explicit endpoint. /// - /// The Connect request if this is a HTTPS request from explicit endpoint. + /// The Connect request if this is a HTTPS request from explicit endpoint. /// Prefetched server connection for current client using Connect/SNI headers. private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection, CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter, @@ -61,7 +61,7 @@ private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientCon { var cancellationToken = cancellationTokenSource.Token; - // Loop through each subsequest request on this particular client connection + // Loop through each subsequent request on this particular client connection // (assuming HTTP connection is kept alive by client) while (true) { @@ -312,6 +312,8 @@ private async Task handleHttpSessionRequest(string httpCmd, Session if (args.HttpClient.Request.UpgradeToWebSocket) { + args.HttpClient.ConnectRequest.TunnelType = TunnelType.Websocket; + // if upgrading to websocket then relay the request without reading the contents await handleWebSocketUpgrade(httpCmd, args, args.HttpClient.Request, args.HttpClient.Response, args.ProxyClient.ClientStream, args.ProxyClient.ClientStreamWriter, @@ -373,7 +375,7 @@ await clientStreamWriter.WriteResponseStatusAsync(response.HttpVersion, response } /// - /// Prepare the request headers so that we can avoid encodings not parsable by this proxy + /// Prepare the request headers so that we can avoid encodings not parseable by this proxy /// private void prepareRequestHeaders(HeaderCollection requestHeaders) { diff --git a/src/Titanium.Web.Proxy/ResponseHandler.cs b/src/Titanium.Web.Proxy/ResponseHandler.cs index c352523e0..39156f637 100644 --- a/src/Titanium.Web.Proxy/ResponseHandler.cs +++ b/src/Titanium.Web.Proxy/ResponseHandler.cs @@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy public partial class ProxyServer { /// - /// Called asynchronously when a request was successfull and we received the response. + /// Called asynchronously when a request was successful and we received the response. /// /// The session event arguments. /// The task. @@ -92,7 +92,7 @@ private async Task handleHttpSessionResponse(SessionEventArgs args) // clear current response await args.ClearResponse(cancellationToken); var httpCmd = Request.CreateRequestLine(args.HttpClient.Request.Method, - args.HttpClient.Request.OriginalUrl, args.HttpClient.Request.HttpVersion); + args.HttpClient.Request.RequestUriString, args.HttpClient.Request.HttpVersion); await handleHttpSessionRequest(httpCmd, args, null, args.ClientConnection.NegotiatedApplicationProtocol, cancellationToken, args.CancellationTokenSource); return; @@ -125,7 +125,6 @@ await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None, } args.TimeLine["Response Sent"] = DateTime.Now; - } /// diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj index e613fa06a..d24fa80be 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj @@ -12,11 +12,13 @@ - - - + + + + + diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj index 86b3387eb..f7387218e 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj @@ -12,9 +12,8 @@ - - - + + @@ -35,6 +34,10 @@ + + + + diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj index 4dd4ad9a6..6da302743 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj @@ -1,7 +1,7 @@  - net45;netstandard2.0 + net45;netstandard2.0;netcoreapp2.1 Titanium.Web.Proxy false True @@ -15,24 +15,23 @@ - - 4.4.0 + 4.5.0 - 4.4.1 + 4.5.1 - 4.4.0 + 4.5.0 - 4.4.1 + 4.5.1 @@ -40,6 +39,10 @@ + + + + True diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec index 378bd2839..d548d78f0 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec @@ -15,16 +15,20 @@ - - - - + + + + + + + + diff --git a/src/Titanium.Web.Proxy/TransparentClientHandler.cs b/src/Titanium.Web.Proxy/TransparentClientHandler.cs index a8529a1ed..c929c567d 100644 --- a/src/Titanium.Web.Proxy/TransparentClientHandler.cs +++ b/src/Titanium.Web.Proxy/TransparentClientHandler.cs @@ -67,7 +67,7 @@ private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConn X509Certificate2 certificate = null; try { - sslStream = new SslStream(clientStream, true); + sslStream = new SslStream(clientStream, false); string certName = HttpHelper.GetWildCardDomainName(httpsHostName); certificate = endPoint.GenericCertificate ?? @@ -112,7 +112,7 @@ private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConn var data = BufferPool.GetBuffer(BufferSize); try { - // clientStream.Available sbould be at most BufferSize because it is using the same buffer size + // clientStream.Available should be at most BufferSize because it is using the same buffer size await clientStream.ReadAsync(data, 0, available, cancellationToken); serverStream = connection.Stream; await serverStream.WriteAsync(data, 0, available, cancellationToken); diff --git a/src/Titanium.Web.Proxy/WinAuthHandler.cs b/src/Titanium.Web.Proxy/WinAuthHandler.cs index 05171e137..51eef6ede 100644 --- a/src/Titanium.Web.Proxy/WinAuthHandler.cs +++ b/src/Titanium.Web.Proxy/WinAuthHandler.cs @@ -150,7 +150,7 @@ private async Task handle401UnAuthorized(SessionEventArgs args) } // Need to revisit this. - // Should we cache all Set-Cokiee headers from server during auth process + // Should we cache all Set-Cookie headers from server during auth process // and send it to client after auth? // Let ResponseHandler send the updated request diff --git a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs index cbcf7a3b6..701cccca2 100644 --- a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs +++ b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs @@ -20,7 +20,7 @@ public async Task Post(string server, int port, string content) var request = new Request { Method = "POST", - OriginalUrl = "/", + RequestUriString = "/", HttpVersion = new Version(1, 1) }; request.Headers.AddHeader(KnownHeaders.Host, server); diff --git a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs index e5cae16f7..9733568fc 100644 --- a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs +++ b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs @@ -26,7 +26,7 @@ internal static Request ParseRequest(string messageText, bool requireBody) RequestResponseBase request = new Request() { Method = method, - OriginalUrl = url, + RequestUriString = url, HttpVersion = version }; while (!string.IsNullOrEmpty(line = reader.ReadLine())) @@ -43,7 +43,7 @@ internal static Request ParseRequest(string messageText, bool requireBody) if (!requireBody) return request as Request; - if (ParseBody(reader, ref request)) + if (parseBody(reader, ref request)) return request as Request; } catch { } @@ -84,7 +84,7 @@ internal static Response ParseResponse(string messageText) if (line?.Length != 0) return null; - if (ParseBody(reader, ref response)) + if (parseBody(reader, ref response)) return response as Response; } catch { } @@ -92,7 +92,7 @@ internal static Response ParseResponse(string messageText) return null; } - private static bool ParseBody(StringReader reader, ref RequestResponseBase obj) + private static bool parseBody(StringReader reader, ref RequestResponseBase obj) { obj.OriginalContentLength = obj.ContentLength; if (obj.ContentLength <= 0) diff --git a/tests/Titanium.Web.Proxy.IntegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj b/tests/Titanium.Web.Proxy.IntegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj index 5da157f06..95e3124c0 100644 --- a/tests/Titanium.Web.Proxy.IntegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj +++ b/tests/Titanium.Web.Proxy.IntegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.2 @@ -17,7 +17,7 @@ - + diff --git a/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs b/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs index 4d8afa358..12bdd1ae1 100644 --- a/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs +++ b/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs @@ -11,22 +11,22 @@ namespace Titanium.Web.Proxy.UnitTests public class SystemProxyTest { [TestMethod] - public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() + public void CompareProxyAddressReturnedByWebProxyAndWinHttpProxyResolver() { var proxyManager = new SystemProxyManager(); try { - CompareUrls(); + compareUrls(); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Http); - CompareUrls(); + compareUrls(); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Https); - CompareUrls(); + compareUrls(); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.AllHttp); - CompareUrls(); + compareUrls(); // for this test you need to add a proxy.pac file to a local webserver //function FindProxyForURL(url, host) @@ -43,25 +43,25 @@ public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() //CompareUrls(); proxyManager.SetProxyOverride("<-loopback>"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride(""); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("yahoo.com"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("http://*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("<-loopback>;*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("<-loopback>;*.local;"); - CompareUrls(); + compareUrls(); } finally { @@ -69,7 +69,7 @@ public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() } } - private void CompareUrls() + private void compareUrls() { var webProxy = WebRequest.GetSystemWebProxy(); diff --git a/tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj b/tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj index dff5cb58c..9e4519ec4 100644 --- a/tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj +++ b/tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj @@ -7,7 +7,7 @@ - +