Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit ae0239d

Browse files
Merge pull request #195 from justcoding121/develop
Merge Beta with develop
2 parents 142cabc + 66ac567 commit ae0239d

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public ProxyTestController()
1818
{
1919
proxyServer = new ProxyServer();
2020
proxyServer.TrustRootCertificate = true;
21+
22+
//optionally set the Certificate Engine
23+
//Under Mono only BouncyCastle will be supported
24+
//proxyServer.CertificateEngine = Network.CertificateEngine.BouncyCastle;
25+
2126
requestBodyHistory = new Dictionary<Guid, string>();
2227
}
2328

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var proxyServer = new ProxyServer();
4343
//locally trust root certificate used by this proxy
4444
proxyServer.TrustRootCertificate = true;
4545

46+
//optionally set the Certificate Engine
47+
//Under Mono only BouncyCastle will be supported
48+
//proxyServer.CertificateEngine = Network.CertificateEngine.BouncyCastle;
49+
4650
proxyServer.BeforeRequest += OnRequest;
4751
proxyServer.BeforeResponse += OnResponse;
4852
proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;

Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public Func<SessionEventArgs, Task<ExternalProxy>> GetCustomUpStreamHttpsProxyFu
205205
/// <summary>
206206
/// List of supported Ssl versions
207207
/// </summary>
208-
public SslProtocols SupportedSslProtocols { get; set; } = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Ssl3;
208+
public SslProtocols SupportedSslProtocols { get; set; } = SslProtocols.Tls
209+
| SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Ssl3;
209210

210211
/// <summary>
211212
/// Constructor
@@ -242,7 +243,8 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName)
242243
/// <param name="endPoint"></param>
243244
public void AddEndPoint(ProxyEndPoint endPoint)
244245
{
245-
if (ProxyEndPoints.Any(x => x.IpAddress.Equals(endPoint.IpAddress) && endPoint.Port != 0 && x.Port == endPoint.Port))
246+
if (ProxyEndPoints.Any(x => x.IpAddress.Equals(endPoint.IpAddress)
247+
&& endPoint.Port != 0 && x.Port == endPoint.Port))
246248
{
247249
throw new Exception("Cannot add another endpoint to same port & ip address");
248250
}
@@ -281,6 +283,11 @@ public void RemoveEndPoint(ProxyEndPoint endPoint)
281283
/// <param name="endPoint"></param>
282284
public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint)
283285
{
286+
if(RunTime.IsRunningOnMono())
287+
{
288+
throw new Exception("Mono Runtime do not support system proxy settings.");
289+
}
290+
284291
ValidateEndPointAsSystemProxy(endPoint);
285292

286293
//clear any settings previously added
@@ -304,6 +311,11 @@ public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint)
304311
/// <param name="endPoint"></param>
305312
public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint)
306313
{
314+
if (RunTime.IsRunningOnMono())
315+
{
316+
throw new Exception("Mono Runtime do not support system proxy settings.");
317+
}
318+
307319
ValidateEndPointAsSystemProxy(endPoint);
308320

309321
if (!endPoint.EnableSsl)
@@ -312,14 +324,17 @@ public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint)
312324
}
313325

314326
//clear any settings previously added
315-
ProxyEndPoints.OfType<ExplicitProxyEndPoint>().ToList().ForEach(x => x.IsSystemHttpsProxy = false);
316-
327+
ProxyEndPoints.OfType<ExplicitProxyEndPoint>()
328+
.ToList()
329+
.ForEach(x => x.IsSystemHttpsProxy = false);
317330

318331
//If certificate was trusted by the machine
319332
if (certValidated)
320333
{
321334
systemProxySettingsManager.SetHttpsProxy(
322-
Equals(endPoint.IpAddress, IPAddress.Any) | Equals(endPoint.IpAddress, IPAddress.Loopback) ? "127.0.0.1" : endPoint.IpAddress.ToString(),
335+
Equals(endPoint.IpAddress, IPAddress.Any) |
336+
Equals(endPoint.IpAddress, IPAddress.Loopback) ?
337+
"127.0.0.1" : endPoint.IpAddress.ToString(),
323338
endPoint.Port);
324339
}
325340

@@ -329,14 +344,20 @@ public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint)
329344
#if !DEBUG
330345
firefoxProxySettingsManager.AddFirefox();
331346
#endif
332-
Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy", endPoint.IpAddress, endPoint.Port);
347+
Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy",
348+
endPoint.IpAddress, endPoint.Port);
333349
}
334350

335351
/// <summary>
336352
/// Remove any HTTP proxy setting of current machien
337353
/// </summary>
338354
public void DisableSystemHttpProxy()
339355
{
356+
if (RunTime.IsRunningOnMono())
357+
{
358+
throw new Exception("Mono Runtime do not support system proxy settings.");
359+
}
360+
340361
systemProxySettingsManager.RemoveHttpProxy();
341362
}
342363

@@ -345,6 +366,11 @@ public void DisableSystemHttpProxy()
345366
/// </summary>
346367
public void DisableSystemHttpsProxy()
347368
{
369+
if (RunTime.IsRunningOnMono())
370+
{
371+
throw new Exception("Mono Runtime do not support system proxy settings.");
372+
}
373+
348374
systemProxySettingsManager.RemoveHttpsProxy();
349375
}
350376

@@ -353,6 +379,11 @@ public void DisableSystemHttpsProxy()
353379
/// </summary>
354380
public void DisableAllSystemProxies()
355381
{
382+
if (RunTime.IsRunningOnMono())
383+
{
384+
throw new Exception("Mono Runtime do not support system proxy settings.");
385+
}
386+
356387
systemProxySettingsManager.DisableAllProxy();
357388
}
358389

@@ -372,7 +403,7 @@ public void Start()
372403

373404
certValidated = certificateCacheManager.CreateTrustedRootCertificate();
374405

375-
if (TrustRootCertificate)
406+
if (TrustRootCertificate)
376407
{
377408
//current user
378409
certificateCacheManager
@@ -383,7 +414,8 @@ public void Start()
383414
.TrustRootCertificate(StoreLocation.LocalMachine, exceptionFunc);
384415
}
385416

386-
if (ForwardToUpstreamGateway && GetCustomUpStreamHttpProxyFunc == null && GetCustomUpStreamHttpsProxyFunc == null)
417+
if (ForwardToUpstreamGateway && GetCustomUpStreamHttpProxyFunc == null
418+
&& GetCustomUpStreamHttpsProxyFunc == null)
387419
{
388420
GetCustomUpStreamHttpProxyFunc = GetSystemUpStreamProxy;
389421
GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy;

0 commit comments

Comments
 (0)