Passing Client Certificates Through a Curl Request Using Guzzle

I have the following curl command

sudo curl -E openyes.crt.pem --key openyes.key.pem https://sky.myapitutorial.in:444/app/live/get

which works great. But when I try to make Guzzle out of it, it's a failure.

I cannot pass client certificates in the request.

Here is what I tried

$headers = ['Content-Type' => 'application/json','X-Client-Id' => config('mykey') , 'X-Client-Secret' => config('mykey')];

        $client = new client();

        try {
            $response = $client->post(
                $endpoint
                , 
                ['json' => $content, 'headers' => $headers,['connect_timeout' => 650]],
                [
                    'config' => [
                        'curl' => [
                            'CURLOPT_SSLKEY' => base_path().'/openyes.key.pem',
                            'CURLOPT_SSLCERT' => base_path().'/openyes.crt.pem',
                            'CURLOPT_VERBOSE' => true
                        ],
                    ]
                ],
                ['debug'=>true],
                ['http_errors' => false]
            );

            dd($response);

        }
        catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
            throw $e;
        }

I did not find a solution in the Guzzle documentation.

Any idea why this is not working?

The error I get is

cURL error 35: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure (see http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html)
+4
source share
1 answer

You can use ssl_key and cert :

$response = $client->post(
    $endpoint, [
        'json' => $content,
        'headers' => $headers,
        'connect_timeout' => 650,
        // add these
        'cert' => '/path/to/openyes.crt.pem',
        'ssl_key' => '/path/to/openyes.key.pem       
    ]
);

if they have a passphrase, you can set them like this:

        'cert' => ['/path/to/openyes.crt.pem', 'password'],
        'ssl_key' => ['/path/to/openyes.key.pem', 'password']
+1
source

Source: https://habr.com/ru/post/1695504/


All Articles