diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 8f75c6f..73cc0bf 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -511,6 +511,27 @@ public function createCa(int $caExpireInDays): void $this->trustCa($caPemPath); } + /** + * If CA and root certificates exist, remove them. + */ + public function removeCa(): void + { + foreach (['pem', 'key', 'srl'] as $ending) { + $path = $this->caPath('LaravelValetCASelfSigned.' . $ending); + + if ($this->files->exists($path)) { + $this->files->unlink($path); + } + } + + $cName = 'Laravel Valet CA Self Signed CN'; + + $this->cli->run(sprintf( + 'sudo security delete-certificate -c "%s" /Library/Keychains/System.keychain', + $cName + )); + } + /** * Create and trust a certificate for the given URL. * diff --git a/cli/app.php b/cli/app.php index a7f9882..7bd4889 100644 --- a/cli/app.php +++ b/cli/app.php @@ -512,6 +512,8 @@ function (ConsoleCommandEvent $event) { info('Removing certificates for all Secured sites...'); Site::unsecureAll(); + info('Removing certificate authority...'); + Site::removeCa(); info('Removing Nginx and configs...'); Nginx::uninstall(); info('Removing Dnsmasq and configs...'); diff --git a/tests/CliTest.php b/tests/CliTest.php index aa22606..a509153 100644 --- a/tests/CliTest.php +++ b/tests/CliTest.php @@ -778,6 +778,7 @@ public function test_force_uninstall_command() $site = Mockery::mock(RealSite::class); $site->shouldReceive('unsecureAll')->once(); + $site->shouldReceive('removeCa')->once(); $site->shouldReceive('uninstallLoopback')->once(); $nginx = Mockery::mock(Nginx::class);