Ошибка unable to get local issuer certificate

I am getting an unable to get local issuer certificate error when performing an npm install:

typings ERR! message Unable to read typings for "es6-shim". You should check the
 entry paths in "es6-shim.d.ts" are up to date
typings ERR! caused by Unable to connect to "https://raw.githubusercontent.com/D
efinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/es6-shim
/es6-shim.d.ts"
typings ERR! caused by unable to get local issuer certificate

I have recently update to node 4 from a much earlier version and it sounds like node is much more strict when these kind of problems arise.

There is an issue discussed here which talks about using ca files, but it’s a bit beyond my understanding and I’m unsure what to do about it.

I am behind a corporate firewall, but I can get to the url fine in a browser without any restriction.

Does anyone have any further insight into this issue and what possible solutions there are?

I’m wondering about reverting to node 0.12 in the meantime :(

asked Apr 8, 2016 at 7:52

mindparse's user avatar

1

There is an issue discussed here which talks about using ca files, but it’s a bit beyond my understanding and I’m unsure what to do about it.

This isn’t too difficult once you know how! For Windows:

Using Chrome go to the root URL NPM is complaining about (so https://raw.githubusercontent.com in your case).
Open up dev tools and go to Security-> View Certificate. Check Certification path and make sure your at the top level certificate, if not open that one. Now go to «Details» and export the cert with «Copy to File…».

You need to convert this from DER to PEM. There are several ways to do this, but the easiest way I found was an online tool which should be easy to find with relevant keywords.

Now if you open the key with your favorite text editor you should see

-----BEGIN CERTIFICATE----- 

yourkey

-----END CERTIFICATE-----

This is the format you need. You can do this for as many keys as you need, and combine them all into one file. I had to do github and the npm registry keys in my case.

Now just edit your .npmrc to point to the file containing your keys like so

cafile=C:workspacerootCerts.crt

I have personally found this to perform significantly better behind our corporate proxy as opposed to the strict-ssl option. YMMV.

answered Jun 23, 2017 at 16:33

Tim L's user avatar

Tim LTim L

8477 silver badges7 bronze badges

10

Anyone gets this error when ‘npm install’ is trying to fetch a package from HTTPS server with a self-signed or invalid certificate.

Quick and insecure solution:

npm config set strict-ssl false

Why this solution is insecure?
The above command tells npm to connect and fetch module from server even server do not have valid certificate and server identity is not verified. So if there is a proxy server between npm client and actual server, it provided man in middle attack opportunity to an intruder.

Secure solution:

If any module in your package.json is hosted on a server with self-signed CA certificate then npm is unable to identify that server with an available system CA certificates.
So you need to provide CA certificate for server validation with the explicit configuration in .npmrc.
In .npmrc you need to provide cafile, please refer to more detail about cafile configuration.

cafile=./ca-certs.pem

In ca-certs file, you can add any number of CA certificates(public) that you required to identify servers. The certificate should be in “Base-64 encoded X.509 (.CER)(PEM)” format.

For example,

# cat ca-certs.pem 
DigiCert Global Root CA
=======================
-----BEGIN CERTIFICATE-----
CAUw7C29C79Fv1C5qfPrmAE.....
-----END CERTIFICATE-----

VeriSign Class 3 Public Primary Certification Authority - G5
========================================
-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQ......
-----END CERTIFICATE-----

Note: once you provide cafile configuration in .npmrc, npm try to identify all server using CA certificate(s) provided in cafile only, it won’t check system CA certificate bundles then.
Here’s a well-known public CA authority certificate bundle.

One other situation when you get this error:

If you have mentioned Git URL as a dependency in package.json and git is on invalid/self-signed certificate then also npm throws a similar error.
You can fix it with following configuration for git client

git config --global http.sslVerify false 

isherwood's user avatar

isherwood

57.7k16 gold badges113 silver badges154 bronze badges

answered Nov 22, 2019 at 4:26

Nils's user avatar

NilsNils

8801 gold badge9 silver badges21 bronze badges

2

If you’re on a corporate computer, it likely has custom certificates (note the plural on that). It took a while to figure out, but I’ve been using this little script to grab everything and configure Node, NPM, Yarn, AWS, and Git (turns out the solution is similar for most tools). Stuff this in your ~/.bashrc or ~/.zshrc or similar location:

function setup-certs() {
  # place to put the combined certs
  local cert_path="$HOME/.certs/all.pem"
  local cert_dir=$(dirname "${cert_path}")
  [[ -d "${cert_dir}" ]] || mkdir -p "${cert_dir}"
  # grab all the certs
  security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain > "${cert_path}"
  security find-certificate -a -p /Library/Keychains/System.keychain >> "${cert_path}"
  # configure env vars for commonly used tools
  export GIT_SSL_CAINFO="${cert_path}"
  export AWS_CA_BUNDLE="${cert_path}"
  export NODE_EXTRA_CA_CERTS="${cert_path}"
  # add the certs for npm and yarn
  # and since we have certs, strict-ssl can be true
  npm config set -g cafile "${cert_path}"
  npm config set -g strict-ssl true
  yarn config set cafile "${cert_path}" -g
  yarn config set strict-ssl true -g
}
setup-certs

You can then, at any time, run setup-certs in your terminal. Note that if you’re using Nvm to manage Node versions, you’ll need to run this for each version of Node. I’ve noticed that some corporate certificates get rotated every so often. Simply re-running setup-certs fixes all that.

You’ll notice that most answers suggest setting strict-ssl to false. Please don’t do that. Instead use the setup-certs solution to use the actual certificates.

answered Apr 9, 2021 at 16:32

tjklemz's user avatar

tjklemztjklemz

1,17012 silver badges19 bronze badges

0

Typings can be configured with the ~/.typingsrc config file. (~ means your home directory)

After finding this issue on github: https://github.com/typings/typings/issues/120, I was able to hack around this issue by creating ~/.typingsrc and setting this configuration:

{
  "proxy": "http://<server>:<port>",
  "rejectUnauthorized": false
}

It also seemed to work without the proxy setting, so maybe it was able to pick that up from the environment somewhere.

This is not a true solution, but was enough for typings to ignore the corporate firewall issues so that I could continue working. I’m sure there is a better solution out there.

answered Apr 14, 2016 at 16:03

nfiles's user avatar

nfilesnfiles

3003 silver badges8 bronze badges

0

My problem was that my company proxy was getting in the way. The solution here was to identify the Root CA / certificate chain of our proxy, (on mac) export it from the keychain in .pem format, then export a variable for node to use.

export NODE_EXTRA_CA_CERTS=/path/to/your/CA/cert.pem

answered Jan 21, 2021 at 18:52

Erik's user avatar

ErikErik

1454 silver badges9 bronze badges

0

There are different reason for this issue and workaround is different depends on situation. Listing here few workaround (note: it is insecure workaround so please check your organizational policies before trying).

enter image description here

Step 1: Test and ensure internet is working on machine with command prompt and same url is accessible directly which fails by NPM. There are many tools for this, like curl, wget etc. If you are using windows then try telnet or curl for windows.

Step 2: Set strict ssl to false by using below command

npm -g config set strict-ssl false

Step 3: Set reject unauthorized TLS to no by using below command:

export NODE_TLS_REJECT_UNAUTHORIZED=0

In case of windows (or can use screen to set environment variable):

set NODE_TLS_REJECT_UNAUTHORIZED=0

Step 4: Add unsafe param in installation command e.g.

npm i -g abc-package@1.0 --unsafe-perm true

answered Apr 20, 2021 at 3:54

Sandeep Kumar's user avatar

Once you have your certificate (cer or pem file), add it as a system variable like in the screenshot below.

This is the secure way of solving the problem, rather than disabling SSL. You have to tell npm or whatever node tool you’re using to use these certificates when establing an SSL connection using the environment variable NODE_EXTRA_CA_CERTS.

This is common when you’re behind a corporate firewall or proxy. You can find the correct certificate by just inspecting the security tab in Chrome when visiting a page while on your company’s VPN or proxy and exporting the certificate through the «Manage Computer Certificates» window in Windows.

enter image description here

answered Jan 6, 2022 at 14:30

Prasanth Louis's user avatar

Prasanth LouisPrasanth Louis

4,6572 gold badges34 silver badges47 bronze badges

answered Jul 9, 2019 at 0:06

Henry's user avatar

HenryHenry

2,8021 gold badge25 silver badges17 bronze badges

2

For anyone coming to this from macOS:

Somehow, npm hasn’t picked up correct certificates file location, and I needed to explicitly point to it:

$ echo "cafile=$(brew --prefix)/share/ca-certificates/cacert.pem" >> ~/.npmrc
$ cat ~/.npmrc # for ARM macOS
cafile=/opt/homebrew/share/ca-certificates/cacert.pem

answered Aug 29, 2022 at 22:11

m0nhawk's user avatar

m0nhawkm0nhawk

22.8k9 gold badges44 silver badges72 bronze badges

2

In case you use yarn:

yarn config set strict-ssl false

answered Dec 21, 2020 at 15:52

trnc's user avatar

trnctrnc

20.4k21 gold badges60 silver badges98 bronze badges

I have encountered the same issue. This command didn’t work for me either:

npm config set strict-ssl false

After digging deeper, I found out that this link was block by our IT admin.

http://registry.npmjs.org/npm

So if you are facing the same issue, make sure this link is accessible to your browser first.

answered Feb 5, 2020 at 18:37

Willy David Jr's user avatar

Willy David JrWilly David Jr

8,5065 gold badges44 silver badges55 bronze badges

2

Well this is not a right answer but can be consider as a quick workaround. Right answer is turn off Strict SSL.

I am having the same error

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip
Saving to C:UsersSamAppDataLocalTempphantomjsphantomjs-2.1.1-windows.zip
Receiving…

Error making request.
Error: unable to get local issuer certificate
at TLSSocket. (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38)

So the after reading the error.

Just downloaded the file manually and placed it on the required path.
i.e

C:UsersSamAppDataLocalTempphantomjs

This solved my problem.

    PhantomJS not found on PATH                                                                                                
Download already available at C:UserssamAppDataLocalTempphantomjsphantomjs-2.1.1-windows.zip                    
Verified checksum of previously downloaded file                                                                            
Extracting zip contents                                    

answered Jan 1, 2019 at 14:40

Somnath Sarode's user avatar

1

A disclaimer: This solution is less secure, bad practice, don’t do this.
I had a duplicate error message—I’m behind a corporate VPN/firewall. I was able to resolve this issue by adding a .typingsrc file to my user directory (C:UsersMyUserName.typingsrc in windows). Of course, anytime you’re circumventing SSL you should be yapping to your sys admins to fix the certificate issue.

Change the registry URL from https to http, and as seen in nfiles’ answser above, set rejectUnauthorized to false.

.typingsrc (placed in project directory or in user root directory)

{
     "rejectUnauthorized": false,
     "registryURL": "http://api.typings.org/"
}

Optionally add your github token (I didn’t find success until I had added this too.)

{
    "rejectUnauthorized": false,
    "registryURL": "http://api.typings.org/",
    "githubToken": "YourGitHubToken"
}

See instructions for setting up your github token at https://github.com/blog/1509-personal-api-tokens

answered May 31, 2016 at 7:32

Benson's user avatar

BensonBenson

4,0812 gold badges26 silver badges43 bronze badges

0

On FreeBSD, this error can be produced because the cafile path is set to a symlink instead of the absolute path.

answered Feb 8 at 2:41

gboone's user avatar

“Unable to get Local Issuer Certificate” is a common SSL certificate error. It is related to the incomplete certificate chain such as (most commonly) missing the intermediate certificate. The fix is to ensure the entire certificate chain is present.

We will dive into this issue to see why this happens and how to fix it.

Understanding certificate chain

A certificate chain is an ordered list of certificates, containing an SSL/TLS server certificate, intermediate certificate, and Certificate Authority (CA) Certificates, that enable the receiver to verify that the sender and all CA’s are trustworthy.

  • Root Certificate. A root certificate is a digital certificate that belongs to the issuing Certificate Authority. It comes pre-downloaded in most browsers and is stored in what is called a “trust store.” The root certificates are closely guarded by CAs.
  • Intermediate Certificate. Intermediate certificates branch off root certificates like branches of trees. They act as middle-men between the protected root certificates and the server certificates issued out to the public. There will always be at least one intermediate certificate in a chain, but there can be more than one.
  • Server Certificate. The server certificate is the one issued to the specific domain the user is needing coverage for.

We will use these files in this example.

  • CA certificate file (usually called ca.pem or cacerts.pem)
  • Intermediate certificate file (if exists, can be more than one. If you don’t know if you need an intermediate certificate, run through the steps and find out)
  • Server certificate file

How to get a free SSL certificate?

If you need a free SSL certificate for your website, Elementor Cloud Website is a great option. They offer fast speeds, good uptime, and excellent customer support. It is an end-to-end solution gives you everything you need in one place for your website. Web Hosting on Google Cloud + SSL certificate + WordPress + Website Builder + Templates.

We recommend using Elementor Cloud Website to build a website. It is very easy to start. You can get your website online in minutes. The price is $99 for one year. Plus, they offer a 30-day money-back guarantee, so you can try it out with no risk.

How do Certificate Chains work?

When we install our TLS certificate, we also be sent an intermediate root certificate or bundle.

When a browser downloads our website’s TLS certificate upon arriving at our homepage, it begins chaining that certificate back to its root. It will begin by following the chain to the intermediate that has been installed, from there it continues tracing backwards until it arrives at a trusted root certificate.

If the certificate is valid and can be chained back to a trusted root, it will be trusted. If it can’t be chained back to a trusted root, the browser will issue a warning about the certificate.

View Certificate Chain

Use the openssl utility that can display a certificate chain. The following command will display the certificate chain for google.com.

openssl s_client -connect google.com:443 -servername google.com 

0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.google.com
i:/C=US/O=Google Inc/CN=Google Internet Authority G2
1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority

In the openssl output, the numbered lines start with the server certificate (#0) followed by the intermediate (#1) and the root (#2).

The s: indicates the certificate subject, and i: indicates the issuing certificate’s subject.

Guidelines to verify the certificate chain is valid

  • Subject of each certificate matches the Issuer of the preceding certificate in the chain (except for the Entity certificate).
  • Subject and Issuer are the same for the root certificate.

If the certificates in the chain adhere to these guidelines, then the certificate chain is considered to be complete and valid.

  • The Subject of the intermediate certificate matches the Issuer of the entity certificate.
  • The Subject of the root certificate matches the Issuer of the intermediate certificate.
  • The Subject and Issuer are the same in the root certificate.

Example of a valid certificate chain

server certificate

openssl x509 -text -in entity.pem | grep -E '(Subject|Issuer):'

Issuer: C = US, O = Google Trust Services, CN = GTS CA 1O1
Subject: C = US, ST = California, L = Mountain View, O = Google LLC, CN = *.enterprise.apigee.com

Intermediate certificate

openssl x509 -text -in intermediate.pem | grep -E '(Subject|Issuer):'

Issuer: OU = GlobalSign Root CA – R2, O = GlobalSign, CN = GlobalSign
Subject: C = US, O = Google Trust Services, CN = GTS CA 1O1

Root certificate

openssl x509 -text -in root.pem | grep -E '(Subject|Issuer):'

Issuer: OU = GlobalSign Root CA – R2, O = GlobalSign, CN = GlobalSign
Subject: OU = GlobalSign Root CA – R2, O = GlobalSign, CN = GlobalSign

Check SSL Certificate with OpenSSL

Validate certificate chain with server and root Certificate

openssl verify cert.pem

cert.pem: C = Country, ST = State, O = Organization, CN = FQDN
error 20 at 0 depth lookup:unable to get local issuer certificate

We can use the following two commands to make sure that the issuer in the server certificate matches the subject in the ca certificate.

openssl x509 -noout -issuer -in cert.pem

issuer= /CN=the name of the CA

$ openssl x509 -noout -subject -in ca.pem

subject= /CN=the name of the CA

In the following case, we need to add the CAfile to verify the root certificate.

$ openssl verify -CAfile ca.pem cert.pem

cert.pem: OK

Validate certificate chain with server, intermediate, and root Certificate

$ openssl verify cert.pem

cert.pem: C = Countrycode, ST = State, O = Organization, CN = yourdomain.com
error 20 at 0 depth lookup:unable to get local issuer certificate

To complete the validation of the chain, we need to provide the CA certificate file and the intermediate certificate file when validating the server certificate file.

We can do that using the parameters CAfile (to provide the CA certificate) and untrusted (to provide intermediate certificate):

$ openssl verify -CAfile ca.pem -untrusted intermediate.cert.pem cert.pem

cert.pem: OK

If we have multiple intermediate CA certficates, we can use the untrusted parameter multiple times like -untrusted intermediate1.pem -untrusted intermediate2.pem .

Fix routines:X509_check_private_key:key values mismatch in 2 Ways

Related:

  • Exploring SSL Certificate Chain with Examples
  • Understanding X509 Certificate with Openssl Command
  • OpenSSL Command to Generate View Check Certificate
  • Converting CER CRT DER PEM PFX Certificate with Openssl
  • SSL vs TLS and how to check TLS version in Linux
  • Understanding SSH Key RSA DSA ECDSA ED25519
  • Understanding server certificates with Examples

Platform Notice: Cloud, Server, and Data Center — This article applies equally to all platforms.

Problem

The following is seen on the command line when pushing or pulling:

SSL Certificate problem: unable to get local issuer

Cause

There are two potential causes that have been identified for this issue.

  1. A Self-signed certificate cannot be verified. 
  2. Default GIT crypto backend (Windows clients)

Resolution

Resolution #1 — Self Signed certificate

Workaround

Tell git to not perform the validation of the certificate using the global option:

git config --global http.sslVerify false

(warning) Please be advised disabling SSL verification globally might be considered a security risk and should be implemented only temporarily

Resolution — Client Side

Please notice that we refer to the Certificate Authority in this article by the acronym CA. 

There are several ways this issue has been resolved previously. Below we suggest possible solutions that should be run on the client side:

  1.  Ensure the root cert is added to git.exe’s certificate store. The location of this file will depend on how/where GIT was installed. For instance, the trusted certificate store directory for Git Bash is C:Program FilesGitmingw64sslcerts. This is also discussed on this Microsoft blog.
  2. Tell Git where to find the CA bundle, either by running:

    git config --system http.sslCAPath /absolute/path/to/git/certificates

    where /absolute/path/to/git/certificates  is the path to where you placed the file that contains the CA certificate(s).

    or by copying the CA bundle to the /bin  directory and adding the following to the gitconfig file:

    sslCAinfo = /bin/curl-ca-bundle.crt
  3. Reinstall Git.
  4. Ensure that the complete certificate chain is present in the CA bundle file, including the root cert.

Resolution — Server Side

This issue can also happen on configurations where Bitbucket Server is secured with an SSL-terminating connector rather than a proxy

  1. Ensure that the Java KeyStore has the entire certificate chain (Intermediate CA and Root CA) 
    • View the Certificate Chain Details inside the KeyStore using a tool like the KeyStore Explorer to check

Resolution #2 — Default GIT crypto backend

When using Windows, the problem resides that git by default uses the «Linux» crypto backend, so the GIT operation may not complete occasionally. Starting with Git for Windows 2.14, you can configure Git to use SChannel, the built-in Windows networking layer as the crypto backend. To do that, just run the following command in the GIT client:

git config --global http.sslbackend schannel

This means that it will use the Windows certificate storage mechanism and you don’t need to explicitly configure the curl CA storage (http.sslCAInfo) mechanism.

What is the ‘ssl certificate problem unable to get local issuer certificate’ error

The unable to get local issuer certificate is a common issue faced by developers when trying to push, pull, or clone a git repository using Git Bash, a command-line tool specific to Windows.

The unable to get local issuer certificate error often occurs when the Git server’s SSL certificate is self-signed. The issue with self-signed certificates is that the private key associated with them cannot be revoked, making it a security vulnerability.

Alternatively, it can be due to incorrect configuration for Git on your system or when using git inside Visual Studio Code (VS Code) terminal.

What causes ‘ssl certificate problem unable to get local issuer certificate’

The unable to get local issuer certificate error is caused by the misconfiguration of the SSL certificate on your local machine. When pushing, pulling, or cloning, Git cannot verify your SSL certification, which leads to the error.

A valid HTTPS handshake requires both the client and the server to create a secure connection, allowing for safe communication between your local machine and where the source code is hosted. When the SSL certificate cannot be verified, Git cannot complete the HTTPS handshake with the server that hosts the repository.

When the unable to get local issuer certificate error occurs in VS Code, it is often because Visual Studio cannot locate the SSL certificate. This may be due to the path being misconfigured on the local machine.

How can you fix ‘ssl certificate problem unable to get local issuer certificate errors’

When ssl certificate problem unable to get local issuer certificate error is caused by a self-signed certificate, the fix is to add the certificate to the trusted certificate store.

By default, the trusted certificate store is located in the following directory for Git Bash:

C:Program FilesGitmingw64sslcerts

Open the file ca-bundle.crt located in the directory above, then copy and paste the Git SSL certificate to the end of the file. Once completed, save the file and run your git pull, push, or clone command.

Disabling SSL certificate validation is not recommended for security purposes. However, it is an option for fixing the ssl certificate problem unable to get local issuer certificate error.

You can disable SSL certificate validation locally in Git using the following command:

$ git -c http.sslVerify=false clone [URL]

You can also disable SSL certificate validation at a global level using the following command:

$ git config --global http.sslVerify false

To re-enable SSL certificate validation, use the following command:

$ git config --global http.sslVerify true

Another method for fixing the ssl certificate problem unable to get local issuer certificate error is to reinstall Git and choose the SSL transport backend option during the installation process.

If the unable to get local issuer certificate error occurs inside Visual Studio Code, you need to grant your repository access to the SSL certificates. To do this, git can be reconfigured with the --global flag on your SSL certificate configuration. This will give the Git server accessibility to the required SSL certificate.

To do this, run the following command in the Terminal:

git config --global http.sslBackend schannel

Accessibility to SSL certificate verification can also be set at the system level. To do this, you must be running in administrator mode before executing the following command:

git config --system http.sslBackend schannel

If the unable to get local issuer certificate error in Visual Studio Code is not due to accessibility but a location misconfiguration, this can be fixed by reassigning the path. This can be done through the following command:

git config --global http.sslcainfo "Path"

How to prevent ‘ssl certificate problem unable to get local issuer certificate’ errors

The main purpose of a SSL certificate is to confirm authentication so that the information passed between client and server is secure. When an unable to get local issuer certificate error occurs, a secure connection cannot be established, and the git client rejects your attempt to push, pull, or clone a repository for security reasons.

While disabling SSL certificates altogether is an option and common fix, it is not recommended. It opens up a security vulnerability for your repository and your local machine. Nevertheless, you can negate the unable to get local issuer certificate error by disabling SSL certificates at a local and global level. If SSL certificates are disabled at a global level, it is good to always enable them again so that other projects are not impacted by the intentional security disablement.

To prevent the error, ensure that you have a valid SSL certificate in your certificate store. Alternatively, you can reinstall your Git Bash with SSL Transport backend selected during the installation process.

If you are using Git via Visual Studio Code and have a valid SSL certificate in your certificate store but still encounter the certificate problem error, use the --global flag on your SSL certificate configuration to grant the Git server accessibility.

Kubernetes Troubleshooting With Komodor

We hope that the guide above helps you better understand the troubleshooting steps you need to take in order to fix the unable to get local issuer certificate error.

Keep in mind that this is just one of many Git errors that can pop up in your k8s logs and cause the system to fail. Due to the complex and distributed nature of k8s, the search for the root cause of each such failure can be stressful, disorienting, and time-consuming.

Komodor is a Kubernetes troubleshooting platform that turns hours of guesswork into actionable answers in just a few clicks. Using Komodor, you can monitor, alert and troubleshoot incidents in your entire K8s cluster.

For each K8s resource, Komodor automatically constructs a coherent view, including the relevant deploys, config changes, dependencies, metrics, and past incidents. Komodor seamlessly integrates and utilizes data from cloud providers, source controls, CI/CD pipelines, monitoring tools, and incident response platforms.

  • Discover the root cause automatically with a timeline that tracks all changes made in your application and infrastructure.
  • Quickly tackle the issue, with easy-to-follow remediation instructions.
  • Give your entire team a way to troubleshoot independently, without having to escalate.

Introduction

When working with NPM/ Node projects, I sometimes come across SSL or certificate errors, like the below error, after running a npm install:

npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY

npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY

npm ERR! unable to get local issuer certificate
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

Another similar example is:

{ Error: unable to get local issuer certificate
    at TLSSocket.<anonymous> (_tls_wrap.js:1116:38)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket._finishInit (_tls_wrap.js:643:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:473:38) code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }

In the above example, I was firing up a react app on my local machine to get started on development.

What does this mean?

This error just means that NPM could not verify the certificate of the registry that you are trying to download the package from.

Usually the cause is that the SSL certificate is not trusted or that your local machine does not have the certificate.

Another reason why this is happening is that you are behind a corporate proxy and its configured for “deep inspection”.
What this means is that as NPM tries to connect to the package registry, the proxy will then “swap” the SSL cert with its own to allow it to inspect your traffic.

So there could be automated systems to make your browser trust the root CA cert that issues these certificates, NPM is not configured to trust that Certificate Authority.

We can fix this issue in a few ways:

  1. Disable strict SSL checking strict-ssl=false
  2. Use the HTTP version of the NPM registry
  3. Set NODE_EXTRA_CA_CERTS environment variable
  4. Changing the cafile setting: npm config set cafile /path/to/your/cert.pem
  5. Stop rejecting unknown CAs: set NODE_TLS_REJECT_UNAUTHORIZED=0

1. Disable strict SSL checking strict-ssl=false

If you are unable to obtain the registry’s SSL certificate or are still experiencing issues after adding it to your trusted list, you can temporarily disable strict SSL checking by running the following command:

npm config set strict-ssl false

Note that disabling strict SSL checking can leave your system vulnerable to man-in-the-middle attacks, so it should only be used as a temporary workaround. Once you have resolved the SSL certificate issue, be sure to re-enable strict SSL checking by running:

npm config set strict-ssl true

2. Use the HTTP version of the NPM registry

We can change the registry to use the HTTP version (http://registry.npmjs.org).

The NPM registry is the location where NPM looks for packages when you use the npm install command.

When we first install NPM the public registry is set to HTTPS (https://registry.npmjs.org), however we can change this with the npm config command.

To set the NPM registry for HTTP, follow these steps:

  1. Open a terminal or command prompt window.
  2. Enter the following command to set the registry to the public NPM registry:

npm config set registry http://registry.npmjs.org/

The NODE_EXTRA_CA_CERTS environment variable allows you to add additional root certificates to the list of trusted certificates that Node.js and NPM use when making SSL/TLS connections.

This can be useful if you need to connect to a server that uses a certificate signed by a root certificate that is not included in the default list of trusted certificates on your system.

We can set it as follows (Linux or OSX systems):

export NODE_EXTRA_CA_CERTS=path/to/my-certs.pem

If you are on Windows you can do:

set NODE_EXTRA_CA_CERTS=C:\path\to\certificate.pem

When Node.js or an application built on top of it makes an SSL/TLS connection to a server, it checks the server’s certificate against a list of trusted root certificates. If the server’s certificate is signed by a trusted root certificate, the connection is allowed. If the certificate is not signed by a trusted root certificate, the connection is rejected.

Note:

The NODE_EXTRA_CA_CERTS environment variable is only read when the Node.js process is first launched. Changing the value at runtime using process.env.NODE_EXTRA_CA_CERTS has no effect on the current process.

4. Changing the cafile setting: npm config set cafile /path/to/your/cert.pem

We can change the CA file with the set cafile command like so:

npm config set cafile /path/to/root/certificate.pem

Note:

these CA settings will override the default “real world” certificate authority lookups that npm uses. If you try and use any public npm registries via https that aren’t signed by your CA certificate, you will get errors.

You can also configure ca string(s) directly.

npm config set ca "cert string"

ca can be an array of cert strings too. In your .npmrc:

ca[]="cert 1 base64 string"
ca[]="cert 2 base64 string"

The npm config commands above will persist the relevant config items to your ~/.npmrc file:

cafile=/path/to/cert.pem

We can use the environment variable of NODE_TLS_REJECT_UNAUTHORIZED. This variable will tell Node to reject certificates that are not valid or just ignore them.

Certificate checks that could end up being invalid includes: expired, unsigned or trusted by a root CA, does not match hostname, etc

The default value of NODE_TLS_REJECT_UNAUTHORIZED is 1 — reject any certificate thats got verification errors.

NODE_TLS_REJECT_UNAUTHORIZED=0 means that we ignore any certificate issues. This can be useful when we know what we are doing. Keeping this value to 0 exposes you to man in the middle attacks!

To set NODE_TLS_REJECT_UNAUTHORIZED, you can use the following command:

export NODE_TLS_REJECT_UNAUTHORIZED=0

This sets NODE_TLS_REJECT_UNAUTHORIZED to 0, which disables SSL/TLS certificate verification.

unable_to_get_issuer_cert_locally and Proxies

If you are behind a company firewall, you can get this unable_to_get_issuer_cert_locally because the proxy might be swapping the SSL cert with its own certificate to be able to inspect the traffic.

This is case, we just need to contact the company network admin to get the .pem file.

Another option is to download it using Firefox or Chrome by connecting to any website which the certificate is swapped (in this case the NPM registry — https://registry.npmjs.org)

Then you may use NODE_EXTRA_CA_CERTS to provide the certificate file to Node.js.

Summary

In this post, we went over a few ways to fix the error of NPM err code unable_to_get_issuer_cert_locally. This error is caused by NPM not being able to verify the certificate of the registry eg (https://registry.npmjs.org).

The reason for this could be that the SSL certificate is not trusted or your local machine does not have it. We can resolve this with using HTTP registry instead, setting strict-ssl to false, manually add the .pem file to NODE_EXTRA_CA_CERTS and use NODE_TLS_REJECT_UNAUTHORIZED to tell node to ignore all cert issues.

Additionally if you are running npm install behind a corporate firewall/ proxy then it could be that the SSL is swapped to inspect the traffic. In this case you will need to get the .pem file from your network admins and then use NODE_EXTRA_CA_CERTS setting!

Понравилась статья? Поделить с друзьями:
  • Ошибка u3110 ваз 2107 инжектор
  • Ошибка unable to find при запуске
  • Ошибка u3006 форд мондео 4
  • Ошибка u3006 ford s max
  • Ошибка unable to find the ubisoft game launcher