Created
January 27, 2016 06:32
-
-
Save Kaweechelchen/712f0a97800f24aaf012 to your computer and use it in GitHub Desktop.
script to get the expiry date of the SSL cert of a specific domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('Europe/Luxembourg'); | |
$expiryDate = getCertExpiryDate('mona.lu'); | |
if ($expiryDate) { | |
echo date('r', $expiryDate ); | |
} | |
function getCertExpiryDate($domain) { | |
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE))); | |
$read = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get); | |
$cert = stream_context_get_params($read); | |
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate'], true); | |
if (strpos($certinfo['extensions']['subjectAltName'], $domain)) { | |
return $certinfo['validTo_time_t']; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment