I'm getting following error while reading SSL cert file from GCP Cloud Storage.
* Connected to [my.website.com] (A.b.C.D) port 443 (#0)
* found 6 certificates in /home/<username>/[CAINFO].crt
* found 597 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* error reading X.509 key or certificate file: Error while reading file.
* Closing connection 0
Error: SSL connect error
at Error (native)
file."
Here's what I'm doing.
- In NodeJS code, I'm pinging an API end point while authenticating with SSL certs
- I have an SSL cert stored in GCP Cloud Storage and made it Public (just for testing) following instructions given here.
- Instructions to access this object is given here.
Using
gsutil
, I am able to access the cert.$ gsutil ls -r gs://[BUCKET_NAME]/[SSLCERT].pem
gs://[BUCKET_NAME]/[SSLCERT].pem
When I access the SSL cert from NodeJS code, I get above error. The URL to access the file is:
http://storage.googleapis.com/[BUCKET_NAME]/[SSLCERT].pem
Instead of Cloud Storage, if I access the cert from local disk and run NodeJS code, it works fine. So, the cert is valid.
Outline of my code:
const Curl = require('node-libcurl').Curl;
const curl = new Curl();
const URL = 'https://api-end-point.com';
// let sslcert = '/home/path/to/[SSLCERT].pem'; << this works
let sslcert = 'http://storage.googleapis.com/[BUCKET_NAME]/[SSLCERT].pem'; << NOT working
curl.setOpt('URL', URL);
...
curl.setOpt('SSLCERT', sslcert);
...
curl.on('end', function(statusCode, body, headers) {
console.info("Status Code: " + statusCode);
console.info(body.length);
this.close();
});
curl.on('error', (err) => {
console.log(err);
});
curl.perform();