How to add custom certificate authority (CA) to nodejs

前端 未结 5 1078
失恋的感觉
失恋的感觉 2020-11-29 02:03

I\'m using a CLI tool to build hybrid mobile apps which has a cool upload feature so I can test the app on a device without going through the app store (it\'s ionic-cli). Ho

5条回答
  •  暖寄归人
    2020-11-29 02:37

    I'm aware of two npm modules that handle this problem when you control the app:

    1. https://github.com/capriza/syswide-cas (I'm the author of this one)
    2. https://github.com/coolaj86/node-ssl-root-cas

    node-ssl-root-cas bundles it's own copies of nodes root CAs and also enables adding your own CAs to trust. It places the certs on the https global agent, so it will only be used for https module, not pure tls connections. Also, you will need extra steps if you use a custom Agent instead of the global agent.

    syswide-cas loads certificates from pre-defined directories (such as /etc/ssl/certs) and uses node internal API to add them to the trusted list of CAs in conjunction to the bundled root CAs. There is no need to use the ca option since it makes the change globally which affects all later TLS calls automatically. It's also possible to add CAs from other directories/files if needed. It was verified to work with node 0.10, node 5 and node 6.

    Since you do not control the app you can create a wrapper script to enable syswide-cas (or node-ssl-root-cas) and then require the ionic-cli script:

    require('syswide-cas'); // this adds your custom CAs in addition to bundled CAs
    require('./path/to/real/script'); // this runs the actual script
    

提交回复
热议问题