Skip to content

Commit a39a7b0

Browse files
committed
prevent the old cert from being removed if the trust ca command is canceled
1 parent 72845a3 commit a39a7b0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cli/Valet/Site.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,18 @@ public function secure(string $url, ?string $siteConf = null, int $certificateEx
475475
// Extract in order to later preserve custom PHP version config when securing
476476
$phpVersion = $this->customPhpVersion($url);
477477

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 be not removed.
480480
$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);
481485

482486
$this->files->ensureDirExists($this->certificatesPath(), user());
483487

484488
$this->files->ensureDirExists($this->nginxPath(), user());
485489

486-
$caExpireInDate = (new \DateTime())->diff(new \DateTime("+{$caExpireInYears} years"));
487-
488-
$this->createCa($caExpireInDate->format('%a'));
489490
$this->createCertificate($url, $certificateExpireInDays);
490491

491492
$siteConf = $this->buildSecureNginxServer($url, $siteConf);

0 commit comments

Comments
 (0)