通过"set api ssl"命令可以将PHPoC启动为SSL server。 下面是SSL server设定例。
$port = 1470; // port number
$pid = pid_open("/mmap/tcp0"); // open TCP 0
pid_ioctl($pid, "set api ssl"); // set api to SSL
pid_ioctl($pid, "set ssl method server"); // set SSL server mode
pid_bind($pid, "", $port); // binding
pid_listen($pid); // listen TCP connection
do
$state = pid_ioctl($pid, "get state");
while(($state != SSL_CLOSED) && ($state != SSL_CONNECTED));
if($state == SSL_CONNECTED)
{
echo "Connection has been established!\r\n";
pid_close($pid); // close TCP connection
}
※ 当PHPoC作为SSL server使用时,在产品中需要保存认证。认证书可通过PHPoC Debugger生成或是保存。
下面是将PHPoC设定为SSL client的例子。
$addr = "10.1.0.2"; // server's IP address
$port = 1470; // server's port number
$pid = pid_open("/mmap/tcp0"); // open TCP 0
pid_ioctl($pid, "set api ssl"); // set api to SSL
pid_ioctl($pid, "set ssl method client"); // set SSL client mode
pid_connect($pid, $addr, $port); // connect to TCP server
do
$state = pid_ioctl($pid, "get state");
while(($state != SSL_CLOSED) && ($state != SSL_CONNECTED));
if($state == SSL_CONNECTED)
{
echo "Connection has been established!\r\n";
pid_close($pid); // close TCP connection
}
※ PHPoC的闪存容量增大时,无法获得可进行SSL通信的闪存空间,从而导致SSL动作异常或是无法工作。