1

I'm quite newbie of PHP, but studying and trying to build simple webpage which displays SSL Certificate status. (e.g.Expiry date) Also each servers(common name) and ports are stored at MySQL DB and read by PDO. Usually this works if server returns valid certificate. However it fails to load when certificate is expired or by other reasons such as unmatched Common Name.

Code as below:

<?php
    $get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
    $read = stream_socket_client("ssl://".$row["domain"].":".$row["port"], $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
    $cert = stream_context_get_params($read);
    $certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
?>

May I be advised how to resolve this issue please?

Thank you!

SAVAFA
  • 818
  • 8
  • 23
Minibrary
  • 21
  • 2

1 Answers1

1

Foolish myself, found solution from Stack Overflow. SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Modified first line:

$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));

into:

$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE, 'verify_peer' => false, 'verify_peer_name' => false)));
Community
  • 1
  • 1
Minibrary
  • 21
  • 2