Require certificate common name instead of full path on check
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Kelunik\AcmeClient\Commands;
|
namespace Kelunik\AcmeClient\Commands;
|
||||||
|
|
||||||
|
use Kelunik\AcmeClient\Stores\CertificateStore;
|
||||||
use Kelunik\Certificate\Certificate;
|
use Kelunik\Certificate\Certificate;
|
||||||
use League\CLImate\Argument\Manager;
|
use League\CLImate\Argument\Manager;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -22,13 +23,10 @@ class Check implements Command {
|
|||||||
* @return \Generator
|
* @return \Generator
|
||||||
*/
|
*/
|
||||||
private function doExecute(Manager $args) {
|
private function doExecute(Manager $args) {
|
||||||
$path = $args->get("cert");
|
$path = dirname(dirname(__DIR__)) . "/data/certs";
|
||||||
|
$certificateStore = new CertificateStore($path);
|
||||||
|
|
||||||
if (!realpath($path)) {
|
$pem = (yield $certificateStore->get($args->get("name")));
|
||||||
throw new \RuntimeException("Certificate doesn't exist: '{$path}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
$pem = (yield \Amp\File\get($path));
|
|
||||||
$cert = new Certificate($pem);
|
$cert = new Certificate($pem);
|
||||||
|
|
||||||
$this->logger->info("Certificate is valid until " . date("d.m.Y", $cert->getValidTo()));
|
$this->logger->info("Certificate is valid until " . date("d.m.Y", $cert->getValidTo()));
|
||||||
@@ -44,10 +42,9 @@ class Check implements Command {
|
|||||||
|
|
||||||
public static function getDefinition() {
|
public static function getDefinition() {
|
||||||
return [
|
return [
|
||||||
"cert" => [
|
"name" => [
|
||||||
"longPrefix" => "cert",
|
"longPrefix" => "name",
|
||||||
"prefix" => "c",
|
"description" => "Common name of the certificate to check.",
|
||||||
"description" => "Certificate to check.",
|
|
||||||
"required" => true,
|
"required" => true,
|
||||||
],
|
],
|
||||||
"ttl" => [
|
"ttl" => [
|
||||||
|
|||||||
@@ -120,10 +120,6 @@ class Issue implements Command {
|
|||||||
$certificateStore = new CertificateStore($path);
|
$certificateStore = new CertificateStore($path);
|
||||||
yield $certificateStore->put($certificates);
|
yield $certificateStore->put($certificates);
|
||||||
|
|
||||||
yield \Amp\File\put($path . "/" . reset($domains) . "/config.json", json_encode([
|
|
||||||
"domains" => $domains, "path" => $args->get("path"), "user" => $user, "bits" => $bits,
|
|
||||||
], JSON_PRETTY_PRINT) . "\n");
|
|
||||||
|
|
||||||
$this->logger->info("Successfully issued certificate, see {$path}/" . reset($domains));
|
$this->logger->info("Successfully issued certificate, see {$path}/" . reset($domains));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,20 @@ class CertificateStore {
|
|||||||
$this->root = rtrim(str_replace("\\", "/", $root), "/");
|
$this->root = rtrim(str_replace("\\", "/", $root), "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get($name) {
|
||||||
|
return \Amp\resolve($this->doGet($name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doGet($name) {
|
||||||
|
Assert::string($name, "Name must be a string. Got: %s");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return yield \Amp\File\get($this->root . "/" . $name . "/cert.pem");
|
||||||
|
} catch (FilesystemException $e) {
|
||||||
|
throw new CertificateStoreException("Failed to load certificate.", 0, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function put(array $certificates) {
|
public function put(array $certificates) {
|
||||||
return \Amp\resolve($this->doPut($certificates));
|
return \Amp\resolve($this->doPut($certificates));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user