11 Commits

Author SHA1 Message Date
Niklas Keller
d4f2009315 Fix build on nightly 2018-01-11 17:18:29 +01:00
Niklas Keller
2b4a200263 Fix CSR generation 2018-01-11 17:15:04 +01:00
Niklas Keller
256aa76011 Fix directory permissions 2018-01-11 17:11:28 +01:00
Niklas Keller
69bc88daf1 Refactor directory creation 2018-01-11 17:00:27 +01:00
Niklas Keller
19f6550e33 Fix key store path in exception message 2018-01-11 16:53:01 +01:00
Niklas Keller
ed3da3c98d Fix DNS lookups 2018-01-11 16:43:32 +01:00
Niklas Keller
56955155fe Work around https://bugs.php.net/bug.php?id=75396 2018-01-11 10:36:45 +01:00
Niklas Keller
e3d7723da3 Fix bugs in stores not yielding the correct things 2018-01-11 10:32:17 +01:00
Niklas Keller
0ae207fce3 Downgrade dependencies to be compatible with PHP 7.0 2018-01-09 19:30:34 +01:00
Niklas Keller
bb7e25704c Work around issue with amphp/parallel and PHARs 2018-01-08 18:44:33 +01:00
Niklas Keller
246a02b5cf Update dependencies 2018-01-08 18:43:52 +01:00
8 changed files with 169 additions and 133 deletions

View File

@@ -20,7 +20,7 @@ install:
script:
- find -name "*.php" -not -path "./vendor/*" -print0 | xargs -n 1 -0 php -l
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
- php vendor/bin/php-cs-fixer --diff --dry-run -v fix
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
after_script:
- php vendor/bin/coveralls -v

View File

@@ -1,10 +1,12 @@
#!/usr/bin/env php
<?php
use Amp\File\BlockingDriver;
use Amp\Loop;
use Auryn\Injector;
use Kelunik\AcmeClient\AcmeFactory;
use League\CLImate\CLImate;
use function Amp\File\filesystem;
$logo = <<<LOGO
____ __________ ___ ___
@@ -105,6 +107,9 @@ if (!array_key_exists($argv[1], $commands)) {
exit(1);
}
// Use blocking driver for now, as amphp/parallel doesn't work inside PHARs
filesystem(new BlockingDriver);
/** @var \Kelunik\AcmeClient\Commands\Command $class */
$class = "Kelunik\\AcmeClient\\Commands\\" . ucfirst($argv[1]);
$definition = $class::getDefinition();
@@ -139,8 +144,9 @@ $injector->share(new AcmeFactory);
$injector->share(new Amp\Artax\DefaultClient);
$command = $injector->make($class);
$exitCode = 1;
Loop::run(function () use ($command, $climate) {
Loop::run(function () use ($command, $climate, &$exitCode) {
$handler = function ($e) use ($climate) {
$error = (string) $e;
$lines = explode("\n", $error);
@@ -159,13 +165,13 @@ Loop::run(function () use ($command, $climate) {
$exitCode = yield $command->execute($climate->arguments);
if ($exitCode === null) {
exit(0);
$exitCode = 0;
}
exit($exitCode);
} catch (Throwable $e) {
$handler($e);
}
Loop::stop();
});
exit($exitCode);

View File

@@ -41,18 +41,27 @@
"src/functions.php"
]
},
"config": {
"platform": {
"php": "7.0.0"
}
},
"extra": {
"phar-builder": {
"compression": "GZip",
"name": "acme-client.phar",
"output-dir": "build",
"include": ["info", "src", "vendor/kelunik/acme/res", "vendor/amphp/socket/var"],
"include": ["info", "src", "vendor/kelunik/acme/res"],
"include-dev": false,
"skip-shebang": false,
"entry-point": "bin/acme",
"events": {
"command.package.start": [
"mkdir -p info",
"git describe --tags > info/build.version",
"php -r 'echo time();' > info/build.time"
"php -r 'echo time();' > info/build.time",
"rm -rf vendor/amphp/file/travis",
"rm -rf vendor/amphp/parallel/travis"
],
"command.package.end": [
"rm -rf info",

214
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "453e56fe6bb9de302a96b94f70baa09a",
"content-hash": "4332d77ce602e20b8ab72bdce75be8f8",
"packages": [
{
"name": "amphp/amp",
@@ -1283,26 +1283,23 @@
},
{
"name": "symfony/yaml",
"version": "v3.4.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "afe0cd38486505c9703707707d91450cfc1bd536"
"reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/afe0cd38486505c9703707707d91450cfc1bd536",
"reference": "afe0cd38486505c9703707707d91450cfc1bd536",
"url": "https://api.github.com/repos/symfony/yaml/zipball/ddc23324e6cfe066f3dd34a37ff494fa80b617ed",
"reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"conflict": {
"symfony/console": "<3.4"
"php": ">=5.5.9"
},
"require-dev": {
"symfony/console": "~3.4|~4.0"
"symfony/console": "~2.8|~3.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
@@ -1310,7 +1307,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -1337,7 +1334,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-12-11T20:38:23+00:00"
"time": "2017-07-23T12:43:26+00:00"
},
{
"name": "webmozart/assert",
@@ -1455,30 +1452,30 @@
},
{
"name": "doctrine/annotations",
"version": "v1.6.0",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/annotations.git",
"reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5"
"reference": "54cacc9b81758b14e3ce750f205a393d52339e97"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5",
"reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5",
"url": "https://api.github.com/repos/doctrine/annotations/zipball/54cacc9b81758b14e3ce750f205a393d52339e97",
"reference": "54cacc9b81758b14e3ce750f205a393d52339e97",
"shasum": ""
},
"require": {
"doctrine/lexer": "1.*",
"php": "^7.1"
"php": "^5.6 || ^7.0"
},
"require-dev": {
"doctrine/cache": "1.*",
"phpunit/phpunit": "^6.4"
"phpunit/phpunit": "^5.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6.x-dev"
"dev-master": "1.4.x-dev"
}
},
"autoload": {
@@ -1519,36 +1516,36 @@
"docblock",
"parser"
],
"time": "2017-12-06T07:11:42+00:00"
"time": "2017-02-24T16:22:25+00:00"
},
{
"name": "doctrine/instantiator",
"version": "1.1.0",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda"
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
"php": "^7.1"
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "^6.2.3",
"squizlabs/php_codesniffer": "^3.0.2"
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.0.x-dev"
}
},
"autoload": {
@@ -1573,7 +1570,7 @@
"constructor",
"instantiate"
],
"time": "2017-07-22T11:58:36+00:00"
"time": "2015-06-14T21:17:01+00:00"
},
{
"name": "doctrine/lexer",
@@ -2755,16 +2752,16 @@
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "5.0.5",
"version": "5.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "283b9f4f670e3a6fd6c4ff95c51a952eb5c75933"
"reference": "33fd41a76e746b8fa96d00b49a23dadfa8334cdf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/283b9f4f670e3a6fd6c4ff95c51a952eb5c75933",
"reference": "283b9f4f670e3a6fd6c4ff95c51a952eb5c75933",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/33fd41a76e746b8fa96d00b49a23dadfa8334cdf",
"reference": "33fd41a76e746b8fa96d00b49a23dadfa8334cdf",
"shasum": ""
},
"require": {
@@ -2810,7 +2807,7 @@
"mock",
"xunit"
],
"time": "2017-12-10T08:01:53+00:00"
"time": "2018-01-06T05:45:45+00:00"
},
{
"name": "psr/log",
@@ -3465,45 +3462,45 @@
},
{
"name": "symfony/console",
"version": "v3.4.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "9f21adfb92a9315b73ae2ed43138988ee4913d4e"
"reference": "b0878233cb5c4391347e5495089c7af11b8e6201"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/9f21adfb92a9315b73ae2ed43138988ee4913d4e",
"reference": "9f21adfb92a9315b73ae2ed43138988ee4913d4e",
"url": "https://api.github.com/repos/symfony/console/zipball/b0878233cb5c4391347e5495089c7af11b8e6201",
"reference": "b0878233cb5c4391347e5495089c7af11b8e6201",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/debug": "~2.8|~3.0|~4.0",
"php": ">=5.5.9",
"symfony/debug": "~2.8|~3.0",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/dependency-injection": "<3.4",
"symfony/process": "<3.3"
"symfony/dependency-injection": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.3|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/lock": "~3.4|~4.0",
"symfony/process": "~3.3|~4.0"
"symfony/config": "~3.3",
"symfony/dependency-injection": "~3.3",
"symfony/event-dispatcher": "~2.8|~3.0",
"symfony/filesystem": "~2.8|~3.0",
"symfony/http-kernel": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0"
},
"suggest": {
"psr/log": "For using the console logger",
"symfony/event-dispatcher": "",
"symfony/lock": "",
"symfony/filesystem": "",
"symfony/process": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3530,36 +3527,36 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2017-12-14T19:40:10+00:00"
"time": "2017-07-29T21:27:59+00:00"
},
{
"name": "symfony/debug",
"version": "v4.0.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "8c3e709209ce3b952a31c0f4a31ac7703c3d0226"
"reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/8c3e709209ce3b952a31c0f4a31ac7703c3d0226",
"reference": "8c3e709209ce3b952a31c0f4a31ac7703c3d0226",
"url": "https://api.github.com/repos/symfony/debug/zipball/7c13ae8ce1e2adbbd574fc39de7be498e1284e13",
"reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"php": ">=5.5.9",
"psr/log": "~1.0"
},
"conflict": {
"symfony/http-kernel": "<3.4"
"symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
},
"require-dev": {
"symfony/http-kernel": "~3.4|~4.0"
"symfony/http-kernel": "~2.8|~3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3586,34 +3583,34 @@
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2017-12-12T08:41:51+00:00"
"time": "2017-07-28T15:27:31+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v4.0.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "d4face19ed8002eec8280bc1c5ec18130472bf43"
"reference": "67535f1e3fd662bdc68d7ba317c93eecd973617e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d4face19ed8002eec8280bc1c5ec18130472bf43",
"reference": "d4face19ed8002eec8280bc1c5ec18130472bf43",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/67535f1e3fd662bdc68d7ba317c93eecd973617e",
"reference": "67535f1e3fd662bdc68d7ba317c93eecd973617e",
"shasum": ""
},
"require": {
"php": "^7.1.3"
"php": ">=5.5.9"
},
"conflict": {
"symfony/dependency-injection": "<3.4"
"symfony/dependency-injection": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/expression-language": "~3.4|~4.0",
"symfony/stopwatch": "~3.4|~4.0"
"symfony/config": "~2.8|~3.0",
"symfony/dependency-injection": "~3.3",
"symfony/expression-language": "~2.8|~3.0",
"symfony/stopwatch": "~2.8|~3.0"
},
"suggest": {
"symfony/dependency-injection": "",
@@ -3622,7 +3619,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3649,29 +3646,29 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-12-14T19:48:22+00:00"
"time": "2017-06-09T14:53:08+00:00"
},
{
"name": "symfony/filesystem",
"version": "v4.0.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "8c2868641d0c4885eee9c12a89c2b695eb1985cd"
"reference": "427987eb4eed764c3b6e38d52a0f87989e010676"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/8c2868641d0c4885eee9c12a89c2b695eb1985cd",
"reference": "8c2868641d0c4885eee9c12a89c2b695eb1985cd",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/427987eb4eed764c3b6e38d52a0f87989e010676",
"reference": "427987eb4eed764c3b6e38d52a0f87989e010676",
"shasum": ""
},
"require": {
"php": "^7.1.3"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3698,29 +3695,29 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2017-12-14T19:48:22+00:00"
"time": "2017-07-11T07:17:58+00:00"
},
{
"name": "symfony/finder",
"version": "v3.4.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "dac8d7db537bac7ad8143eb11360a8c2231f251a"
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/dac8d7db537bac7ad8143eb11360a8c2231f251a",
"reference": "dac8d7db537bac7ad8143eb11360a8c2231f251a",
"url": "https://api.github.com/repos/symfony/finder/zipball/baea7f66d30854ad32988c11a09d7ffd485810c4",
"reference": "baea7f66d30854ad32988c11a09d7ffd485810c4",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3747,29 +3744,29 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2017-11-05T16:10:10+00:00"
"time": "2017-06-01T21:01:25+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v4.0.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "75fdda335eb0adbd464089e8a0184c61097808e0"
"reference": "ff48982d295bcac1fd861f934f041ebc73ae40f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/75fdda335eb0adbd464089e8a0184c61097808e0",
"reference": "75fdda335eb0adbd464089e8a0184c61097808e0",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/ff48982d295bcac1fd861f934f041ebc73ae40f0",
"reference": "ff48982d295bcac1fd861f934f041ebc73ae40f0",
"shasum": ""
},
"require": {
"php": "^7.1.3"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -3801,7 +3798,7 @@
"configuration",
"options"
],
"time": "2017-12-14T19:48:22+00:00"
"time": "2017-04-12T14:14:56+00:00"
},
{
"name": "symfony/polyfill-mbstring",
@@ -3978,25 +3975,25 @@
},
{
"name": "symfony/process",
"version": "v3.4.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "bb3ef65d493a6d57297cad6c560ee04e2a8f5098"
"reference": "07432804942b9f6dd7b7377faf9920af5f95d70a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/bb3ef65d493a6d57297cad6c560ee04e2a8f5098",
"reference": "bb3ef65d493a6d57297cad6c560ee04e2a8f5098",
"url": "https://api.github.com/repos/symfony/process/zipball/07432804942b9f6dd7b7377faf9920af5f95d70a",
"reference": "07432804942b9f6dd7b7377faf9920af5f95d70a",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4023,29 +4020,29 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2017-12-14T19:40:10+00:00"
"time": "2017-07-13T13:05:09+00:00"
},
{
"name": "symfony/stopwatch",
"version": "v4.0.2",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "ac0e49150555c703fef6b696d8eaba1db7a3ca03"
"reference": "602a15299dc01556013b07167d4f5d3a60e90d15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/ac0e49150555c703fef6b696d8eaba1db7a3ca03",
"reference": "ac0e49150555c703fef6b696d8eaba1db7a3ca03",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/602a15299dc01556013b07167d4f5d3a60e90d15",
"reference": "602a15299dc01556013b07167d4f5d3a60e90d15",
"shasum": ""
},
"require": {
"php": "^7.1.3"
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "3.3-dev"
}
},
"autoload": {
@@ -4072,7 +4069,7 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2017-11-09T12:45:29+00:00"
"time": "2017-04-12T14:14:56+00:00"
},
{
"name": "theseer/tokenizer",
@@ -4167,5 +4164,8 @@
"php": ">=7",
"ext-openssl": "*"
},
"platform-dev": []
"platform-dev": [],
"platform-overrides": {
"php": "7.0.0"
}
}

View File

@@ -2,6 +2,7 @@
namespace Kelunik\AcmeClient\Commands;
use Amp\Dns;
use Amp\Promise;
use Kelunik\Acme\AcmeException;
use Kelunik\Acme\AcmeService;
@@ -109,7 +110,7 @@ class Issue implements Command {
$this->climate->br();
$this->climate->whisper(' Requesting certificate ...');
$csr = (new OpensslCsrGenerator)->generateCsr($key, $domains);
$csr = yield (new OpensslCsrGenerator)->generateCsr($key, $domains);
$location = yield $acme->requestCertificate($csr);
$certificates = yield $acme->pollForCertificate($location);
@@ -161,7 +162,10 @@ class Issue implements Command {
}
private function checkDnsRecords(array $domains): \Generator {
$promises = AcmeClient\concurrentMap(10, \array_combine($domains, $domains), 'Amp\Dns\resolve');
$promises = AcmeClient\concurrentMap(10, $domains, function (string $domain): Promise {
return Dns\resolve($domain);
});
list($errors) = yield Promise\any($promises);
if ($errors) {

View File

@@ -47,8 +47,12 @@ class CertificateStore {
$chain = \array_slice($certificates, 1);
$path = $this->root . '/' . $commonName;
if (!yield File\isdir($path) && !yield File\mkdir($path, 0644, true) && !yield File\isdir($path)) {
throw new FilesystemException("Couldn't create certificate directory: '{$path}'");
if (!yield File\isdir($path)) {
yield File\mkdir($path, 0755, true);
if (!yield File\isdir($path)) {
throw new FilesystemException("Couldn't create certificate directory: '{$path}'");
}
}
yield File\put($path . '/cert.pem', $certificates[0]);

View File

@@ -22,8 +22,12 @@ class ChallengeStore {
throw new ChallengeStoreException("Document root doesn't exist: '{$this->docroot}'");
}
if (!yield File\isdir($path) && !yield File\mkdir($path, 0644, true) && !yield File\isdir($path)) {
throw new ChallengeStoreException("Couldn't create key directory: '{$path}'");
if (!yield File\isdir($path)) {
yield File\mkdir($path, 0755, true);
if (!yield File\isdir($path)) {
throw new ChallengeStoreException("Couldn't create key directory: '{$path}'");
}
}
if ($user && !$userInfo = \posix_getpwnam($user)) {
@@ -35,13 +39,13 @@ class ChallengeStore {
yield File\chown($this->docroot . '/.well-known/acme-challenge', $userInfo['uid'], -1);
}
yield \Amp\File\put("{$path}/{$token}", $payload);
yield File\put("{$path}/{$token}", $payload);
if ($userInfo !== null) {
yield \Amp\File\chown("{$path}/{$token}", $userInfo['uid'], -1);
yield File\chown("{$path}/{$token}", $userInfo['uid'], -1);
}
yield \Amp\File\chmod("{$path}/{$token}", 0644);
yield File\chmod("{$path}/{$token}", 0644);
});
}
@@ -50,7 +54,7 @@ class ChallengeStore {
$path = $this->docroot . "/.well-known/acme-challenge/{$token}";
if (yield File\exists($path)) {
yield \Amp\File\unlink($path);
yield File\unlink($path);
}
});
}

View File

@@ -18,16 +18,21 @@ class KeyStore {
public function get(string $path): Promise {
return call(function () use ($path) {
$file = $this->root . '/' . $path;
$privateKey = yield File\get($file);
// Check key here to be valid, PrivateKey doesn't do that, we fail early here
$res = \openssl_pkey_get_private($privateKey);
try {
$privateKey = yield File\get($file);
if ($res === false) {
throw new KeyStoreException("Invalid private key: '{$file}'");
// Check key here to be valid, PrivateKey doesn't do that, we fail early here
$res = \openssl_pkey_get_private($privateKey);
if ($res === false) {
throw new KeyStoreException("Invalid private key: '{$file}'");
}
return new PrivateKey($privateKey);
} catch (FilesystemException $e) {
throw new KeyStoreException("Key not found: '{$file}'");
}
return new PrivateKey($privateKey);
});
}
@@ -38,8 +43,12 @@ class KeyStore {
try {
$dir = \dirname($file);
if (!yield File\isdir($dir) && !yield File\mkdir($dir, 0644, true) && !yield File\isdir($dir)) {
throw new FilesystemException("Couldn't create key directory: '{$path}'");
if (!yield File\isdir($dir)) {
yield File\mkdir($dir, 0755, true);
if (!yield File\isdir($dir)) {
throw new FilesystemException("Couldn't create key directory: '{$dir}'");
}
}
yield File\put($file, $key->toPem());