无法验证第一个证书(grpc / node)

时间:2018-06-04 20:26:09

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

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

我已将该文件夹下载到目录中,并尝试运行 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模式。我仍然看到同样的问题。 有人有主意吗?我应该提一下,我正在运行节点版本4.5.0和npm版本2.15.9。

我已经尝试过对这些版本进行一些处理,但无法使其正常工作。

编辑1:

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

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

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),因此它必须与我的机器隔离。

1 个答案:

答案 0 :(得分:0)

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

cafile=<my cert file>

npm安装工作正常。我不确定为什么我的朋友的安装工作,因为他甚至没有这个文件,但这暂时还不错。