title: BankID and CURL ERROR 77 or CURL ERROR 60
body: <p>I've spent a few hours trying to get cURL (in PHP) to work with the Swedish <a href="https://www.bankid.com/utvecklare" rel="nofollow noreferrer">BankID service</a>, and running into the following two certificate errors:</p>
  <pre><code>CURL ERROR 60: SSL certificate problem: unable to get local issuer certificate
  
  CURL ERROR 77: error setting certificate verify locations:
    CAfile: C:\test\bankid\bankid_test_server.pem
    CApath: C:\test\bankid\bankid_test_server.pem
  </code></pre>
  <p>The code I'm using to initialize cURL is the following:</p>
  <pre><code>curl_setopt($ch, CURLOPT_FAILONERROR, true);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);        
  curl_setopt($ch, CURLOPT_CAINFO, getcwd().DIRECTORY_SEPARATOR.$bankidServerCertFile);
  curl_setopt($ch, CURLOPT_CAPATH, getcwd().DIRECTORY_SEPARATOR.$bankidServerCertFile);
          
  curl_setopt($ch, CURLOPT_SSLCERT, $clientCertFile);
  curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $clientCertPass);
  curl_setopt($ch, CURLOPT_SSLKEY, $clientCertKeyFile);
  curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $clientCertKeyPass);
  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  </code></pre>
  <p>I've tried various variations of the <code>CURLOPT_CAINFO</code> and <code>CURLOPT_CAPATH</code> options, but I still get either of the two errors (when I try some variations of the options I get one, when I try some other variations I get the other error).</p>
  <p>I got the server certificate by following the advice to export it using Firefox, as described in <a href="https://stackoverflow.com/questions/7130271/php-curl-and-ssl-certificate-or-cert-chain">this SO question</a>. The certificate file is in the correct location and readable.</p>