【发布时间】:2016-06-20 04:37:52
【问题描述】:
我在 PHP 中使用 stream_socket_client() 使用 TLS 协议连接到服务器时遇到问题。
让我在下面显示我的代码:
$host = '192.168.0.112';
$context = stream_context_create();
$result = stream_context_set_option($context, 'ssl', 'local_cert', 'D:/xampp/htdocs/ssl_test/cert.pem');
$result = stream_context_set_option($context, 'ssl', 'verify_peer', 'true');
$result = stream_context_set_option($context, 'ssl', 'passphrase', '123456');
$socket = stream_socket_client('tls://'.$host.':5443/Exec', $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $context);
运行后,我收到如下消息错误:
警告:stream_socket_client(): Unable to set private key file `D:\xampp\htdocs\ssl_test\cert.pem' in D:\xampp\htdocs\ssl_test\index2.php on line 9
警告:stream_socket_client():无法在第 9 行的 D:\xampp\htdocs\ssl_test\index2.php 中启用加密
警告:stream_socket_client():无法连接到第 9 行 D:\xampp\htdocs\ssl_test\index2.php 中的 tls://192.168.0.112:5443/Exec(未知错误)
请注意,我有两个通用文件用于证书 cert.pem、key.pem 和 password="123456"
我不知道将 stream_context_set_option() 配置到服务器以及在哪里将 key.pem 设置为配置有什么错误或遗漏。
如果有人知道,请帮助我。
非常感谢您, 万纳克。
【问题讨论】:
标签: php ssl certificate key