[英]Unable to verify the first certificate - Nodejs TLS
I'm using the node-module basic-ftp to try to establish a secure connection via TLS/ SSL .我正在使用节点模块basic-ftp尝试通过TLS/ SSL建立安全连接。 The server uses a wildcard CA-signed certificate as it's hostname.
服务器使用通配符 CA 签名证书作为主机名。 I can't seem to find an answer for the followig error code.
我似乎无法找到 followig 错误代码的答案。
Connected to 1.1.1.1:21
< 220 Welcome to ftp.foo.com
> AUTH TLS
< 234 Using authentication type TLS
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1051:34)
at TLSSocket.emit (events.js:189:13)
at TLSSocket._finishInit (_tls_wrap.js:633:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
Below you find the sample code:您可以在下面找到示例代码:
const ftp = require("basic-ftp");
async establishFtpsConnection() {
const client = new ftp.Client();
client.ftp.verbose = true;
try {
await client.access({
host: "ftp.foo.com",
user: "bar",
password: "1234",
port: 21,
secure: true
});
const list = await client.list();
console.log(list);
} catch (err) {
console.log(err);
}
client.close();
}
NOTE: I'm trying to get it to work for my production environment.注意:我试图让它在我的生产环境中工作。 So disabling or rejecting unauthorization is NO option for me.
所以禁用或拒绝未经授权对我来说是没有选择的。
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
OR或者
rejectUnauthorized: false
Try this :尝试这个 :
const ftp = require("basic-ftp");
async establishFtpsConnection() {
const client = new ftp.Client();
client.ftp.verbose = true;
const tlsOptions = {
cert: fs.readFileSync('fullchain.pem', 'ascii')
// a PEM containing the SERVER and ALL INTERMEDIATES
}
try {
await client.access({
host: "ftp.foo.com",
user: "bar",
password: "1234",
port: 21,
secure: true,
secureOptions:tlsOptions
});
const list = await client.list();
console.log(list);
} catch (err) {
console.log(err);
}
client.close();
}
If you are still getting an error then try to inject root SSL certificates如果您仍然收到错误,请尝试注入根 SSL 证书
var sslRootCAs = require('ssl-root-cas/latest')
sslRootCAs.inject()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.