【问题标题】:Passing client certificates through Curl request using Guzzle使用 Guzzle 通过 Curl 请求传递客户端证书
【发布时间】:2018-09-08 00:04:58
【问题描述】:

我有以下 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)

【问题讨论】:

    标签: php laravel ssl curl guzzle


    【解决方案1】:

    您可以使用ssl_keycert

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

    如果他们有密码,你可以这样设置:

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

    【讨论】:

    • 我现在得到了 cURL 错误 58:无法设置私钥文件:'/Users/ajeesh/Documents/Open/open-sme-backend-live/private.key' 类型 PEM(请参阅 @ 987654323@) 。我的私钥有一个密码短语。如何通过?
    • 作为一个数组,其中密码是第二个元素。我用一个例子修改了我的答案。
    • 你很快就会得到你的赏金 :) 它就像魅力一样!
    • 很高兴:D
    • 当在我的生产服务器上运行相同时,我收到错误“cURL 错误 35:错误:14094412:SSL 例程:ssl3_read_bytes:sslv3 警报错误证书”。在本地代码工作正常
    猜你喜欢
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 2015-02-26
    • 2015-02-13
    • 1970-01-01
    相关资源
    最近更新 更多