justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.94k stars 619 forks source link

Question : How to install certificate for local machine #958

Open Tushar-Mahajan41 opened 1 year ago

Tushar-Mahajan41 commented 1 year ago

Problem: I have used proxy server in a window form app and it will be installed in machine and I am inspecting the traffic and take specific action(s). Every user can run this application . When the application runs it asks to install titanium proxy certificate . I want certificate can be installed manually for once for one machine not for every user . How can i do this

This is how i am starting the proxy server

` proxyServer = new ProxyServer();

            proxyServer.CertificateManager.CertificateEngine = Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows;

            ExplicitProxyEndPoint explicitEndPoint = new(IPAddress.Any, 8000, true);

            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();
            proxyServer.BeforeResponse += OnResponse;
            proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
            proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);`

Thanks

trontronicent commented 1 year ago

Get the root cert .pfx file, install it via windows crypto snapp-in - install for machine in "trusted root authorities". Now that it's trusted, ensure to load exactly that certificate either by path (or somehow directly via WinCertStore) on app start - and disable overwrite. If overwritten or missing (and thereby rebuilt by the engine) - the trust is useless, as it's a new cert.

I store my root cert for my apps on a central (readonly) shared folder.

_certificateManager.CertificateEngine = Titanium.Web.Proxy.Network.CertificateEngine.DefaultWindows;
_certificateManager.OverwritePfxFile = false;
bool rootCertLoaded = _certificateManager.LoadRootCertificate("pathToCert", "rootCertPass", false, X509KeyStorageFlags.DefaultKeySet);

if (rootCertLoaded && _certificateManager.IsRootCertificateMachineTrusted()) 
{
         foreach (var proxyServer in proxyServers)
         {
                 proxyServer.CertificateManager = _certificateManager;
         }
}