使用Guzzle通过Curl请求传递客户端证书

时间:2018-03-29 06:12:11

标签: php laravel ssl curl guzzle

我有以下curl命令

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

工作正常。但是当我试图从Guzzle那里做的时候,它失败了。

我无法在请求中传递客户端证书。

这就是我试过的

$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;
        }

我在Guzzle文档中找不到任何解决方案。

知道为什么这不起作用?

我得到的错误是

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

1 个答案:

答案 0 :(得分:9)

您可以使用ssl_keycert

%%timeit -n 1
s3='ab' 'ba'
print(s3)

如果他们有密码短语,您可以这样设置:

$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       
    ]
);