Skip to content

Commit 3c0015c

Browse files
committed
add the ability to see the Certificate Authority expiration date
1 parent 072859e commit 3c0015c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cli/Valet/Site.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ public function secured(): array
437437
/**
438438
* Get all of the URLs with expiration dates that are currently secured.
439439
*/
440-
public function securedWithDates(): array
440+
public function securedWithDates($ca = false): array
441441
{
442-
return collect($this->secured())->map(function ($site) {
442+
$sites = collect($this->secured())->map(function ($site) {
443443
$filePath = $this->certificatesPath().'/'.$site.'.crt';
444444

445445
$expiration = $this->cli->run("openssl x509 -enddate -noout -in $filePath");
@@ -450,7 +450,22 @@ public function securedWithDates(): array
450450
'site' => $site,
451451
'exp' => new DateTime($expiration),
452452
];
453-
})->unique()->values()->all();
453+
})->unique()->values();
454+
455+
if ($ca) {
456+
$filePath = $this->caPath('LaravelValetCASelfSigned.pem');
457+
458+
$expiration = $this->cli->run("openssl x509 -enddate -noout -in $filePath");
459+
460+
$expiration = str_replace('notAfter=', '', $expiration);
461+
462+
$sites->prepend([
463+
'site' => 'Certificate Authority',
464+
'exp' => new DateTime($expiration),
465+
]);
466+
}
467+
468+
return $sites->all();
454469
}
455470

456471
public function isSecured(string $site): bool

cli/app.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ function (ConsoleCommandEvent $event) {
285285
/**
286286
* Display all of the currently secured sites.
287287
*/
288-
$app->command('secured [--expiring] [--days=]', function (OutputInterface $output, $expiring = null, $days = 60) {
288+
$app->command('secured [--expiring] [--days=] [--ca]', function (OutputInterface $output, $expiring = null, $days = 60, $ca = null) {
289289
$now = (new Datetime)->add(new DateInterval('P'.$days.'D'));
290-
$sites = collect(Site::securedWithDates())
290+
$sites = collect(Site::securedWithDates($ca))
291291
->when($expiring, fn ($collection) => $collection->filter(fn ($row) => $row['exp'] < $now))
292292
->map(function ($row) {
293293
return [
@@ -301,6 +301,7 @@ function (ConsoleCommandEvent $event) {
301301
})->descriptions('Display all of the currently secured sites', [
302302
'--expiring' => 'Limits the results to only sites expiring within the next 60 days.',
303303
'--days' => 'To be used with --expiring. Limits the results to only sites expiring within the next X days. Default is set to 60.',
304+
'--ca' => 'Include the Certificate Authority certificate in the list of site certificates.',
304305
]);
305306

306307
/**

0 commit comments

Comments
 (0)