Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches

前端 未结 6 1674
失恋的感觉
失恋的感觉 2020-12-13 01:06

I am new to CURL world, coming from Windows + .NET domain.

Trying to access Rest API for basic authentication at http://www.evercam.io/docs/api/v1/authentication.

6条回答
  •  星月不相逢
    2020-12-13 02:03

    it might save some time to somebody.

    If you use GuzzleHttp and you face with this error message cURL error 60: SSL: no alternative certificate subject name matches target host name and you are fine with the 'insecure' solution (not recommended on production) then you have to add \GuzzleHttp\RequestOptions::VERIFY => false to the client configuration:

    $this->client = new \GuzzleHttp\Client([
        'base_uri'                          => 'someAccessPoint',
        \GuzzleHttp\RequestOptions::HEADERS => [
            'User-Agent' => 'some-special-agent',
        ],
        'defaults'                          => [
            \GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 5,
            \GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => true,
        ],
        \GuzzleHttp\RequestOptions::VERIFY  => false,
    ]);
    

    which sets CURLOPT_SSL_VERIFYHOST to 0 and CURLOPT_SSL_VERIFYPEER to false in the CurlFactory::applyHandlerOptions() method

    $conf[CURLOPT_SSL_VERIFYHOST] = 0;
    $conf[CURLOPT_SSL_VERIFYPEER] = false;
    

    From the GuzzleHttp documentation

    verify

    Describes the SSL certificate verification behavior of a request.

    • Set to true to enable SSL certificate verification and use the default CA bundle > provided by operating system.
    • Set to false to disable certificate verification (this is insecure!).
    • Set to a string to provide the path to a CA bundle to enable verification using a custom certificate.

提交回复
热议问题