Skip to content

Instantly share code, notes, and snippets.

@mrtimp
Created June 12, 2013 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtimp/5763477 to your computer and use it in GitHub Desktop.
Save mrtimp/5763477 to your computer and use it in GitHub Desktop.
Extract a clients SSL certificate
<?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