Created
June 12, 2013 07:38
-
-
Save mrtimp/5763477 to your computer and use it in GitHub Desktop.
Extract a clients SSL certificate
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 | |
$options = array( | |
'ssl'=>array( | |
'capture_peer_cert' => true | |
) | |
); | |
// create our stream context requiring the peers certificate to be returned | |
$context = stream_context_create($options); | |
// create our socket connection to the server on the respective port | |
$socket = stream_socket_client("ssl://[ip_address]:[port]", $errno, $err, 2, STREAM_CLIENT_CONNECT, $context); | |
// get passed and recieved parameters | |
$params = stream_context_get_params($socket); | |
// use OpenSSL to extract the digitial certificate | |
$cert = openssl_x509_parse($params["options"]["ssl"]["peer_certificate"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment