Unable to verify first certificate


Chris Seymour

I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this error:

{[ERROR: Unable to verify first certificate] Code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'}

Python script (Python 3.4.3 and requests library) :

import requests
print(requests.get(url, verify='/tmp/cert/cacert.pem'))

Node script (node ​​4.2.6 and requests library) :

var fs = require('fs');
var request = require('request');

request.get({
    url: url,
    agentOptions: {
        ca: fs.readFileSync('/tmp/cert/cacert.pem')
    }
}, function (error, response, body) {
    if (error) {
        console.log(error);
    } else {
        console.log(body);
    }
});

Both use the same OpenSSL version:

$ python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.0.2e-fips 3 Dec 2015

$ node -pe process.versions.openssl 
1.0.2e

I don't think there is a problem with the certificate bundle, and I don't want to turn off host verification in Node.

Does anyone know why Node is throwing this error?

Chris Seymour

The documentation describes the caoption as follows:

ca: String, buffer or array or buffer of strings of trusted certificates in PEM format. If this option is omitted, multiple well-known "root" CAs, such as VeriSign, will be used. These are used to authorize connections.

So it doesn't want to have CA bundles. The fix is ​​simple, just split the bundle like this:

var fs = require('fs');
var request = require('request');

var certs = fs.readFileSync('/tmp/cert/cacert.pem').toString().split("\n\n"); 

request.get({
    url: url,
    agentOptions: {
        ca: certs
    }
}, function (error, response, body) {
    if (error) {
        console.log(error);
    } else {
        console.log(body);
    }
});

Related


Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate

Chris Seymour I have a directory with certificate bundles, Python scripts and Node scripts. Both scripts make GET requests to the same URL and provide the same certificate bundle. The Python script makes the request as expected, but the node script throws this

Unable to verify first certificate in nodejs

Singh Why does this error occur? Can someone tell me what is the solution for this? If I create a new project using npm init command. UNABLE_TO_VERIFY_LEAF_SIGNATURE error on run Singh you can use this command npm config set strict-ssl false It just disables

NGINX - Unable to verify first certificate

Safek I have Nextcloud (21.0.3) and Onlyoffice Documents Server (6.3.2.2) installed on the same server without docker. I only use nginx as a webserver. The SSL certificate is from European SSL. Nextcloud and Document Server they have different domain names ->

request, error: Unable to verify first certificate

Mr D I want to make a simple POST HTTP request using the requestmodule : var request = require("request"); var form = {form: {some: "form", attributes: "attrs"}} request.post("https://example.com", form) .on('response', function(response) { if (response

request, error: Unable to verify first certificate

Mr D I want to make a simple POST HTTP request by using the requestmodule : var request = require("request"); var form = {form: {some: "form", attributes: "attrs"}} request.post("https://example.com", form) .on('response', function(response) { if (respo

request, error: Unable to verify first certificate

Mr D I want to make a simple POST HTTP request using the requestmodule : var request = require("request"); var form = {form: {some: "form", attributes: "attrs"}} request.post("https://example.com", form) .on('response', function(response) { if (response

Unable to verify first certificate in Node.js

Sideeq Youssef I have a Nodejs API which uses ssl and https, so I am trying to use it on another server to build a web application using express-js. I get the following error when making a GET request: events.js:141 throw er; // Unhandled 'error' event

Unable to verify first certificate in Node.js

Sideeq Youssef I have a Nodejs API which uses ssl and https, so I am trying to use it on another server to build a web application using express-js. I get the following error when making a GET request: events.js:141 throw er; // Unhandled 'error' event

request, error: Unable to verify first certificate

Mr D I want to make a simple POST HTTP request using the requestmodule : var request = require("request"); var form = {form: {some: "form", attributes: "attrs"}} request.post("https://example.com", form) .on('response', function(response) { if (response

request, error: Unable to verify first certificate

Mr D I want to make a simple POST HTTP request using the requestmodule : var request = require("request"); var form = {form: {some: "form", attributes: "attrs"}} request.post("https://example.com", form) .on('response', function(response) { if (response

Node error on Heroku instance: Unable to verify first certificate

Tyler Harden I am trying to run an API provided via heroku. Currently I'm using SSL encryption and I've added it to the site via the panel domains and certificatesin the Settings page . While I can connect to the site on the browser using https and postman, I

expo init <project> throws Unable to verify first certificate

wizard I'm using a work machine behind a corporate proxy. When I run expo init I get the following error request to https://registry.npmjs.org/expo-template-blank failed, reason: unable to verify the first certificate FetchError: request to https://registry.np

Node error on Heroku instance: Unable to verify first certificate

Tyler Harden I am trying to run an API provided via heroku. Currently, I'm using SSL encryption and I've added it to the site via the panel domains and certificatesin the Settings page . While I can connect to the site on the browser using https and postman, I

Node error on Heroku instance: Unable to verify first certificate

Tyler Harden I am trying to run an API provided via heroku. Currently, I'm using SSL encryption and I've added it to the site via the panel domains and certificatesin the Settings page . While I can connect to the site on the browser using https and postman, I

Node error on Heroku instance: Unable to verify first certificate

Tyler Harden I am trying to run an API provided via heroku. Currently, I'm using SSL encryption and I've added it to the site via the panel domains and certificatesin the Settings page . While I can connect to the site on the browser using https and postman, I

expo init <project> throws Unable to verify first certificate

wizard I'm using a work machine behind a corporate proxy. When I run expo init I get the following error request to https://registry.npmjs.org/expo-template-blank failed, reason: unable to verify the first certificate FetchError: request to https://registry.np

expo init <project> throws Unable to verify first certificate

wizard I'm using a work machine behind a corporate proxy. When I run expo init I get the following error request to https://registry.npmjs.org/expo-template-blank failed, reason: unable to verify the first certificate FetchError: request to https://registry.np

expo init <project> throws Unable to verify first certificate

wizard I'm using a work machine behind a corporate proxy. When I run expo init I get the following error request to https://registry.npmjs.org/expo-template-blank failed, reason: unable to verify the first certificate FetchError: request to https://registry.np