Skip to content

Commit

Permalink
Merge pull request #1488 from adrum/fix/trust-ca
Browse files Browse the repository at this point in the history
Require Trusting CA when securing sites
  • Loading branch information
mattstauffer authored Jun 24, 2024
2 parents 35b32b6 + e7c0dba commit 5d4821b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cli/Valet/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,18 @@ public function secure(string $url, ?string $siteConf = null, int $certificateEx
// Extract in order to later preserve custom PHP version config when securing
$phpVersion = $this->customPhpVersion($url);

$this->unsecure($url);

// Create the CA if it doesn't exist.
// If the user cancels the trust operation, the old certificate will not be removed.
$this->files->ensureDirExists($this->caPath(), user());
$caExpireInDate = (new \DateTime())->diff(new \DateTime("+{$caExpireInYears} years"));
$this->createCa($caExpireInDate->format('%a'));

$this->unsecure($url);

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

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

$caExpireInDate = (new \DateTime())->diff(new \DateTime("+{$caExpireInYears} years"));

$this->createCa($caExpireInDate->format('%a'));
$this->createCertificate($url, $certificateExpireInDays);

$siteConf = $this->buildSecureNginxServer($url, $siteConf);
Expand Down Expand Up @@ -640,9 +641,14 @@ public function createSigningRequest(string $url, string $keyPath, string $csrPa
*/
public function trustCa(string $caPemPath): void
{
$this->cli->run(sprintf(
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"', $caPemPath
info('Trusting Laravel Valet Certificate Authority...');
$result = $this->cli->run(sprintf(
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"',
$caPemPath
));
if ($result) {
throw new DomainException('The Certificate Authority must be trusted. Please run the command again.');
}
}

/**
Expand Down

0 comments on commit 5d4821b

Please sign in to comment.