Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4cabf755b | ||
|
|
d78b465739 | ||
|
|
aa8186471c | ||
|
|
888588cf00 | ||
|
|
44f218d8c2 | ||
|
|
af44670353 | ||
|
|
0bd3525938 | ||
|
|
c3f8424785 | ||
|
|
040aebe993 |
@@ -11,12 +11,10 @@ cache:
|
||||
- vendor
|
||||
|
||||
install:
|
||||
- phpenv config-rm xdebug.ini
|
||||
- composer self-update
|
||||
- phpenv config-rm xdebug.ini || true
|
||||
- composer config --global discard-changes true
|
||||
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.5" ]]; then composer require --dev --no-update phpunit/phpunit ^4; fi
|
||||
- composer require satooshi/php-coveralls dev-master --dev --no-update
|
||||
- composer update --ignore-platform-reqs
|
||||
- composer update
|
||||
- composer require satooshi/php-coveralls dev-master --dev
|
||||
- composer show --installed
|
||||
|
||||
script:
|
||||
|
||||
1
bin/acme
1
bin/acme
@@ -135,6 +135,7 @@ try {
|
||||
$injector = new Injector;
|
||||
$injector->share($climate);
|
||||
$injector->share(new AcmeFactory);
|
||||
$injector->share(new Amp\Artax\Client(new Amp\Artax\Cookie\NullCookieJar));
|
||||
|
||||
$command = $injector->make($class);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"symfony/yaml": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5",
|
||||
"phpunit/phpunit": "^4|^5",
|
||||
"friendsofphp/php-cs-fixer": "^1.9",
|
||||
"macfja/phar-builder": "^0.2.5"
|
||||
},
|
||||
|
||||
565
composer.lock
generated
565
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
|
||||
## Installation using Phar
|
||||
|
||||
This is the preferred installation method for usage on a production system.
|
||||
This is the preferred installation method for usage on a production system. You can download `acme-client.phar` in the [release section](https://github.com/kelunik/acme-client/releases).
|
||||
|
||||
### Requirements
|
||||
|
||||
|
||||
22
doc/usage.md
22
doc/usage.md
@@ -77,10 +77,26 @@ the script will be quiet to be cron friendly. If an error occurs, the script wil
|
||||
You should execute `acme-client auto` as a daily cron. It's recommended to setup e-mail notifications for all output of
|
||||
that script.
|
||||
|
||||
```sh
|
||||
0 0 * * * /usr/local/sbin/acme-client auto; RC=$?; if [ $RC = 4 ] || [ $RC = 5 ]; then /usr/sbin/service nginx reload; fi
|
||||
Create a new script, e.g. in `/usr/local/bin/acme-renew`. The `PATH` might need to be modified to suit your system.
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
||||
|
||||
acme-client auto
|
||||
|
||||
RC=$?
|
||||
|
||||
if [ $RC = 4 ] || [ $RC = 5 ]; then
|
||||
service nginx reload
|
||||
fi
|
||||
```
|
||||
|
||||
```sh
|
||||
# Cron Job Configuration
|
||||
0 0 * * * /usr/local/bin/acme-renew
|
||||
```
|
||||
The path to `acme-client` should be modified to suit your system. The full path should be used as the system path may not be set up in your cron environment.
|
||||
|
||||
| Exit Code | Description |
|
||||
|-----------|-------------|
|
||||
|
||||
@@ -89,6 +89,14 @@ class Auto implements Command {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($config["challenge-concurrency"]) && !is_numeric($config["challenge-concurrency"])) {
|
||||
$this->climate->error("Config file ({$configPath}) defines an invalid 'challenge-concurrency' value.");
|
||||
yield new CoroutineResult(self::EXIT_CONFIG_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
$concurrency = isset($config["challenge-concurrency"]) ? (int) $config["challenge-concurrency"] : null;
|
||||
|
||||
$command = implode(" ", array_map("escapeshellarg", [
|
||||
PHP_BINARY,
|
||||
$GLOBALS["argv"][0],
|
||||
@@ -113,22 +121,16 @@ class Auto implements Command {
|
||||
return;
|
||||
}
|
||||
|
||||
$certificateChunks = array_chunk($config["certificates"], 10, true);
|
||||
|
||||
$errors = [];
|
||||
$values = [];
|
||||
|
||||
foreach ($certificateChunks as $certificateChunk) {
|
||||
$promises = [];
|
||||
|
||||
foreach ($certificateChunk as $certificate) {
|
||||
$promises[] = \Amp\resolve($this->checkAndIssue($certificate, $config["server"], $config["storage"]));
|
||||
foreach ($config["certificates"] as $i => $certificate) {
|
||||
try {
|
||||
$result = (yield \Amp\resolve($this->checkAndIssue($certificate, $config["server"], $config["storage"], $concurrency)));
|
||||
$values[$i] = $result;
|
||||
} catch (\Exception $e) {
|
||||
$errors[$i] = $e;
|
||||
}
|
||||
|
||||
list($chunkErrors, $chunkValues) = (yield \Amp\any($promises));
|
||||
|
||||
$errors += $chunkErrors;
|
||||
$values += $chunkValues;
|
||||
}
|
||||
|
||||
$status = [
|
||||
@@ -171,10 +173,11 @@ class Auto implements Command {
|
||||
* @param array $certificate certificate configuration
|
||||
* @param string $server server to use for issuance
|
||||
* @param string $storage storage directory
|
||||
* @param int|null $concurrency concurrent challenges
|
||||
* @return \Generator
|
||||
* @throws AcmeException if something does wrong
|
||||
*/
|
||||
private function checkAndIssue(array $certificate, $server, $storage) {
|
||||
private function checkAndIssue(array $certificate, $server, $storage, $concurrency = null) {
|
||||
$domainPathMap = $this->toDomainPathMap($certificate["paths"]);
|
||||
$domains = array_keys($domainPathMap);
|
||||
$commonName = reset($domains);
|
||||
@@ -230,6 +233,11 @@ class Auto implements Command {
|
||||
$args[] = $certificate["bits"];
|
||||
}
|
||||
|
||||
if ($concurrency) {
|
||||
$args[] = "--challenge-concurrency";
|
||||
$args[] = $concurrency;
|
||||
}
|
||||
|
||||
$command = implode(" ", array_map("escapeshellarg", $args));
|
||||
|
||||
$process = new Process($command);
|
||||
|
||||
@@ -82,7 +82,9 @@ class Issue implements Command {
|
||||
$acme = $this->acmeFactory->build($server, $keyPair);
|
||||
$errors = [];
|
||||
|
||||
$domainChunks = array_chunk($domains, 10, true);
|
||||
$concurrency = $args->get("challenge-concurrency");
|
||||
|
||||
$domainChunks = array_chunk($domains, \min(20, \max($concurrency, 1)), true);
|
||||
|
||||
foreach ($domainChunks as $domainChunk) {
|
||||
$promises = [];
|
||||
@@ -194,7 +196,13 @@ class Issue implements Command {
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
throw new AcmeException("Couldn't resolve the following domains to an IPv4 nor IPv6 record: " . implode(", ", array_keys($errors)));
|
||||
$failedDomains = implode(", ", array_keys($errors));
|
||||
$reasons = implode("\n\n", array_map(function ($exception) {
|
||||
/** @var \Exception|\Throwable $exception */
|
||||
return get_class($exception) . ": " . $exception->getMessage();
|
||||
}, $errors));
|
||||
|
||||
throw new AcmeException("Couldn't resolve the following domains to an IPv4 nor IPv6 record: {$failedDomains}\n\n{$reasons}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +253,12 @@ class Issue implements Command {
|
||||
"defaultValue" => 2048,
|
||||
"castTo" => "int",
|
||||
],
|
||||
"challenge-concurrency" => [
|
||||
"longPrefix" => "challenge-concurrency",
|
||||
"description" => "Number of challenges to be solved concurrently.",
|
||||
"defaultValue" => 10,
|
||||
"castTo" => "int",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Kelunik\AcmeClient\Commands;
|
||||
|
||||
use Amp\CoroutineResult;
|
||||
use Amp\Dns\NoRecordException;
|
||||
use Amp\Dns\Record;
|
||||
use Amp\Dns\ResolutionException;
|
||||
use InvalidArgumentException;
|
||||
@@ -80,8 +81,10 @@ class Setup implements Command {
|
||||
|
||||
try {
|
||||
yield \Amp\Dns\query($host, Record::MX);
|
||||
} catch (ResolutionException $e) {
|
||||
} catch (NoRecordException $e) {
|
||||
throw new AcmeException("No MX record defined for '{$host}'");
|
||||
} catch (ResolutionException $e) {
|
||||
throw new AcmeException("Dns query for an MX record on '{$host}' failed for the following reason: " . $e->getMessage(), null, $e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user