hitrov/oci-arm-host-capacity

PHP Fatal error: Uncaught Hitrov\Exception\CurlException: curl error occurred: SSL certificate problem: unable to get local issuer certificate

ZaydenGit opened this issue · 5 comments

not sure what I did wrong,

php index.php
PHP Fatal error: Uncaught Hitrov\Exception\CurlException: curl error occurred: SSL certificate problem: unable to get local issuer certificate, response: in C:.oci\oci-arm-host-capacity\src\HttpClient.php:31
Stack trace:
#0 C:.oci\oci-arm-host-capacity\src\OciApi.php(257): Hitrov\HttpClient::getResponse()
#1 C:.oci\oci-arm-host-capacity\src\OciApi.php(132): Hitrov\OciApi->call()
#2 C:.oci\oci-arm-host-capacity\index.php(74): Hitrov\OciApi->getInstances()
#3 {main}
thrown in C:.oci\oci-arm-host-capacity\src\HttpClient.php on line 31

im also getting this issue, did u find a solution?

You guys need to download the latest https://curl.se/docs/caextract.html and add this in Line 23 oof HttpClient.php
curl_setopt($curl, CURLOPT_CAINFO, 'C:/PATH_TO_CERT'); As you are running it on Windows and windows doesn't come with a standard set of SSL Certificates. You need to download them manually and add the neccessary code to tell the program where to find those.

You guys need to download the latest https://curl.se/docs/caextract.html and add this in Line 23 oof HttpClient.php curl_setopt($curl, CURLOPT_CAINFO, 'C:/PATH_TO_CERT'); As you are running it on Windows and windows doesn't come with a standard set of SSL Certificates. You need to download them manually and add the neccessary code to tell the program where to find those.

I'm getting the same issue, can you guide in a bit more detail please?
is this correct?

HttpClient:

<?php


namespace Hitrov;


use Hitrov\Exception\ApiCallException;
use Hitrov\Exception\CurlException;
use JsonException;

class HttpClient
{
    /**
     * @param array $curlOptions
     * @return array
     * @throws ApiCallException
     * @throws JsonException|CurlException
     */
    public static function getResponse(array $curlOptions): array
    {
        $curl = curl_init();
        // curl_setopt_array($curl, $curlOptions);
        curl_setopt($curl, $curlOptions, "C:/Tools/php83/cURL/cacert-2024-03-11.pem");
        
        $response = curl_exec($curl);
        $error = curl_error($curl);
        $errNo = curl_errno($curl);
        $info = curl_getinfo($curl);
        curl_close($curl);

        if ($response === false || ($error && $errNo)) {
            throw new CurlException("curl error occurred: $error, response: $response", $errNo);
        }

        $responseArray = json_decode($response, true);
        $jsonError = json_last_error();
        $logResponse = $response;
        if (!$jsonError) {
            $logResponse = json_encode($responseArray, JSON_PRETTY_PRINT);
        }

        if ($info['http_code'] < 200 || $info['http_code'] >= 300) {
            throw new ApiCallException($logResponse, $info['http_code']);
        }

        if ($jsonError) {
            $jsonErrorMessage = json_last_error_msg();
            throw new JsonException("JSON error occurred: $jsonError ($jsonErrorMessage), response: \n$logResponse");
        }

        return $responseArray;
    }
}

I'm getting the following error;

[01-May-2024 14:10:00 UTC] PHP Fatal error:  Uncaught TypeError: curl_setopt(): Argument #2 ($option) must be of type int, array given in C:\Users\%User%\oci-arm-host-capacity\src\HttpClient.php:23
Stack trace:
#0 C:\Users\%User%\oci-arm-host-capacity\src\HttpClient.php(23): curl_setopt()
#1 C:\Users\%User%\oci-arm-host-capacity\src\OciApi.php(257): Hitrov\HttpClient::getResponse()
#2 C:\Users\%User%\oci-arm-host-capacity\src\OciApi.php(132): Hitrov\OciApi->call()
#3 C:\Users\%User%\oci-arm-host-capacity\index.php(74): Hitrov\OciApi->getInstances()
#4 {main}
  thrown in C:\Users\%User%\oci-arm-host-capacity\src\HttpClient.php on line 23

There is no CURLOPT_CAINFO that's why i left $curlOptions in it's place.

But, even if i do put it in, i get the following Error;

[01-May-2024 14:14:39 UTC] PHP Fatal error:  Uncaught Hitrov\Exception\CurlException: curl error occurred: No URL set, response:  in C:\Users\%User%\oci-arm-host-capacity\src\HttpClient.php:32
Stack trace:
#0 C:\Users\%User%\oci-arm-host-capacity\src\OciApi.php(257): Hitrov\HttpClient::getResponse()
#1 C:\Users\%User%\oci-arm-host-capacity\src\OciApi.php(132): Hitrov\OciApi->call()
#2 C:\Users\%User%\oci-arm-host-capacity\index.php(74): Hitrov\OciApi->getInstances()
#3 {main}
  thrown in C:\Users\%User%\oci-arm-host-capacity\src\HttpClient.php on line 32

Which probably means it's working but then it get's stuck at line; 29> curl_close($curl);

If anyone else is here with this issue, this stack overflow helped me. Specifically Boern's answer:
https://stackoverflow.com/questions/24611640/curl-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate

TL:DR
If you are using php you need to add the following to your php.ini:
curl.cainfo="/path/to/downloaded/cacert.pem"
With the .pem file downloaded from https://curl.se/docs/caextract.html