php-http-proxy icon indicating copy to clipboard operation
php-http-proxy copied to clipboard

https+wss proxy

Open xenion54 opened this issue 1 year ago • 2 comments

Hi @walkor. In my project, i'm using this awesome example of http proxy server. And its work fine. Btw its work for http+websocket proxy. But when i try to use it with https and wss its fail. I see, that this is because in method "onMessage" i have encrypted data. Can you pls help me to solve this task?

Of cource, when i do this

$remote_connection->pipe($connection); 
$connection->pipe($remote_connection);
$remote_connection->connect();

data passing encrypted to destination and its not what he expects.

I try to replace tcp://0.0.0.0:xxx to http://0.0.0.0:xxx, but it still not working. Pls, help me.

Here is my minimal code, for reproduce

<?php

$context = array(
    'ssl' => array(
        'local_cert' => app_paths['ssl_public_key'], // Alternatively, it can be a crt file
        'local_pk' => app_paths['ssl_private_key'],
        'verify_peer' => false,
        'allow_self_signed' => true,
    )
);

$worker = new Worker('tcp://0.0.0.0:' . $args['port'], $context);
$worker->transport = 'ssl';

$worker->onMessage = function ($connection, $buffer) use ($args) {

    list($method, $addr, $http_version) = explode(' ', $buffer);
    $remote_connection = new AsyncTcpConnection("tcp://{$args['proxy-ip']}:{$args['port']}");
    if ($method !== 'CONNECT') {
        $remote_connection->send($buffer);
    } else {
        $connection->send("HTTP/1.1 200 Connection Established\r\n\r\n");
    }
    $remote_connection->pipe($connection);
    $connection->pipe($remote_connection);
    $remote_connection->connect();

};

xenion54 avatar Oct 25 '24 18:10 xenion54

This project supports HTTPS and WSS without the need to modify the source code.

walkor avatar Oct 28 '24 00:10 walkor

Yes, supports. Just in $buffer variable inside onMessage callback, i have encrypted data in this example. When i disable https, buffer filled not encrypted data. i resolve my problem using nginx proxy for establish https connection. But still want to know what i m doing wrong.

xenion54 avatar Nov 09 '24 13:11 xenion54