wayne7b Posted August 31, 2007 Share Posted August 31, 2007 Need to conduct an SSL Socket session via PHP. The following openssl command line works: openssl s_client -cert '/path/to/cert/cert.pem' -key '/path/to/key/key.pem' -CAfile /path/to/ca/ca.crt -connect my.host.tld:12345 But I can't seem to "make it happen" via PHP. After reading that fsockopen() does not support an SSL "context" parameter in PHP 5, I tried a simpler test via stream_context_create() and stream_socket_client(), etc., but it seems that I can't supply the same arguments/opitons to stream_context_create as I can to openssl. For instance, stream_context_create seems not to allow setting a "key" option, but seems to require cert passphrase which the working ssl command does not require (not to mention that I do not know the password for the cert. It would be really cool if I could so soemthing like this, but I'm stuck as to how to resolve the "key vs. cert password" issue: <?php $host = 'my.host.tld'; $port = 12345; $timeout = 10; $cert = '/path/to/cert/cert.pem'; $key = '/path/to/cafile/cafile.pem'; $cafile = '/path/to/cafile/cafile.pem'; $context = stream_context_create(array('ssl'=>array('local_cert'=>$cert, 'key'=>'$key, 'cafile'=>'$cafile, ))); if ($fp = stream_socket_client('ssl://'.$host.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context)) { fwrite($fp, "\n"); echo fread($fp, 26); fclose($fp); } else { echo "ERROR: $errno - $errstr<br />\n"; } ?> Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/67461-ssl-socket-connection-problems/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.