ratchetphp / Pawl

Asynchronous WebSocket client
MIT License
584 stars 85 forks source link

OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed #119

Closed marcosmarcolin closed 2 years ago

marcosmarcolin commented 3 years ago

https://github.com/ratchetphp/Pawl/issues/47

Hello, all right?

I have a problem similar to the issue above, but even escaping the certificate validation I have the problem occurring.

Follow my codes.

Server.php


<?php

require_once('includes/config.php');

use Maker\Utils\RatchetServer;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory;
use React\Socket\SecureServer;
use React\Socket\Server;

$app = new HttpServer(
    new WsServer(
        new RatchetServer()
    )
);

$loop = Factory::create();

$secure_websockets = new Server('192.168.25.150:8888', $loop);
$secure_websockets = new SecureServer($secure_websockets, $loop, [
    'local_cert' => '/var/www/cert.crt',
    'local_pk' => '/var/www/cert.key',
    'verify_peer' => false,
    'allow_self_signed' => true
]);

$secure_websockets_server = new IoServer($app, $secure_websockets, $loop);
$secure_websockets_server->run();

Client.php with problem


<?php

// failed

require('vendor/autoload.php');

\Ratchet\Client\connect('wss://192.168.25.150:8888',
    [
        'verify_peer' => false,
        'verify_peer_name' => false
    ]
)->then(function ($conn) {
    $conn->send(json_encode('Hello World!'));
}, function ($e) {
    echo '<pre>';
    var_dump($e->getMessage());
});

JS Working perfectly

// success
var socket = new WebSocket('wss://192.168.25.150:8888');

"Connection to 192.168.25.150:8888 failed during TLS handshake: Unable to complete TLS handshake: SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed"

Can anyone help? Thank you!

clue commented 3 years ago

In order to pass TLS options, you need to use the Ratchet\Client\Connector class instead of the connect() function and pass it an instance of React\Socket\Connector. See https://github.com/ratchetphp/Pawl/issues/53#issuecomment-800522810 and https://github.com/ratchetphp/Pawl/issues/72

marcosmarcolin commented 3 years ago

In order to pass TLS options, you need to use the Ratchet\Client\Connector class instead of the connect() function and pass it an instance of React\Socket\Connector. See #53 (comment) and #72

Thanks for the quick feedback Clue, I already tested it and it worked correctly, hug!