D
D
DromHour2021-04-09 00:24:13
API
DromHour, 2021-04-09 00:24:13

Why doesn't Axios accept an SSL certificate (unable to verify the first certificate)?

I create a REST API on a website, SSL is accepted by the browser, Encryption Everywhere is released.
When trying to make a request from the program via Axios, it throws an error:

Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
at TLSSocket.emit (events.js:198:13)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
at TLSSocket._finishInit(_tls_wrap.js:636:8)

Since the SSL certificate is free, I realized that there is no trust in it. However, how do I add the certificate to the trusted list when requested?
Tried:
const agent = new https.Agent({
    rejectUnauthorized: false,
    ca: fs.readFileSync("./certificate.crt")
});
(async() => {
    console.log(await axios.get('http://site.ru/api.php'), {httpsAgent: agent});
})()


certificate.crt tried to put both root, and intermediate, and standard, even tried to combine them into a list - it doesn’t work out ...
Actually, what should I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2021-04-09
@CityCat4

Study the issue deeper and figure out:
- either what root certificate store is used in this code fragment (it’s not at all a fact that the place where you put it is used as a root certificate store, besides, don’t forget to make links)
- or how to disable validation (force to accept any certificate). This, of course, is a so-so solution, it’s impossible to sell it, but for testing, so as not to slow down at this place, it will do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question