My node.js https client always works regardless of certificate validity

后端 未结 4 917
再見小時候
再見小時候 2020-12-09 23:22

This test program connects to an https server and gets some content. I\'ve checked my server in browsers and with curl and the certificate is working correctly. If I run cur

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 23:26

    In order to make this work I needed to upgrade to v0.7.8 (although any v0.7 should be fine) where the rejectUnauthorized functionality has been added to https.get

    This combination of options is needed:

    agent: false, // or you can supply your own agent, but if you don't you must set to false
    rejectUnauthorized: true, 
    ca: [ fs.readFileSync('https_simple/cacert.pem') ]
    

    Now if the authentication fails you will get an 'error' event and the request will not go ahead.

    See the https.request documentation for details on making your own Agent

    The bug fix was committed in this change: https://github.com/joyent/node/commit/f8c335d0

提交回复
热议问题