Skip to content

Commit 1a2310e

Browse files
author
laking
committed
Update on certificte CA-signing. Moved config to control panel.
1 parent 1fff4b1 commit 1a2310e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ function onLoad() {
8282
// Handle the creation of SSL certificates
8383
function ssl($event_name,$data) {
8484
global $app, $conf;
85+
86+
// load the server configuration options
87+
$app->uses('getconf');
88+
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
89+
if ($web_config['CA_path']!='' && !file_exists($web_config['CA_path'].'/openssl.cnf'))
90+
$app->log("CA path error, file does not exist:".$web_config['CA_path'].'/openssl.conf',LOGLEVEL_ERROR);
8591

8692
//* Only vhosts can have a ssl cert
8793
if($data["new"]["type"] != "vhost") return;
@@ -142,18 +148,22 @@ function ssl($event_name,$data) {
142148
$crt_file = escapeshellcmd($crt_file);
143149

144150
if(is_file($ssl_cnf_file)) {
145-
151+
146152
exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 2048");
147153
exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file");
148-
if(isset($conf['CA-path']) && isset($conf['CA-pass']) )
154+
exec("openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
155+
156+
if(file_exists($web_config['CA_path'].'/openssl.cnf'))
149157
{
150-
exec("openssl ca -batch -out $crt_file -config ".$conf['CA-path']."/openssl.cnf -passin pass:".$conf['CA-pass']." -in $csr_file");
158+
exec("openssl ca -batch -out $crt_file -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -in $csr_file");
151159
$app->log("Creating CA-signed SSL Cert for: $domain",LOGLEVEL_DEBUG);
152-
} else{
160+
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);
161+
};
162+
if (filesize($crt_file)==0 || !file_exists($crt_file)){
153163
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 ");
154164
$app->log("Creating self-signed SSL Cert for: $domain",LOGLEVEL_DEBUG);
155165
};
156-
exec("openssl rsa -passin pass:$ssl_password -in $key_file -out $key_file2");
166+
157167
}
158168

159169
exec('chmod 400 '.$key_file2);
@@ -193,9 +203,9 @@ function ssl($event_name,$data) {
193203
$csr_file = $ssl_dir.'/'.$domain.'.csr';
194204
$crt_file = $ssl_dir.'/'.$domain.'.crt';
195205
$bundle_file = $ssl_dir.'/'.$domain.'.bundle';
196-
if(isset($conf['CA-path']) && isset($conf['CA-pass']) )
206+
if(file_exists($web_config['CA_path'].'/openssl.cnf'))
197207
{
198-
exec("openssl ca -batch -config ".$conf['CA-path']."/openssl.cnf -passin pass:".$conf['CA-pass']." -revoke $crt_file");
208+
exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke $crt_file");
199209
$app->log("Revoking CA-signed SSL Cert for: $domain",LOGLEVEL_DEBUG);
200210
};
201211
unlink($csr_file);
@@ -620,12 +630,12 @@ function update($event_name,$data) {
620630
$crt_file = $ssl_dir.'/'.$domain.'.crt';
621631
$bundle_file = $ssl_dir.'/'.$domain.'.bundle';
622632

623-
if($data['new']['ssl'] == 'y' && @is_file($crt_file) && @is_file($key_file) && (@filesize($crt_file)>0) && (@filesize($key_file)>0)) {
633+
if($domain!='' && $data['new']['ssl'] == 'y' && @is_file($crt_file) && @is_file($key_file) && (@filesize($crt_file)>0) && (@filesize($key_file)>0)) {
624634
$vhost_data['ssl_enabled'] = 1;
625635
$app->log('Enable SSL for: '.$domain,LOGLEVEL_DEBUG);
626636
} else {
627637
$vhost_data['ssl_enabled'] = 0;
628-
$app->log('Disable SSL for: '.$domain,LOGLEVEL_DEBUG);
638+
$app->log('SSL Disabled. '.$domain,LOGLEVEL_DEBUG);
629639
}
630640

631641
if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1;

0 commit comments

Comments
 (0)