/** * Register user at ACME * * @throws \Kelunik\Acme\AcmeException */ public function register() { try { \amp\wait($this->acme->register($this->email)); } catch (\Exception $e) { throw new \Exception('Error registering ' . $this->email . ': ' . $e->getMessage(), 0, $e); } $this->config('status', 'registered at Let\'s Encrypt'); $this->config('email', $this->email); }
public function doExecute(Manager $args) : Generator { if (posix_geteuid() !== 0) { throw new AcmeException("Please run this script as root!"); } $email = $args->get("email"); (yield resolve($this->checkEmail($email))); $server = $args->get("server"); $protocol = substr($server, 0, strpos("://", $server)); if (!$protocol || $protocol === $server) { $server = "https://" . $server; } elseif ($protocol !== "https") { throw new \InvalidArgumentException("Invalid server protocol, only HTTPS supported"); } $identity = str_replace(["/", "%"], "-", substr($server, 8)); $path = __DIR__ . "/../../data/accounts"; $pathPrivate = "{$path}/{$identity}.private.key"; $pathPublic = "{$path}/{$identity}.public.key"; if ((yield exists($pathPrivate)) && (yield exists($pathPublic))) { $this->logger->info("Loading existing keys ..."); $private = file_get_contents($pathPrivate); $public = file_get_contents($pathPublic); $keyPair = new KeyPair($private, $public); } else { $this->logger->info("Generating key keys ..."); $keyPair = (new OpenSSLKeyGenerator())->generate(4096); if (!file_exists($path) && !mkdir($path, 0700, true)) { throw new AcmeException("Couldn't create account directory"); } file_put_contents($pathPrivate, $keyPair->getPrivate()); file_put_contents($pathPublic, $keyPair->getPublic()); chmod($pathPrivate, 600); chmod($pathPrivate, 600); } $acme = new AcmeService(new AcmeClient($server, $keyPair), $keyPair); $this->logger->info("Registering with ACME server " . substr($server, 8) . " ..."); /** @var Registration $registration */ $registration = (yield $acme->register($email)); $this->logger->notice("Registration successful with contact " . json_encode($registration->getContact())); }
/** * Register user at ACME * * @throws \Kelunik\Acme\AcmeException */ public function register() { $this->acme->register($this->email); $this->config('status', 'registered at Let\'s Encrypt'); $this->config('email', $this->email); }
/** * Register user at ACME * * @throws \Kelunik\Acme\AcmeException */ public function register() { $this->acme->register($this->email); }