带有php服务器套接字的TLS [英] TLS with php server socket
本文介绍了带有php服务器套接字的TLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我的问题是,我在服务器端代码(写为php)中有一个开放的套接字,我需要对该套接字进行转换以使用TLS,并对该流进行协商和解密,然后再将其传递给可与清晰流一起使用的现有代码没有加密.
存档此内容的最简单解决方案是什么?
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支持使用流上下文进行TLS/SSL侦听.这样的事情应该起作用:
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
这篇关于带有php服务器套接字的TLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文