【问题标题】:Unable to verify the first certificate (grpc/node)无法验证第一个证书(grpc/node)
【发布时间】:2018-06-04 20:26:09
【问题描述】:

对于一些背景,我正在关注this 教程,试图让节点示例正常工作。

我已经下载了文件夹,cd 到目录中,并尝试运行 npm install

我得到以下堆栈跟踪。

npm WARN package.json grpc-examples@0.1.0 No repository field.
npm WARN package.json grpc-examples@0.1.0 No license field.
\
> grpc@1.12.2 install /tmp/grpc/examples/node/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp WARN Tried to download(400): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.12.2/node-v46-linux-x64-glibc.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for grpc@1.12.2 and node@4.5.0 (node-v46 ABI, glibc) (falling back to source compile with node-gyp) 
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: unable to verify the first certificate
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1022:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:586:8)
gyp ERR! stack     at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:428:38)
gyp ERR! System Linux 4.8.13-100.fc23.x86_64
gyp ERR! command "/home/nbkiq0w/.nvm/versions/node/v4.5.0/bin/node" "/home/nbkiq0w/.nvm/versions/node/v4.5.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--libr$ry=static_library" "--module=/tmp/grpc/examples/node/node_modules/grpc/src/node/extension_binary/node-v46-linux-x64-glibc/grpc_node.node" "--module_name=grpc_node" "--module_path=/tmp/grpc/examples/node/node_mo$ules/grpc/src/node/extension_binary/node-v46-linux-x64-glibc" "--node_abi_napi=node-v46"

堆栈跟踪还有更多内容,但我认为这是要点。

Unable to verify the first certificate

在这里似乎相关。

我搜索了一下,找到了this,这似乎解决了我的问题。我修改了示例源代码,

examples/node/dynamic_codegen/greeter_server.js

所以它现在在现有文件的顶部添加了以下内容。

var rootCas = require('ssl-root-cas/latest').create();                                                                                                                                                             
rootCas                                                                                                                                                                                                            
   .addFile('/etc/pki/ca-trust/source/anchors/amrs-g2.cer');                                                                                                                                                        
require('https').globalAgent.options.ca = rootCas;    

试图遵循this 模式。我仍然看到同样的问题。 有人有想法么?我应该提到我正在运行 node 版本 4.5.0 和 npm 版本 2.15.9。

我尝试过修改版本,但无法正常工作。

编辑 1:

尝试将节点版本更新到 10.0.0 Npm 版本 5.6.0

再次尝试 npm install,这次出现了一个奇怪的错误...

npm install
npm ERR! code E418
npm ERR! 418 I'm a teapot: async@^1.5.2

编辑 2:

尝试一遍又一遍地运行命令,似乎它失败的库或多或少是随机的。

npm ERR! code E418
npm ERR! 418 I'm a teapot: grpc@^1.0.0
^C
[nbkiq0w@localhost node]$ npm install 
npm ERR! code E418
npm ERR! 418 I'm a teapot: google-protobuf@^3.0.0
^C
[nbkiq0w@localhost node]$ npm install 
npm ERR! code E418
npm ERR! 418 I'm a teapot: lodash@^4.6.1
^C
[nbkiq0w@localhost node]$ npm install 
npm ERR! code E418
npm ERR! 418 I'm a teapot: grpc@^1.0.0
^C
[nbkiq0w@localhost node]$ npm install 
npm ERR! code E418
npm ERR! 418 I'm a teapot: lodash@^4.6.1

似乎无论库如何,它都会失败,我尝试更新我的代理设置,如看到的here。似乎没有帮助。

编辑3:

切换回节点 6.12.0,并看到原始 tls 错误。我的一个朋友能够按原样下载节点目录,并在他的机器上运行(使用 6.12.0),所以它必须是与我的机器隔离的东西。

【问题讨论】:

  • 修改源代码在这里没有帮助。这是由于某种原因无法下载预编译的二进制文件后回退到编译 grpc 库时发生的安装时间故障。我不知道为什么会发生这种情况,但是您使用的是非常旧版本的 Node.js 可能无济于事。我的第一个故障排除建议是升级到较新的。
  • 升级到节点 10.0.0,npm 版本 5.6.0,现在我收到一个奇怪的错误消息,见上文
  • 新错误似乎是这样的:github.com/npm/npm/issues/20791。我以为他们修好了,所以我不知道你为什么现在看到它。

标签: node.js npm https ssl-certificate grpc


【解决方案1】:

我在另一个页面上找到了一些建议来调整在我的主目录中找到的 .npmrc 文件。我添加了以下行

cafile=<my cert file>

npm install 成功了。我不确定为什么我朋友的安装成功了,因为他甚至没有这个文件,但目前这已经足够了。

【讨论】:

    猜你喜欢
    • 2021-06-15
    • 1970-01-01
    • 2021-10-20
    • 2021-01-02
    • 2020-02-17
    • 2021-03-26
    • 1970-01-01
    • 2018-08-29
    • 2020-03-29
    相关资源
    最近更新 更多