@@ -86,6 +86,10 @@ public async Task Run(CancellationToken? cancellationToken)
8686
8787 _proxyServer . CertificateManager . RootCertificateName = "Dev Proxy CA" ;
8888 _proxyServer . CertificateManager . CertificateStorage = new CertificateDiskCache ( ) ;
89+ // we need to change this to a value lower than 397
90+ // to avoid the ERR_CERT_VALIDITY_TOO_LONG error in Edge
91+ _proxyServer . CertificateManager . CertificateValidDays = 365 ;
92+ _proxyServer . CertificateManager . CreateRootCertificate ( ) ;
8993 _proxyServer . BeforeRequest += OnRequest ;
9094 _proxyServer . BeforeResponse += OnBeforeResponse ;
9195 _proxyServer . AfterResponse += OnAfterResponse ;
@@ -95,18 +99,16 @@ public async Task Run(CancellationToken? cancellationToken)
9599
96100 var ipAddress = string . IsNullOrEmpty ( _config . IPAddress ) ? IPAddress . Any : IPAddress . Parse ( _config . IPAddress ) ;
97101 _explicitEndPoint = new ExplicitProxyEndPoint ( ipAddress , _config . Port , true ) ;
98- if ( ! RunTime . IsWindows )
102+ // Fired when a CONNECT request is received
103+ _explicitEndPoint . BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest ;
104+ if ( _config . InstallCert )
99105 {
100- // we need to change this to a value lower than 397
101- // to avoid the ERR_CERT_VALIDITY_TOO_LONG error in Edge
102- _proxyServer . CertificateManager . CertificateValidDays = 365 ;
103- // we need to call it explicitly for non-Windows OSes because it's
104- // a part of the SetAsSystemHttpProxy that works only on Windows
105106 _proxyServer . CertificateManager . EnsureRootCertificate ( ) ;
106107 }
107-
108- // Fired when a CONNECT request is received
109- _explicitEndPoint . BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest ;
108+ else
109+ {
110+ _explicitEndPoint . GenericCertificate = _proxyServer . CertificateManager . LoadRootCertificate ( ) ;
111+ }
110112
111113 _proxyServer . AddEndPoint ( _explicitEndPoint ) ;
112114 _proxyServer . Start ( ) ;
@@ -119,18 +121,24 @@ public async Task Run(CancellationToken? cancellationToken)
119121 _logger . LogInfo ( $ "Listening on { endPoint . IpAddress } :{ endPoint . Port } ...") ;
120122 }
121123
122- if ( RunTime . IsWindows )
123- {
124- // Only explicit proxies can be set as system proxy!
125- _proxyServer . SetAsSystemHttpsProxy ( _explicitEndPoint ) ;
126- }
127- else if ( RunTime . IsMac )
124+ if ( _config . AsSystemProxy )
128125 {
129- ToggleSystemProxy ( ToggleSystemProxyAction . On , _config . IPAddress , _config . Port ) ;
126+ if ( RunTime . IsWindows )
127+ {
128+ _proxyServer . SetAsSystemHttpsProxy ( _explicitEndPoint ) ;
129+ }
130+ else if ( RunTime . IsMac )
131+ {
132+ ToggleSystemProxy ( ToggleSystemProxyAction . On , _config . IPAddress , _config . Port ) ;
133+ }
134+ else
135+ {
136+ _logger . LogWarn ( "Configure your operating system to use this proxy's port and address" ) ;
137+ }
130138 }
131139 else
132140 {
133- _logger . LogWarn ( "Configure your operating system to use this proxy's port and address" ) ;
141+ _logger . LogInfo ( "Configure your application to use this proxy's port and address" ) ;
134142 }
135143
136144 _logger . LogInfo ( "Press CTRL+C to stop Dev Proxy" ) ;
@@ -156,7 +164,8 @@ private void FirstRunSetup()
156164 {
157165 if ( ! RunTime . IsMac ||
158166 _config . NoFirstRun ||
159- ! IsFirstRun ( ) )
167+ ! IsFirstRun ( ) ||
168+ ! _config . InstallCert )
160169 {
161170 return ;
162171 }
@@ -340,7 +349,7 @@ private void StopProxy()
340349 _proxyServer . Stop ( ) ;
341350 }
342351
343- if ( RunTime . IsMac )
352+ if ( RunTime . IsMac && _config . AsSystemProxy )
344353 {
345354 ToggleSystemProxy ( ToggleSystemProxyAction . Off ) ;
346355 }
@@ -562,4 +571,4 @@ Task OnCertificateSelection(object sender, CertificateSelectionEventArgs e)
562571 // set e.clientCertificate to override
563572 return Task . CompletedTask ;
564573 }
565- }
574+ }
0 commit comments