我正在寻找一种方法来添加一个自定义的CA到NPM,这样我就可以从一个位置下载使用上述证书(一个内部git服务器),而不必核所有的CA检查
npm config set strict-ssl false
有没有办法做到这一点?(如果没有:是否已经存在缺陷?)
发布于 2015-01-17 16:16:33
您可以将npm指向cafile
npm config set cafile /path/to/cert.pem
您也可以直接配置ca
字符串。
npm config set ca "cert string"
ca
也可以是证书字符串数组。在你的.npmrc
中
ca[]="cert 1 base64 string"
ca[]="cert 2 base64 string"
上面的npm config
命令会将相关配置项保存到您的~/.npmrc
文件中:
cafile=/path/to/cert.pem
npm注意:这些CA设置将覆盖使用的默认“真实世界”证书颁发机构查找。如果您尝试通过https使用任何未由您的CA证书签名的公共npm注册表,您将得到错误。
如果您既需要支持公共https npm注册中心,也需要支持您自己的注册中心,您可以使用curl's Mozilla based CA bundle并将CA证书附加到cacert.pem
文件:
curl https://curl.haxx.se/ca/cacert.pem > ~/.npm.certs.pem
cat my-ca-cert.pem >> ~/.npm.certs.pem
npm config set cafile ~/.npm.certs.pem
不幸的是,npm的CA包是不可编辑的,因为它是在source code (感谢tomekwi)中提供的,而是在nitzel has provided a generic Node.js method中通过NODE_EXTRA_CA_CERTS
环境变量附加一个证书。
如果你碰巧使用的是基于的发行版和打包的nodejs/npm,你可以使用标准的update-ca-trust
method,因为RedHat将它们的包指向系统CA。
发布于 2019-05-21 21:57:00
如果Matts Answer不能帮助你:
在Windows Powershell中,$env:NODE_EXTRA_CA_CERTS=path\to\certificate.pem; npm install
为我工作。
对于DOS/cmd (由Marc在注释中指出)
set NODE_EXTRA_CA_CERTS=C:\\path\\to\\certificate.pem
npm install
https://stackoverflow.com/questions/23788564
复制相似问题