SSL certificate issue unable to get local issuer certificate SSL certificate issue unable to get local issuer certificate curl curl

SSL certificate issue unable to get local issuer certificate


When you connect to the server to establish secure connection you as a client get server's certificate in the beginning of the conversation with it. This certificate and its private key are used to establish the secure connection. You client wants to ensure that the server's certificate is trusted and is not created by some man-in-the middle attacker. So your client need to have the CA certificate that signed the server certificate. The error above means that the client tried to find server's certificate issuer (or one of the issuers in the chain) and didn't find. The place it tries to find it is in the specified /etc/apache2/ssl/m4/mydomain.com.crt file. You have two options: either add CA certificate to the file or to disable server certificate verification (not secure) by setting CURLOPT_SSL_VERIFYPEER to false.


I got support from my API providers who pointed something missing in my approach. For their gateway I needed to load the private key, public key and password that protects these keys in curl request. The solution is as follows:

/*ssl crts*/$twpg_cert_file = "/etc/apache2/ssl/m4/mydomain.com.crt";$twpg_key_file = "/etc/apache2/ssl/m4/mydomain.com.key";$twpg_key_password = '';/*ssl crts*/$ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $requestUrl);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_TIMEOUT, 60000);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);        curl_setopt($ch, CURLOPT_POST, 1);        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//My post data        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);        curl_setopt($ch, CURLOPT_SSLCERT,  $twpg_cert_file);        curl_setopt($ch, CURLOPT_SSLKEY, $twpg_key_file);        curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $twpg_key_password);        curl_setopt($ch, CURLOPT_CERTINFO, 1);        $headers = [];        array_push($headers, 'Content-Type: text/xml;charset=UTF-8');        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);        $content = trim(curl_exec($ch));        curl_close($ch);

Now every thing works as expected.