. * * Version 0.1 * Author: Daniel Larraz */ function exists_certificates ($paths) /* ------------------------------------------------------------------------ */ { exec ("sudo ls ".$paths['cacert'], $ca_cmd); exec ("sudo ls ".$paths['server_cert'], $sc_cmd); exec ("sudo ls ".$paths['server_key'], $sk_cmd); return $ca_cmd[0] == $paths['cacert'] && $sc_cmd[0] == $paths['server_cert'] && $sk_cmd[0] == $paths['server_key']; } /* ------------------------------------------------------------------------ */ function are_cert_and_key_valid($paths, $key_pass='') /* ------------------------------------------------------------------------ */ { $are_valid = false; $ca_path = $paths['cacert']; $cert_path = $paths['server_cert']; $key_path = $paths['server_key']; exec ("sudo /etc/ssl/sh/mod_crt.sh $cert_path", $cert); if ($cert[0] == 'VALID_FILE') { // It's OK although it does not need key_pass if ($key_pass == '') { exec ("sudo awk '/private_key_password/ {print $3}' ".$paths['fr_eap'], $awk); $key_pass = $awk[0]; } exec ("sudo /etc/ssl/sh/mod_key.sh $key_path $key_pass", $key); if ($key[0] == 'VALID_FILE') { if ($cert[1] == $key[1]) { exec ("sudo openssl verify -CAfile $ca_path $cert_path", $ssl); $ssl_tmp=explode(':',end($ssl)); $are_valid = (( trim($ssl_tmp[0])== "OK")||( trim($ssl_tmp[1])== "OK")); } } } return $are_valid; } /* ------------------------------------------------------------------------ */ ?>