How do I use a self signed certificate for a HTTPS Node.js server?

前端 未结 5 1123
别那么骄傲
别那么骄傲 2020-11-28 19:16

I have started writing a wrapper for an API which requires all requests to be over HTTPS. Instead of making requests to the actual API while I am developing and testing it I

5条回答
  •  借酒劲吻你
    2020-11-28 19:30

    This procedure allows you to create both a certificate authority & a certificate :

    1. grab this ca.cnf file to use as a configuration shortcut :

      wget https://raw.githubusercontent.com/anders94/https-authorized-clients/master/keys/ca.cnf


    1. create a new certificate authority using this configuration :

      openssl req -new -x509 -days 9999 -config ca.cnf -keyout ca-key.pem -out ca-cert.pem


    1. now that we have our certificate authority in ca-key.pem and ca-cert.pem, let's generate a private key for the server :

      openssl genrsa -out key.pem 4096


    1. grab this server.cnf file to use as a configuration shortcut :

      wget https://raw.githubusercontent.com/anders94/https-authorized-clients/master/keys/server.cnf


    1. generate the certificate signing request using this configuration :

      openssl req -new -config server.cnf -key key.pem -out csr.pem


    1. sign the request :

      openssl x509 -req -extfile server.cnf -days 999 -passin "pass:password" -in csr.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem

    I found this procedure here, along with more information on how to use these certificates.

提交回复
热议问题