ByPass SSL certificate validation with Artax

472 Views Asked by At

When making a POST request to a server with an invalid SSL certificate ( Cloudflare has to reissue the certificate ), Artax returns the following error:

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I have attempted to use

$client->setOption('tlsOptions', [
    'verify_peer' => FALSE,
]);

and

$request->setOption('tlsOptions', [
    'verify_peer' => FALSE,
]);

However in both cases errors are thrown.

Can anyone shed light on the correct method to disable peer verification with Artax?


Update

I've tried both:

$client->setAllOptions([
    'tlsOptions' => [
        'verify_peer' => FALSE,
        'allow_self_signed' => TRUE,
    ],
]);

And

$client->setOption('tlsOptions', [
    'verify_peer' => FALSE,
    'allow_self_signed' => TRUE,
]);

Both give me a response of 400 ( Bad Request ).

[status:Artax\Response:private] => 400
        [reason:Artax\Response:private] => Bad Request
        [protocol:Artax\Message:private] => 1.1
        [headers:Artax\Message:private] => Array
            (
                [Date] => Array
                    (
                        [0] => Mon, 19 May 2014 09:50:19 GMT
                    )

                [Server] => Array
                    (
                        [0] => Apache/2.4.9 (Ubuntu)
                    )

                [Content-Length] => Array
                    (
                        [0] => 303
                    )

                [Connection] => Array
                    (
                        [0] => close
                    )

                [Content-Type] => Array
                    (
                        [0] => text/html; charset=iso-8859-1
                    )

            )

        [headerCaseMap:Artax\Message:private] => Array
            (
                [DATE] => Date
                [SERVER] => Server
                [CONTENT-LENGTH] => Content-Length
                [CONNECTION] => Connection
                [CONTENT-TYPE] => Content-Type
            )
2

There are 2 best solutions below

2
Loïc On

Maybe allowing self signed would work :

$client->setOption('tlsOptions', [
    'verify_peer' => FALSE,
    'allow_self_signed' => TRUE,
    ]);
0
kelunik On

With the current master branch, the following will bypass the validation:

$client->setOption(Amp\Artax\Client::OP_CRYPTO, [
    "verify_peer" => false,
    "verify_peer_name" => false
]);