简体   繁体   English

无法验证第一个证书 - Nodejs TLS

[英]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.

相关问题 使用 TLS 的 elasticdump - 无法验证第一个证书 - elasticdump with TLS - unable to verify the first certificate 无法使用loopbackjs验证nodejs中的第一个证书 - unable to verify the first certificate in nodejs with loopbackjs Nodejs Fetch API:无法验证第一个证书 - Nodejs Fetch API: unable to verify the first certificate 错误:无法验证nodejs中的第一个证书 - Error: unable to verify the first certificate in nodejs 无法验证第一个证书 - Unable to verify the first certificate 无法验证第一个证书; NodeJs 与 Python 请求 - Unable to verify the first certificate; NodeJs vs Python Requests 错误:无法验证nodejs中的第一个证书azure队列存储createMessage - Error: unable to verify the first certificate in nodejs azure queue storage createMessage stompit 是 nodejs 模块无法连接并出现错误“”无法验证第一个证书” - stompit is nodejs module failed to connect with error “”Unable to verify the first certificate" SwagQL - 无法验证第一个证书 - SwagQL - Unable to verify the first certificate 使用自生成证书从nodejs连接到elasticsearch时“无法验证第一个证书” - "unable to verify the first certificate" when connecting to elasticsearch from nodejs using self-generated certificates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM