create-ca.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. # Generates your own Certificate Authority for development.
  3. # This script should be executed just once.
  4. set -e
  5. if [ -f "ca.crt" ] || [ -f "ca.key" ]; then
  6. echo -e "\e[41mCertificate Authority files already exist!\e[49m"
  7. echo
  8. echo -e "You only need a single CA even if you need to create multiple certificates."
  9. echo -e "This way, you only ever have to import the certificate in your browser once."
  10. echo
  11. echo -e "If you want to restart from scratch, delete the \e[93mca.crt\e[39m and \e[93mca.key\e[39m files."
  12. exit
  13. fi
  14. # Generate private key
  15. openssl genrsa -out ca.key 2048
  16. # Generate root certificate
  17. openssl req -x509 -new -nodes -subj "/C=US/O=_Development CA/CN=Development certificates" -key ca.key -sha256 -days 3650 -out ca.crt
  18. echo -e "\e[42mSuccess!\e[49m"
  19. echo
  20. echo "The following files have been written:"
  21. echo -e " - \e[93mca.crt\e[39m is the public certificate that should be imported in your browser"
  22. echo -e " - \e[93mca.key\e[39m is the private key that will be used by \e[93mcreate-certificate.sh\e[39m"
  23. echo
  24. echo "Next steps:"
  25. echo -e " - Import \e[93mca.crt\e[39m in your browser"
  26. echo -e " - run \e[93mcreate-certificate.sh example.com\e[39m"