Hi
My proplem is that I have a open socket in my server side code (written php) and I need to trasform this socket to use TLS, with negotiation and decription of the stream before passing it to the already existing code that work with a clear stream without encryption.
What is the simplest solution to archive this?
PHP supports TLS/SSL listening using a stream context. Something like this should work:
$listenstr = "tls://0.0.0.0:1234";
$ctx=stream_context_create(array('ssl'=>array(
"local_cert"=>"mycertandkey.pem",
"passphrase"=>"badpassphrase"
)));
$s = stream_socket_server($listenstr,$errno,$errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN,$ctx);
$conn = stream_socket_accept($s);
// do stuff with your new connection here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With