@@ -118,45 +118,55 @@ private static void HandleClient(ExplicitProxyEndPoint endPoint, TcpClient clien
118
118
}
119
119
120
120
//This is called when requests are routed through router to this endpoint
121
+ //For ssl requests
121
122
private static void HandleClient ( TransparentProxyEndPoint endPoint , TcpClient tcpClient )
122
123
{
123
- var sslStream = new SslStream ( tcpClient . GetStream ( ) , true ) ;
124
+ Stream clientStream = tcpClient . GetStream ( ) ;
124
125
CustomBinaryReader clientStreamReader = null ;
125
126
StreamWriter clientStreamWriter = null ;
126
127
X509Certificate2 certificate = null ;
127
128
128
- //if(endPoint.UseServerNameIndication)
129
- //{
130
- // //implement in future once SNI supported by SSL stream
131
- // certificate = CertManager.CreateCertificate(endPoint.GenericCertificateName);
132
- //}
133
- //else
134
- certificate = CertManager . CreateCertificate ( endPoint . GenericCertificateName ) ;
135
-
136
- try
129
+ if ( endPoint . EnableSsl )
137
130
{
138
- //Successfully managed to authenticate the client using the fake certificate
139
- sslStream . AuthenticateAsServer ( certificate , false ,
140
- SslProtocols . Tls , false ) ;
131
+ var sslStream = new SslStream ( clientStream , true ) ;
132
+ //if(endPoint.UseServerNameIndication)
133
+ //{
134
+ // //implement in future once SNI supported by SSL stream
135
+ // certificate = CertManager.CreateCertificate(endPoint.GenericCertificateName);
136
+ //}
137
+ //else
138
+ certificate = CertManager . CreateCertificate ( endPoint . GenericCertificateName ) ;
139
+
140
+ try
141
+ {
142
+ //Successfully managed to authenticate the client using the fake certificate
143
+ sslStream . AuthenticateAsServer ( certificate , false ,
144
+ SslProtocols . Tls , false ) ;
141
145
142
- clientStreamReader = new CustomBinaryReader ( sslStream , Encoding . ASCII ) ;
143
- clientStreamWriter = new StreamWriter ( sslStream ) ;
144
- //HTTPS server created - we can now decrypt the client's traffic
146
+ clientStreamReader = new CustomBinaryReader ( sslStream , Encoding . ASCII ) ;
147
+ clientStreamWriter = new StreamWriter ( sslStream ) ;
148
+ //HTTPS server created - we can now decrypt the client's traffic
145
149
150
+ }
151
+ catch ( Exception )
152
+ {
153
+ if ( sslStream != null )
154
+ sslStream . Dispose ( ) ;
155
+
156
+ Dispose ( tcpClient , sslStream , clientStreamReader , clientStreamWriter , null ) ;
157
+ return ;
158
+ }
159
+ clientStream = sslStream ;
146
160
}
147
- catch ( Exception )
161
+ else
148
162
{
149
- if ( sslStream != null )
150
- sslStream . Dispose ( ) ;
151
-
152
- Dispose ( tcpClient , sslStream , clientStreamReader , clientStreamWriter , null ) ;
153
- return ;
163
+ clientStreamReader = new CustomBinaryReader ( clientStream , Encoding . ASCII ) ;
154
164
}
155
165
156
166
var httpCmd = clientStreamReader . ReadLine ( ) ;
157
167
158
168
//Now create the request
159
- HandleHttpSessionRequest ( tcpClient , httpCmd , sslStream , clientStreamReader , clientStreamWriter ,
169
+ HandleHttpSessionRequest ( tcpClient , httpCmd , clientStream , clientStreamReader , clientStreamWriter ,
160
170
true ) ;
161
171
}
162
172
0 commit comments