@@ -475,17 +475,18 @@ public function secure(string $url, ?string $siteConf = null, int $certificateEx
475
475
// Extract in order to later preserve custom PHP version config when securing
476
476
$ phpVersion = $ this ->customPhpVersion ($ url );
477
477
478
- $ this -> unsecure ( $ url );
479
-
478
+ // Create the CA if it doesn't exist.
479
+ // If the user cancels the trust operation, the old certificate will not be removed.
480
480
$ this ->files ->ensureDirExists ($ this ->caPath (), user ());
481
+ $ caExpireInDate = (new \DateTime ())->diff (new \DateTime ("+ {$ caExpireInYears } years " ));
482
+ $ this ->createCa ($ caExpireInDate ->format ('%a ' ));
483
+
484
+ $ this ->unsecure ($ url );
481
485
482
486
$ this ->files ->ensureDirExists ($ this ->certificatesPath (), user ());
483
487
484
488
$ this ->files ->ensureDirExists ($ this ->nginxPath (), user ());
485
489
486
- $ caExpireInDate = (new \DateTime ())->diff (new \DateTime ("+ {$ caExpireInYears } years " ));
487
-
488
- $ this ->createCa ($ caExpireInDate ->format ('%a ' ));
489
490
$ this ->createCertificate ($ url , $ certificateExpireInDays );
490
491
491
492
$ siteConf = $ this ->buildSecureNginxServer ($ url , $ siteConf );
@@ -640,9 +641,14 @@ public function createSigningRequest(string $url, string $keyPath, string $csrPa
640
641
*/
641
642
public function trustCa (string $ caPemPath ): void
642
643
{
643
- $ this ->cli ->run (sprintf (
644
- 'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s" ' , $ caPemPath
644
+ info ('Trusting Laravel Valet Certificate Authority... ' );
645
+ $ result = $ this ->cli ->run (sprintf (
646
+ 'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s" ' ,
647
+ $ caPemPath
645
648
));
649
+ if ($ result ) {
650
+ throw new DomainException ('The Certificate Authority must be trusted. Please run the command again. ' );
651
+ }
646
652
}
647
653
648
654
/**
0 commit comments