Esempio n. 1
0
 internal bool Attach(bool bCollectGWInfo)
 {
     if (!this._bIsAttached)
     {
         if (bCollectGWInfo)
         {
             this.CollectConnectoidAndGatewayInfo();
         }
         WinINETProxyInfo oNewInfo = new WinINETProxyInfo();
         oNewInfo.bUseManualProxies = true;
         oNewInfo.bAllowDirect      = true;
         oNewInfo.sHttpProxy        = KPCONFIG.sKProxyListenHostPort;
         if (KPCONFIG.bCaptureCONNECT)
         {
             oNewInfo.sHttpsProxy = KPCONFIG.sKProxyListenHostPort;
         }
         else if (this.piPrior != null)
         {
             oNewInfo.sHttpsProxy = this.piPrior.sHttpsProxy;
         }
         if ((this.piPrior != null) && this.piPrior.bUseManualProxies)
         {
             oNewInfo.sFtpProxy   = this.piPrior.sFtpProxy;
             oNewInfo.sSocksProxy = this.piPrior.sSocksProxy;
         }
         if (KPCONFIG.bCaptureFTP)
         {
             oNewInfo.sFtpProxy = KPCONFIG.sKProxyListenHostPort;
         }
         oNewInfo.sHostsThatBypass = KPCONFIG.sHostsThatBypassKProxy;
         if (KPCONFIG.bHookWithPAC)
         {
             if (KProxyApplication.Prefs.GetBoolPref("KProxy.proxy.pacfile.usefileprotocol", true))
             {
                 oNewInfo.sPACScriptLocation = "file://" + KPCONFIG.GetPath("Pac");
             }
             else
             {
                 oNewInfo.sPACScriptLocation = "http://" + KPCONFIG.sKProxyListenHostPort + "/proxy.pac";
             }
         }
         if (!KPCONFIG.bIsViewOnly)
         {
             if (this.oAllConnectoids.HookConnections(oNewInfo))
             {
                 this._bIsAttached = true;
                 KProxyApplication.OnKProxyAttach();
                 this.WriteAutoProxyPACFile(true);
             }
             else
             {
                 KProxyApplication.DoNotifyUser("Failed to register KProxy as the system proxy.", "Error");
                 _setDynamicRegistryKey(false);
                 return(false);
             }
             _setDynamicRegistryKey(true);
         }
     }
     return(true);
 }
Esempio n. 2
0
        private X509CertificateCollection GetCertificateCollectionFromFile(string sClientCertificateFilename)
        {
            X509CertificateCollection certificates = null;

            if (!string.IsNullOrEmpty(sClientCertificateFilename))
            {
                sClientCertificateFilename = Utilities.EnsurePathIsAbsolute(KPCONFIG.GetPath("Root"), sClientCertificateFilename);
                if (System.IO.File.Exists(sClientCertificateFilename))
                {
                    certificates = new X509CertificateCollection();
                    certificates.Add(X509Certificate.CreateFromCertFile(sClientCertificateFilename));
                    return(certificates);
                }
            }
            return(certificates);
        }
Esempio n. 3
0
        private X509Certificate _GetDefaultCertificate()
        {
            if (KProxyApplication.oDefaultClientCertificate != null)
            {
                return(KProxyApplication.oDefaultClientCertificate);
            }
            X509Certificate certificate = null;

            if (System.IO.File.Exists(KPCONFIG.GetPath("DefaultClientCertificate")))
            {
                certificate = X509Certificate.CreateFromCertFile(KPCONFIG.GetPath("DefaultClientCertificate"));
                if ((certificate != null) && KProxyApplication.Prefs.GetBoolPref("KProxy.network.https.cacheclientcert", true))
                {
                    KProxyApplication.oDefaultClientCertificate = certificate;
                }
            }
            return(certificate);
        }
Esempio n. 4
0
        private static ICertificateProvider LoadOverrideCertProvider()
        {
            string stringPref = KProxyApplication.Prefs.GetStringPref("KProxy.certmaker.assembly", KPCONFIG.GetPath("App") + "CertMaker.dll");

            if (File.Exists(stringPref))
            {
                Assembly assembly;
                try
                {
                    assembly = Assembly.LoadFrom(stringPref);
                    if (!Utilities.KProxyMeetsVersionRequirement(assembly, "Certificate Maker"))
                    {
                        return(null);
                    }
                }
                catch (Exception exception)
                {
                    KProxyApplication.LogAddonException(exception, "Failed to load CertMaker" + stringPref);
                    return(null);
                }
                foreach (Type type in assembly.GetExportedTypes())
                {
                    if ((!type.IsAbstract && type.IsPublic) && (type.IsClass && typeof(ICertificateProvider).IsAssignableFrom(type)))
                    {
                        try
                        {
                            return((ICertificateProvider)Activator.CreateInstance(type));
                        }
                        catch (Exception exception2)
                        {
                            KProxyApplication.DoNotifyUser(string.Format("[Kavprot Proxy] Failure loading {0} CertMaker from {1}: {2}\n\n{3}\n\n{4}", new object[] { type.Name, assembly.CodeBase, exception2.Message, exception2.StackTrace, exception2.InnerException }), "Load Error");
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 5
0
        //internal object _GetTransportContext()
        //{
        //    if (base._httpsStream != null)
        //    {
        //        return base._httpsStream.get_TransportContext();
        //    }
        //    return null;
        //}

        private X509Certificate AttachClientCertificate(Session oS, object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers)
        {
            if (localCertificates.Count > 0)
            {
                this.MarkAsAuthenticated(oS.LocalProcessID);
                oS.oFlags["x-client-cert"] = localCertificates[0].Subject + " Serial#" + localCertificates[0].GetSerialNumberString();
                return(localCertificates[0]);
            }
            if ((remoteCertificate != null) || (acceptableIssuers.Length >= 1))
            {
                X509Certificate certificate = this._GetDefaultCertificate();
                if (certificate != null)
                {
                    this.MarkAsAuthenticated(oS.LocalProcessID);
                    oS.oFlags["x-client-cert"] = certificate.Subject + " Serial#" + certificate.GetSerialNumberString();
                    return(certificate);
                }
                if (KPCONFIG.bShowDefaultClientCertificateNeededPrompt && KProxyApplication.Prefs.GetBoolPref("KProxy.network.https.clientcertificate.ephemeral.prompt-for-missing", true))
                {
                    KProxyApplication.DoNotifyUser("The server [" + targetHost + "] requests a client certificate.\nPlease save a client certificate using the filename:\n\n" + KPCONFIG.GetPath("DefaultClientCertificate"), "Client Certificate Requested");
                    KProxyApplication.Prefs.SetBoolPref("KProxy.network.https.clientcertificate.ephemeral.prompt-for-missing", false);
                }
            }
            return(null);
        }