peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.37k stars 203 forks source link

ssl:// wrapper with encryption not implemented? #391

Closed xukku closed 4 years ago

xukku commented 5 years ago

trying to make request to https://site111/

$res = stream_socket_client($proto.$host.":".$port, $errno, $errstr, $this->socketTimeout); // $res = stream_socket_client("ssl://site111:443", $errno, $errstr, $this->socketTimeout);

and getting error

string(423) "HTTP/1.1 400 Bad Request
Server: nginx/1.14.0
Date: Sat, 23 Mar 2019 18:49:35 GMT
Content-Type: text/html
Content-Length: 271
Connection: close

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

in regular PHP request all works fine

jakubmisek commented 5 years ago

Can we have a test case? Thank you :)

xukku commented 5 years ago
function request($host, $path, $postData = [])
{
    $context = stream_context_create([
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true,
        ],
    ]);
    if (!$context) {
        echo "connection error\n";

        return false;
    }
    echo "[Connection to ssl://{$host}:443]\n";
    $fp = stream_socket_client('ssl://'.$host.':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
        fwrite($fp, "POST $path HTTP/1.0\r\nHost: $host\r\nAccept: */*\r\n\r\n");
        fwrite($fp, http_build_query($postData));
        while (!feof($fp)) {
            echo fgets($fp, 1024);
        }
        fclose($fp);
    }
}

function main()
{
    request('storehof.bitrix24.ru', '/rest/1/qwnx9wy3k9zur922/profile/');
}

main();

php program.php > resultphp.log

result for php - OK

[Connection to ssl://nexene.bitrix24.ru:443]
HTTP/1.1 200 OK
Server: nginx/1.14.0
Date: Sat, 20 Apr 2019 13:28:18 GMT
Content-Type: application/json; charset=utf-8
Connection: close
P3P: policyref="/bitrix/p3p.xml", CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA"
X-Powered-CMS: Bitrix Site Manager (bc2cad9153cb418bb2dfd5602c3c3754)
Set-Cookie: PHPSESSID=TvhZHoXGvucH1atJ0BtEG3dRw696B8f1; path=/; secure; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: qmb=.; path=/
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: origin, content-type, accept
X-Content-Type-Options: nosniff
X-Bitrix-Rest-Time: 0.0031170845
X-Bitrix-Rest-User-Time: 0.0010000000
X-Bitrix-Rest-System-Time: 0.0000000000
Set-Cookie: BITRIX_SM_SALE_UID=0; expires=Tue, 14-Apr-2020 13:28:18 GMT; Max-Age=31104000; path=/
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000; includeSubdomains

{"result":{"ID":"1","ADMIN":true,"NAME":"6umpukc","LAST_NAME":"Hanexene","PERSONAL_GENDER":"","TIME_ZONE":"","TIME_ZONE_OFFSET":10800},"time":{"start":1555766898.0611,"finish":1555766898.0954,"duration":0.034217119216919,"processing":0.0031170845031738,"date_start":"2019-04-20T16:28:18+03:00","date_finish":"2019-04-20T16:28:18+03:00"}}

dotnet run > resultpeachpie.log result for peachpie - not ok

[Connection to ssl://nexene.bitrix24.ru:443]
HTTP/1.1 400 Bad Request
Server: nginx/1.14.0
Date: Sat, 20 Apr 2019 13:28:31 GMT
Content-Type: text/html
Content-Length: 271
Connection: close

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.14.0</center>
</body>
</html>
jakubmisek commented 5 years ago

seems this is a part of the openssl extension, ref https://github.com/peachpiecompiler/peachpie/issues/402

jakubmisek commented 4 years ago

just confirming this has been implemented in https://github.com/peachpiecompiler/peachpie/commit/0321cad3d2ea735fcada74ca10370d6d4a954022

Known issue is SSL options:

'ssl' => ['verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true,]

are ignored and system defaults are used always