Skip to content

Commit 1107171

Browse files
author
Marius Burkard
committed
Merge branch '6015_letsencrypt_token_permissions' into 'develop'
acme.sh and missing letsencrypt client fixes Closes #6015 See merge request ispconfig/ispconfig3!1396
2 parents c0db019 + 76647e8 commit 1107171

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

install/lib/installer_base.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,9 @@ public function make_ispconfig_ssl_cert() {
29772977

29782978
swriteln('acme.sh is installed, overriding certificate path to use ' . $acme_cert_dir);
29792979

2980+
# acme.sh does not set umask, resulting in incorrect permissions (ispconfig issue #6015)
2981+
$old_umask = umask(0022);
2982+
29802983
$out = null;
29812984
$ret = null;
29822985
if($conf['nginx']['installed'] == true || $conf['apache']['installed'] == true) {
@@ -2998,6 +3001,7 @@ public function make_ispconfig_ssl_cert() {
29983001
$acme_chain = "--fullchain-file " . escapeshellarg($ssl_crt_file);
29993002
exec("$acme --install-cert -d " . escapeshellarg($hostname) . " $acme_key $acme_chain");
30003003
$issued_successfully = true;
3004+
umask($old_umask);
30013005

30023006
// Make temporary backup of self-signed certs permanent
30033007
if(file_exists($ssl_crt_file.'-temporary.bak') || is_link($ssl_crt_file.'-temporary.bak'))
@@ -3010,6 +3014,8 @@ public function make_ispconfig_ssl_cert() {
30103014
} else {
30113015
swriteln('Issuing certificate via acme.sh failed. Please check that your hostname can be verified by letsencrypt');
30123016

3017+
umask($old_umask);
3018+
30133019
// Restore temporary backup of self-signed certs
30143020
if(file_exists($ssl_crt_file.'-temporary.bak') || is_link($ssl_crt_file.'-temporary.bak'))
30153021
rename($ssl_crt_file.'-temporary.bak', $ssl_crt_file);

server/lib/classes/letsencrypt.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,15 @@ public function request_certificates($data, $server_type = 'apache') {
317317
if($this->get_acme_script()) {
318318
$use_acme = true;
319319
} elseif(!$this->get_certbot_script()) {
320+
$app->log("Unable to find Let's Encrypt client, installing acme.sh.", LOGLEVEL_DEBUG);
320321
// acme and le missing
321322
$this->install_acme();
323+
if($this->get_acme_script()) {
324+
$use_acme = true;
325+
} else {
326+
$app->log("Unable to install acme.sh. Cannot proceed, no Let's Encrypt client found.", LOGLEVEL_WARN);
327+
return false;
328+
}
322329
}
323330

324331
$tmp = $app->letsencrypt->get_website_certificate_paths($data);
@@ -399,11 +406,13 @@ public function request_certificates($data, $server_type = 'apache') {
399406
$this->certbot_use_certcommand = false;
400407
$letsencrypt_cmd = '';
401408
$allow_return_codes = null;
409+
$old_umask = umask(0022); # work around acme.sh permission bug, see #6015
402410
if($use_acme) {
403411
$letsencrypt_cmd = $this->get_acme_command($temp_domains, $key_file, $bundle_file, $crt_file, $server_type);
404412
$allow_return_codes = array(2);
405413
} else {
406414
$letsencrypt_cmd = $this->get_certbot_command($temp_domains);
415+
umask($old_umask);
407416
}
408417

409418
$success = false;
@@ -420,6 +429,7 @@ public function request_certificates($data, $server_type = 'apache') {
420429
}
421430

422431
if($use_acme === true) {
432+
umask($old_umask);
423433
if(!$success) {
424434
$app->log('Let\'s Encrypt SSL Cert for: ' . $domain . ' could not be issued.', LOGLEVEL_WARN);
425435
$app->log($letsencrypt_cmd, LOGLEVEL_WARN);

0 commit comments

Comments
 (0)