コード例 #1
0
 internal Proxy(bool bIsPrimary)
 {
     if (bIsPrimary)
     {
         try
         {
             NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(this.NetworkChange_NetworkAvailabilityChanged);
             NetworkChange.NetworkAddressChanged      += new NetworkAddressChangedEventHandler(this.NetworkChange_NetworkAddressChanged);
         }
         catch
         {
         }
         try
         {
             this.watcherPrefNotify = new PreferenceBag.PrefWatcher?(KProxyApplication.Prefs.AddWatcher("KProxy.network", new EventHandler <PrefChangeEventArgs>(this.onNetworkPrefsChange)));
             this.SetDefaultEgressEndPoint(KProxyApplication.Prefs["KProxy.network.egress.ip"]);
             KPCONFIG.SetNoDecryptList(KProxyApplication.Prefs["KProxy.network.https.NoDecryptionHosts"]);
             KPCONFIG.sKProxyListenHostPort    = KProxyApplication.Prefs.GetStringPref("KProxy.network.proxy.RegistrationHostName", "127.0.0.1") + ":" + KPCONFIG.ListenPort.ToString();
             ClientChatter._cbClientReadBuffer = KProxyApplication.Prefs.GetInt32Pref("KProxy.network.sockets.ClientReadBufferSize", 0x2000);
             ServerChatter._cbServerReadBuffer = KProxyApplication.Prefs.GetInt32Pref("KProxy.network.sockets.ServerReadBufferSize", 0x8000);
         }
         catch
         {
         }
     }
 }
コード例 #2
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);
 }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
 private static void _setDynamicRegistryKey(bool bAttached)
 {
     if (!KPCONFIG.bIsViewOnly)
     {
         try
         {
             RegistryKey key = Registry.CurrentUser.CreateSubKey(KPCONFIG.GetRegPath("Dynamic"));
             if (key != null)
             {
                 key.SetValue("Attached", bAttached ? 1 : 0, RegistryValueKind.DWord);
                 key.Close();
             }
         }
         catch (Exception exception)
         {
             //KProxyApplication.Log.LogFormat("KProxy.network.KProxyHook> Unable to set Dynamic registry key; registry permissions likely corrupt. Exception: {0}", new object[] { exception.Message });
         }
     }
 }
コード例 #6
0
 private void onNetworkPrefsChange(object sender, PrefChangeEventArgs oPCE)
 {
     if (oPCE.PrefName == "KProxy.network.sockets.ClientReadBufferSize")
     {
         ClientChatter._cbClientReadBuffer = KProxyApplication.Prefs.GetInt32Pref("KProxy.network.sockets.ClientReadBufferSize", 0x2000);
     }
     if (oPCE.PrefName == "KProxy.network.sockets.ServerReadBufferSize")
     {
         ServerChatter._cbServerReadBuffer = KProxyApplication.Prefs.GetInt32Pref("KProxy.network.sockets.ServerReadBufferSize", 0x8000);
     }
     if (oPCE.PrefName == "KProxy.network.egress.ip")
     {
         this.SetDefaultEgressEndPoint(oPCE.ValueString);
     }
     else if (oPCE.PrefName == "KProxy.network.https.NoDecryptionHosts")
     {
         KPCONFIG.SetNoDecryptList(oPCE.ValueString);
     }
     else if (oPCE.PrefName == "KProxy.network.proxy.RegistrationHostName")
     {
         KPCONFIG.sKProxyListenHostPort = KProxyApplication.Prefs.GetStringPref("KProxy.network.proxy.RegistrationHostName", "127.0.0.1") + ":" + KPCONFIG.ListenPort.ToString();
     }
 }
コード例 #7
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);
        }
コード例 #8
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);
        }