/// <summary>
        /// Start this proxy server
        /// </summary>
        public void Start()
        {
            if (proxyRunning)
            {
                throw new Exception("Proxy is already running.");
            }

            if (ForwardToUpstreamGateway && GetCustomUpStreamHttpProxyFunc == null &&
                GetCustomUpStreamHttpsProxyFunc == null)
            {
                GetCustomUpStreamHttpProxyFunc  = GetSystemUpStreamProxy;
                GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy;
            }

            foreach (var endPoint in ProxyEndPoints)
            {
                Listen(endPoint);
            }

            CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);

            if (!RunTime.IsRunningOnMono)
            {
                //clear orphaned windows auth states every 2 minutes
                WinAuthEndPoint.ClearIdleStates(2);
            }

            proxyRunning = true;
        }
예제 #2
0
        public async Task Simple_Create_Certificate_Stress_Test()
        {
            var tasks = new List <Task>();

            var mgr = new CertificateManager("Titanium", "Titanium Root Certificate Authority",
                                             new Lazy <Action <Exception> >(() => (e => { })).Value);

            mgr.ClearIdleCertificates(1);

            for (int i = 0; i < 1000; i++)
            {
                foreach (var host in hostNames)
                {
                    tasks.Add(Task.Run(async() =>
                    {
                        await Task.Delay(random.Next(0, 10) * 1000);

                        //get the connection
                        var certificate = mgr.CreateCertificate(host, false);

                        Assert.IsNotNull(certificate);
                    }));
                }
            }

            await Task.WhenAll(tasks.ToArray());

            mgr.StopClearIdleCertificates();
        }
예제 #3
0
        // uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
        //[TestMethod]
        public async Task Simple_Create_Win_Certificate_Test()
        {
            var tasks = new List <Task>();

            var mgr = new CertificateManager(null, null, false, false, false, new Lazy <ExceptionHandler>(() => (e =>
            {
                Debug.WriteLine(e.ToString());
                Debug.WriteLine(e.InnerException?.ToString());
            })).Value)
            {
                CertificateEngine = CertificateEngine.DefaultWindows
            };

            mgr.CreateRootCertificate();
            mgr.TrustRootCertificate(true);
            mgr.ClearIdleCertificates();

            for (int i = 0; i < 5; i++)
            {
                tasks.AddRange(hostNames.Select(host => Task.Run(() =>
                {
                    // get the connection
                    var certificate = mgr.CreateCertificate(host, false);
                    Assert.IsNotNull(certificate);
                })));
            }

            await Task.WhenAll(tasks.ToArray());

            mgr.RemoveTrustedRootCertificate(true);
            mgr.StopClearIdleCertificates();
        }
예제 #4
0
        public async Task Simple_Create_Win_Certificate_Test()
        {
            var tasks = new List <Task>();

            var mgr = new CertificateManager(null, null, false, false, false, new Lazy <Action <Exception> >(() => (e =>
            {
                //Console.WriteLine(e.ToString() + e.InnerException != null ? e.InnerException.ToString() : string.Empty);
            })).Value);

            mgr.CertificateEngine = CertificateEngine.DefaultWindows;
            mgr.CreateRootCertificate(true);
            mgr.TrustRootCertificate(true);
            mgr.ClearIdleCertificates();

            for (int i = 0; i < 5; i++)
            {
                foreach (string host in hostNames)
                {
                    tasks.Add(Task.Run(() =>
                    {
                        //get the connection
                        var certificate = mgr.CreateCertificate(host, false);
                        Assert.IsNotNull(certificate);
                    }));
                }
            }

            await Task.WhenAll(tasks.ToArray());

            mgr.RemoveTrustedRootCertificate(true);
            mgr.StopClearIdleCertificates();
        }
예제 #5
0
        /// <summary>
        /// Start this proxy server
        /// </summary>
        public void Start()
        {
            if (proxyRunning)
            {
                throw new Exception("Proxy is already running.");
            }

            certificateCacheManager = new CertificateManager(RootCertificateIssuerName,
                                                             RootCertificateName, ExceptionFunc);

            certValidated = certificateCacheManager.CreateTrustedRootCertificate();

            if (TrustRootCertificate)
            {
                certificateCacheManager.TrustRootCertificate();
            }

            if (ForwardToUpstreamGateway && GetCustomUpStreamHttpProxyFunc == null && GetCustomUpStreamHttpsProxyFunc == null)
            {
                GetCustomUpStreamHttpProxyFunc  = GetSystemUpStreamProxy;
                GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy;
            }

            foreach (var endPoint in ProxyEndPoints)
            {
                Listen(endPoint);
            }

            certificateCacheManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);

            proxyRunning = true;
        }
예제 #6
0
        /// <summary>
        /// Start this proxy server
        /// </summary>
        public void Start()
        {
            if (ProxyRunning)
            {
                throw new Exception("Proxy is already running.");
            }

            //clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
            //due to non gracious proxy shutdown before or something else
            if (systemProxySettingsManager != null && RunTime.IsWindows)
            {
                var proxyInfo = systemProxySettingsManager.GetProxyInfoFromRegistry();
                if (proxyInfo.Proxies != null)
                {
                    var protocolToRemove = ProxyProtocolType.None;
                    foreach (var proxy in proxyInfo.Proxies.Values)
                    {
                        if ((proxy.HostName == "127.0.0.1" ||
                             proxy.HostName.Equals("localhost", StringComparison.OrdinalIgnoreCase)) &&
                            ProxyEndPoints.Any(x => x.Port == proxy.Port))
                        {
                            protocolToRemove |= proxy.ProtocolType;
                        }
                    }

                    if (protocolToRemove != ProxyProtocolType.None)
                    {
                        //do not restore to any of listening address when we quit
                        systemProxySettingsManager.RemoveProxy(protocolToRemove, false);
                    }
                }
            }

            if (ForwardToUpstreamGateway && GetCustomUpStreamProxyFunc == null && systemProxySettingsManager != null)
            {
                // Use WinHttp to handle PAC/WAPD scripts.
                systemProxyResolver = new WinHttpWebProxyFinder();
                systemProxyResolver.LoadFromIE();

                GetCustomUpStreamProxyFunc = GetSystemUpStreamProxy;
            }

            ProxyRunning = true;

            foreach (var endPoint in ProxyEndPoints)
            {
                Listen(endPoint);
            }

            CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);

            if (RunTime.IsWindows && !RunTime.IsRunningOnMono)
            {
                //clear orphaned windows auth states every 2 minutes
                WinAuthEndPoint.ClearIdleStates(2);
            }
        }
예제 #7
0
        /// <summary>
        ///     Start this proxy server instance.
        /// </summary>
        public void Start()
        {
            if (ProxyRunning)
            {
                throw new Exception("Proxy is already running.");
            }

            if (ProxyEndPoints.OfType <ExplicitProxyEndPoint>().Any(x => x.GenericCertificate == null))
            {
                CertificateManager.EnsureRootCertificate();
            }

            // clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
            // due to ungracious proxy shutdown before or something else
            if (systemProxySettingsManager != null && RunTime.IsWindows)
            {
                var proxyInfo = systemProxySettingsManager.GetProxyInfoFromRegistry();
                if (proxyInfo.Proxies != null)
                {
                    var protocolToRemove = ProxyProtocolType.None;
                    foreach (var proxy in proxyInfo.Proxies.Values)
                    {
                        if (NetworkHelper.IsLocalIpAddress(proxy.HostName) &&
                            ProxyEndPoints.Any(x => x.Port == proxy.Port))
                        {
                            protocolToRemove |= proxy.ProtocolType;
                        }
                    }

                    if (protocolToRemove != ProxyProtocolType.None)
                    {
                        systemProxySettingsManager.RemoveProxy(protocolToRemove, false);
                    }
                }
            }

            if (ForwardToUpstreamGateway && GetCustomUpStreamProxyFunc == null && systemProxySettingsManager != null)
            {
                // Use WinHttp to handle PAC/WAPD scripts.
                systemProxyResolver = new WinHttpWebProxyFinder();
                systemProxyResolver.LoadFromIE();

                GetCustomUpStreamProxyFunc = getSystemUpStreamProxy;
            }

            ProxyRunning = true;

            CertificateManager.ClearIdleCertificates();

            foreach (var endPoint in ProxyEndPoints)
            {
                listen(endPoint);
            }
        }
예제 #8
0
        /// <summary>
        /// Start this proxy server
        /// </summary>
        public void Start()
        {
            if (proxyRunning)
            {
                throw new Exception("Proxy is already running.");
            }

            certificateCacheManager = new CertificateManager(RootCertificateIssuerName,
                                                             RootCertificateName);

            certTrusted = certificateCacheManager.CreateTrustedRootCertificate();

            foreach (var endPoint in ProxyEndPoints)
            {
                Listen(endPoint);
            }

            certificateCacheManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);

            proxyRunning = true;
        }