sslcurl

curl:(51) : SSL certificate subject name does not match target host name


I am having an issue where my SSL certificate subject name 'does match' the target host name but yet it throws the error

bash-4.1$ curl -X GET --cacert ./server-cert.pem --cert ./client-cert.pem --key ./client-key.pem 'https://PHXC02NX7CBG3QD:9001'
curl: (51) SSL: certificate subject name 'PHXC02NX7CBG3QD' does not match target host name 'PHXC02NX7CBG3QD'

As it can be seen that both the names are matching yet an error is thrown for reasons unkonwn.

Any help will be appreciated. Thanks in advance!


Solution

  • Just pass CURLOPT_SSL_VERIFYHOST equals to FALSE in curl request

        $url = 'https://aa.com';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (curl_exec($ch) === false) {
            echo 'Curl error: ' . curl_error($ch);
        } else {
            echo 'Operation completed without any errors';
        }
        $content = curl_exec($ch);
        curl_close($ch);