TLS与php服务器套接字

Mac*_*acs 6 php sockets ssl

嗨,
我的问题是,我的服务器端代码(编写php)中有一个打开的套接字,我需要将此套接字转换为使用TLS,在将流传递给已经存在的代码使用清除之前对流进行协商和解密没有加密的流.存档这个最简单的解决方案是什么?

小智 3

PHP 支持使用流上下文的 TLS/SSL 监听。像这样的东西应该有效:

$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 
Run Code Online (Sandbox Code Playgroud)