43

When I used openssl APIs to validate server certificate (self signed), I got following error :

error 19 at 1 depth lookup:self signed certificate in certificate chain

As per openssl documentation, this error (19) is

"X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain - the certificate chain could be built up using the untrusted certificates but the root could not be found locally."

Why this error occurs ? Any problems with my server certificate ?

Vadzim
  • 24,954
  • 11
  • 143
  • 151
Lunar Mushrooms
  • 8,358
  • 18
  • 66
  • 88

6 Answers6

32

You have a certificate which is self-signed, so it's non-trusted by default, that's why OpenSSL complains. This warning is actually a good thing, because this scenario might also rise due to a man-in-the-middle attack.

To solve this, you'll need to install it as a trusted server. If it's signed by a non-trusted CA, you'll have to install that CA's certificate as well.

Have a look at this link about installing self-signed certificates.

Eitan T
  • 32,660
  • 14
  • 72
  • 109
26

Here is one-liner to verify certificate to be signed by specific CA:

openssl verify -verbose -x509_strict -CAfile ca.pem certificate.pem

This doesn't require to install CA anywhere.

See How does an SSL certificate chain bundle work? for details and correct certificate chain handling.

Vadzim
  • 24,954
  • 11
  • 143
  • 151
5

The solution for the error is to add this line at the top of the code:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
Serg
  • 2,346
  • 3
  • 29
  • 38
lalithsagar
  • 141
  • 1
  • 2
  • 11
    i would consider this a work around or an option for testing. it should not be persistant because it undermines the available security. – Alexander Stohr Apr 17 '19 at 07:34
  • 4
    This seems to be specific to Node.js, if I'm not mistaken. – sshow Nov 18 '19 at 18:02
  • 2
    It *is* NodeJS-specific and just disables all certificate checks. You could do this but only if you really know what you're doing. Just putting this in here as an answer is bad because whoever is using this doesn't get any information on what they're doing. – Sebastian Mar 17 '21 at 09:19
  • 1
    This is not a solution. -10 – spryce Nov 04 '21 at 23:46
  • 1
    I am fine using this for development. DevOps can deal with certs on production however they want. – Qwerty Oct 25 '22 at 10:08
5

If you're running Charles and trying to build a container then you'll most likely get this error.

Make sure to disable Charles (macos) proxy under proxy -> macOS proxy

Charles is an

HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet.

So anything similar may cause the same issue.

kemicofa ghost
  • 16,349
  • 8
  • 82
  • 131
0

if you are testing your end points using Postman, just go to settings and disable "Enable SSL certificate verification"

-1

You can also skip the SSL verification globally using the command:

git config --global http.sslVerify false
Jordan Ferr
  • 191
  • 2
  • 11