Skip to content

Commit 8c82ef8

Browse files
committed
- Fixed: creation of wildcard certificates wasn't working.
1 parent c505a8e commit 8c82ef8

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,34 @@ function ssl($event_name, $data) {
171171

172172
$rand_file = escapeshellcmd($rand_file);
173173
$key_file = escapeshellcmd($key_file);
174+
$openssl_cmd_key_file = $key_file;
174175
if(substr($domain, 0, 2) == '*.' && strpos($key_file, '/ssl/\*.') !== false) $key_file = str_replace('/ssl/\*.', '/ssl/*.', $key_file); // wildcard certificate
175176
$key_file2 = escapeshellcmd($key_file2);
177+
$openssl_cmd_key_file2 = $key_file2;
176178
if(substr($domain, 0, 2) == '*.' && strpos($key_file2, '/ssl/\*.') !== false) $key_file2 = str_replace('/ssl/\*.', '/ssl/*.', $key_file2); // wildcard certificate
177179
$ssl_days = 3650;
178180
$csr_file = escapeshellcmd($csr_file);
181+
$openssl_cmd_csr_file = $csr_file;
179182
if(substr($domain, 0, 2) == '*.' && strpos($csr_file, '/ssl/\*.') !== false) $csr_file = str_replace('/ssl/\*.', '/ssl/*.', $csr_file); // wildcard certificate
180183
$config_file = escapeshellcmd($ssl_cnf_file);
181184
$crt_file = escapeshellcmd($crt_file);
185+
$openssl_cmd_crt_file = $crt_file;
182186
if(substr($domain, 0, 2) == '*.' && strpos($crt_file, '/ssl/\*.') !== false) $crt_file = str_replace('/ssl/\*.', '/ssl/*.', $crt_file); // wildcard certificate
183187

184188
if(is_file($ssl_cnf_file) && !is_link($ssl_cnf_file)) {
185189

186-
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 2048");
187-
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file");
188-
exec("openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
190+
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $openssl_cmd_key_file 2048");
191+
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $openssl_cmd_key_file -out $openssl_cmd_csr_file -days $ssl_days -config $config_file");
192+
exec("openssl rsa -passin pass:$ssl_password -in $openssl_cmd_key_file -out $openssl_cmd_key_file2");
189193

190194
if(file_exists($web_config['CA_path'].'/openssl.cnf'))
191195
{
192-
exec("openssl ca -batch -out $crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $csr_file");
196+
exec("openssl ca -batch -out $openssl_cmd_crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $openssl_cmd_csr_file");
193197
$app->log("Creating CA-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
194-
if (filesize($crt_file)==0 || !file_exists($crt_file)) $app->log("CA-Certificate signing failed. openssl ca -out $crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $csr_file", LOGLEVEL_ERROR);
198+
if (filesize($crt_file)==0 || !file_exists($crt_file)) $app->log("CA-Certificate signing failed. openssl ca -out $openssl_cmd_crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $openssl_cmd_csr_file", LOGLEVEL_ERROR);
195199
};
196200
if (@filesize($crt_file)==0 || !file_exists($crt_file)){
197-
exec("openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -in $csr_file -out $crt_file -days $ssl_days -config $config_file ");
201+
exec("openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $openssl_cmd_key_file -in $openssl_cmd_csr_file -out $openssl_cmd_crt_file -days $ssl_days -config $config_file ");
198202
$app->log("Creating self-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
199203
};
200204

@@ -273,7 +277,7 @@ function ssl($event_name, $data) {
273277
$bundle_file = $ssl_dir.'/'.$domain.'.bundle';
274278
if(file_exists($web_config['CA_path'].'/openssl.cnf') && !is_link($web_config['CA_path'].'/openssl.cnf'))
275279
{
276-
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke $crt_file");
280+
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke ".escapeshellcmd($crt_file));
277281
$app->log("Revoking CA-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
278282
};
279283
$app->system->unlink($csr_file);

server/plugins-available/nginx_plugin.inc.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,34 @@ function ssl($event_name, $data) {
170170

171171
$rand_file = escapeshellcmd($rand_file);
172172
$key_file = escapeshellcmd($key_file);
173+
$openssl_cmd_key_file = $key_file;
173174
if(substr($domain, 0, 2) == '*.' && strpos($key_file, '/ssl/\*.') !== false) $key_file = str_replace('/ssl/\*.', '/ssl/*.', $key_file); // wildcard certificate
174175
$key_file2 = escapeshellcmd($key_file2);
176+
$openssl_cmd_key_file2 = $key_file2;
175177
if(substr($domain, 0, 2) == '*.' && strpos($key_file2, '/ssl/\*.') !== false) $key_file2 = str_replace('/ssl/\*.', '/ssl/*.', $key_file2); // wildcard certificate
176178
$ssl_days = 3650;
177179
$csr_file = escapeshellcmd($csr_file);
180+
$openssl_cmd_csr_file = $csr_file;
178181
if(substr($domain, 0, 2) == '*.' && strpos($csr_file, '/ssl/\*.') !== false) $csr_file = str_replace('/ssl/\*.', '/ssl/*.', $csr_file); // wildcard certificate
179182
$config_file = escapeshellcmd($ssl_cnf_file);
180183
$crt_file = escapeshellcmd($crt_file);
184+
$openssl_cmd_crt_file = $crt_file;
181185
if(substr($domain, 0, 2) == '*.' && strpos($crt_file, '/ssl/\*.') !== false) $crt_file = str_replace('/ssl/\*.', '/ssl/*.', $crt_file); // wildcard certificate
182186

183187
if(is_file($ssl_cnf_file) && !is_link($ssl_cnf_file)) {
184188

185-
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 2048");
186-
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file");
187-
exec("openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
189+
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $openssl_cmd_key_file 2048");
190+
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $openssl_cmd_key_file -out $openssl_cmd_csr_file -days $ssl_days -config $config_file");
191+
exec("openssl rsa -passin pass:$ssl_password -in $openssl_cmd_key_file -out $openssl_cmd_key_file2");
188192

189193
if(file_exists($web_config['CA_path'].'/openssl.cnf'))
190194
{
191-
exec("openssl ca -batch -out $crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $csr_file");
195+
exec("openssl ca -batch -out $openssl_cmd_crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $openssl_cmd_csr_file");
192196
$app->log("Creating CA-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
193-
if (filesize($crt_file)==0 || !file_exists($crt_file)) $app->log("CA-Certificate signing failed. openssl ca -out $crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $csr_file", LOGLEVEL_ERROR);
197+
if (filesize($crt_file)==0 || !file_exists($crt_file)) $app->log("CA-Certificate signing failed. openssl ca -out $openssl_cmd_crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $openssl_cmd_csr_file", LOGLEVEL_ERROR);
194198
};
195199
if (@filesize($crt_file)==0 || !file_exists($crt_file)){
196-
exec("openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -in $csr_file -out $crt_file -days $ssl_days -config $config_file ");
200+
exec("openssl req -x509 -passin pass:$ssl_password -passout pass:$ssl_password -key $openssl_cmd_key_file -in $openssl_cmd_csr_file -out $openssl_cmd_crt_file -days $ssl_days -config $config_file ");
197201
$app->log("Creating self-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
198202
};
199203

@@ -274,7 +278,7 @@ function ssl($event_name, $data) {
274278
//$bundle_file = $ssl_dir.'/'.$domain.'.bundle';
275279
if(file_exists($web_config['CA_path'].'/openssl.cnf') && !is_link($web_config['CA_path'].'/openssl.cnf'))
276280
{
277-
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke $crt_file");
281+
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke ".escapeshellcmd($crt_file));
278282
$app->log("Revoking CA-signed SSL Cert for: $domain", LOGLEVEL_DEBUG);
279283
};
280284
$app->system->unlink($csr_file);

0 commit comments

Comments
 (0)