简体   繁体   English

在套接字连接中添加客户端证书

[英]Add client certificate in socket connection

I am stuck with this problem since last few days but could not get any solution. 自最近几天以来,我一直困扰于此问题,但无法获得任何解决方案。

I am using net php-epp client and here is my code... 我正在使用net php-epp客户端,这是我的代码...

$context = stream_context_create(
    array(
        'ssl'=>array(
            'local_cert'=> dirname(__FILE__).'/cert.pem',
            'passphrase' => dirname(__FILE__).'/key.pem',
        )
    )
);

$greeting = $client->connect($host, $port, $timeout, $ssl, $context);
echo $greeting;

I am getting following error... 我遇到以下错误...

Warning: stream_socket_client(): Unable to set private key file

And before you ask key.pem starts with -----BEGIN RSA PRIVATE KEY----- and cert.pem starts with -----BEGIN CERTIFICATE----- 在您询问key.pem-----BEGIN RSA PRIVATE KEY-----开头和cert.pem-----BEGIN CERTIFICATE-----开头

However i can connect using... 但是我可以使用...连接

openssl s_client -connect epp.dom.net:700 -key key.pem -cert cert.pem -CApath /etc/ssl/certs/

This command shows connected, so does that mean my certificates are fine? 此命令显示已连接,这是否意味着我的证书很好?

Please someone help me to fix this. 请有人帮我解决这个问题。 Please

Thank You. 谢谢。

According to the PHP documentation , the private key must be specified in the local_pk stream context option. 根据PHP文档 ,必须在local_pk流上下文选项中指定local_pk The passphrase option (which you are currently using) is necessary when the private key file itself was encrypted with a passphrase: 当私钥文件本身使用密码短语加密时,必须使用passphrase选项(当前正在使用):

local_pk string local_pk字符串

Path to local private key file on filesystem in case of separate files for certificate (local_cert) and private key. 如果证书(local_cert)和私钥使用单独的文件,则文件系统上本地私钥文件的路径。

passphrase string passphrase字符串

Passphrase with which your local_cert file was encoded. 用来编码local_cert文件的密码。

This means your stream context should be initialized like this: 这意味着您的流上下文应该像这样初始化:

$context = stream_context_create(array(
    'ssl' => array(
        'local_cert' => dirname(__FILE__) . '/cert.pem',
        'local_pk' => dirname(__FILE__) . '/key.pem',
    )
));

Alternatively, you can also concatenate certificate and private key into one file and use the local_cert option only (plus a passphrase option if -- and only if -- your private key is encrypted with a passphrase). 或者,您也可以将证书和私钥连接到一个文件中,并仅使用local_cert选项(如果且仅当您的私钥使用密码加密时,再加上passphrase选项)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP - SSL套接字客户端证书 - PHP - SSL socket client certificate PHP客户端套接字与C#套接字服务器的连接 - PHP client socket connection with C# Socket Server 如何在PHP中将受信任的证书颁发机构列表设置为socket客户端? - How to set trusted certificate authorities list to socket client in PHP? stream_socket_client 无法连接(连接超时) - stream_socket_client unable to connect (connection timed out) PHP客户端和Java服务器之间的SSL套接字连接 - SSL socket connection between PHP client and Java server 如何打开PHP套接字连接并从客户端请求/维护数据 - How to open php socket connection and request/maintain data from client 创建客户端和服务器端套接字连接,并在php中保持连接 - Creating a client and server side socket connection and keeping it connected in php 在Ubuntu上的PHP客户端和C服务器之间建立TCP套接字连接 - Establishing TCP socket connection between PHP client and C server on Ubuntu 连接失败。 错误 #2:stream_socket_enable_crypto():PHPMailer 的对等证书 - Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate with PHPMailer haxe(php)https call:stream_socket_client()对等证书CN与预期的CN不匹配 - haxe (php) https call: stream_socket_client() Peer certificate CN did not match expected CN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM