&1 >/dev/null"; exec($cmd,$output,$returnCode); error_log("output: ".print_r($output,true)); if ($returnCode == 0) { // // Check to make sure there is a key in the file // $cmd="openssl rsa -noout -modulus -in ".$tmpfilename; error_log("cmd: ".$cmd); exec($cmd,$keymodulus,$returnCode); if ($returnCode == 0) { // // Make sure there is a certificate in the files // $cmd="openssl x509 -noout -modulus -in ".$tmpfilename; error_log("cmd: ".$cmd); exec($cmd,$certmodulus,$returnCode); if ($returnCode == 0) { // // Verify the modulus match // error_log("keymoduls: ".$keymodulus."\ncertmodulus: $certmodulus"); if ($certmodulus == $keymodulus) { $cmd="sudo mv ".$tmpfilename." ".$certfilename; error_log("cmd: ".$cmd); exec($cmd,$output,$returnCode); if ($returnCode == 0) { error_log("Uploaded file ".$filename." moved to ".$certfilename."."); $returnMessage="SSL certificate file upload completed."; } else { error_log("Failed to move file ".$filename." to ".$certfilename."."); $returnMessage="SSL certificate file move to https certificate directory failed."; } } else { error_log("The key and certificate modulus do not match."); $returnMessage="The key and certificate modulus do not match."; } } else { error_log("The uploaded file does not contain a certificate."); $returnMessage="The uploaded file does not contain a certificate."; } } else { // // Check and see if there is a password // $cmd=" openssl rsa -noout -in /tmp/user_ssl.pem 2>&1 | grep 'bad password read'" ; error_log("cmd: ".$cmd); exec($cmd,$output,$returnCode); error_log("output: ".print_r($output,true)); if ($returnCode == 0) { error_log("The uploaded certificate file has a pass phrase."); $returnMessage="The uploaded certificate file has a pass phrase."; } else { $cmd=" openssl rsa -noout -in /tmp/user_ssl.pem 2>&1 | grep 'ANY PRIVATE KEY'" ; error_log("cmd: ".$cmd); exec($cmd,$output,$returnCode); if ($returnCode == 0) { error_log("The uploaded file does not contain the public/private key information."); $returnMessage="The uploaded file does not contain the public/private key information."; } else { error_log("The uploaded file contains invalid/corrupt public/private key information."); $returnMessage="The uploaded file contains invalid/corrupt public/private key information."; } } } } else { error_log("Uploaded file ".$filename." is not a pem file."); $returnMessage="Uploaded file ".$filename." is not a pem file."; } } } ?> SSL Communication certificate upload