Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Trusting CA when securing sites #1488

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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