Making a connection in PHP using TLS

前端 未结 4 1611
北恋
北恋 2021-01-21 05:20

I wrote a small SIP client for a special purpose. Basically it connects to port 5060 using function fsockopen()

$fp = fsockopen(\"10.0.0.1\", 5060,          


        
相关标签:
4条回答
  • 2021-01-21 05:59

    You will also need to install the appropriate certificates to get TLS working. Check this SO question for an example of how to use your key files with regular TLS connections.

    Also, check the specs of SIPS itself in RFC 5630.

    0 讨论(0)
  • I just recently encountered this error, debugging here and there for connection problem or proxy problem, finally found the culprit ... and the solution was to install php-pecl-crypto extension.

    My machine is centos 7 using remi-repo for PHP

    0 讨论(0)
  • 2021-01-21 06:14

    I think some of your options are wrong for validating self signed certificates; the following should be enough to make it work:

    $context = stream_context_create([
      'ssl' => [
        'verify_peer' => true,
        'allow_self_signed' => true,
        'local_cert' => 'cert.cer',
      ],
    ]);
    
    0 讨论(0)
  • 2021-01-21 06:15

    This is enough to open a TLS connection:

    $context = stream_context_create();
    
    $fp = stream_socket_client('tls://'.$host.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context)
    

    if the certificates are in their place. If they are not, follow the instructions linked by Filippos.

    0 讨论(0)
提交回复
热议问题