I need to get SSL certificate details (like expiry date, Issuer) of a domain. So for that I ran the following commands from PHP file.
ssl.php
$cdates= shell_exec('openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates');
$issuer= shell_exec('openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -issuer');
echo "$cdates";
echo "$issuer";
Getting the following output:
notBefore=Dec 10 11:54:23 2014 GMT notAfter=Mar 10 00:00:00 2015 GMT
issuer= /C=US/O=Google Inc/CN=Google Internet Authority G2
Now my question is how can I get the parameters from the variables?
For example I need to get CN value (Google Internet Authority G2) from $issuer
variable.
So Is there any command/function exists for that or I need to use regular expressions to extract CN from the string?
Any suggestions would be much appreciated.
Seems like this would be a cleaner approach (using phpseclib):
<?php
include('File/X509.php');
$x509 = new File_X509();
$cert = $x509->loadX509(shell_exec('openssl s_client -connect example.com:443 2>/dev/null'));
print_r($x509->getIssuerDNProp('CN'));
?>