setup-ssl-ca 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. # Generate a new local CA "/root/.local/share/mkcert"
  4. bin/docker-compose exec -T -u root app mkcert -install
  5. docker cp "$(bin/docker-compose ps -q app|awk '{print $1}')":/root/.local/share/mkcert/rootCA.pem .
  6. echo "System password requested to install certificate authority on host..."
  7. if [ "$(uname)" == "Darwin" ]; then
  8. sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
  9. echo "{\"policies\": {\"Certificates\": {\"ImportEnterpriseRoots\": true}}}" | sudo tee policies.json
  10. FIREFOX_FOUND=0
  11. ### Check if Firefox is installed
  12. for FFoxAppDir in \
  13. '/Applications/Firefox.app' \
  14. '/Applications/Firefox Developer Edition.app' \
  15. ; do
  16. FFoxBin=$FFoxAppDir/Contents/MacOS/firefox-bin
  17. if [[ -f $FFoxBin ]]; then
  18. printf 'Firefox compatible found at: %s\n' "$FFoxAppDir" >&2
  19. FIREFOX_FOUND=1
  20. ### Copy the newly created policies.json to the Certificates directory
  21. DistDirectory=$FFoxAppDir/Contents/Resources/distribution
  22. sudo mkdir -p "$DistDirectory"
  23. sudo cp policies.json "$DistDirectory"/policies.json
  24. fi
  25. done
  26. if [[ $FIREFOX_FOUND -ne 0 ]]; then
  27. ### Copy the newly created .pem to the Certificates directory
  28. CertDirectory='/Library/Application Support/Mozilla/Certificates'
  29. printf 'Installing CA certificate to: %s\n' "$CertDirectory" >&2
  30. sudo mkdir -p "$CertDirectory"
  31. sudo cp rootCA.pem "$CertDirectory"/rootCA.pem
  32. fi
  33. rm -f policies.json rootCA.pem
  34. else
  35. ### Requirement: apt install libnss3-tools
  36. REQUIRED_PKG="libnss3-tools"
  37. PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
  38. echo Checking for $REQUIRED_PKG: "$PKG_OK"
  39. if [ "" = "$PKG_OK" ]; then
  40. echo "No $REQUIRED_PKG found. Setting up $REQUIRED_PKG."
  41. sudo apt-get --yes install $REQUIRED_PKG
  42. fi
  43. ### CA file to install (CUSTOMIZE!)
  44. certfile="rootCA.pem"
  45. certname="Root CA"
  46. ### For cert8 (legacy - DBM)
  47. find ~/ -name "cert8.db" -print0 | while read -r certDB
  48. do
  49. certdir=$(dirname "${certDB}");
  50. certutil -D -n "${certname}" -i ${certfile} -d dbm:"${certdir}"
  51. certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d dbm:"${certdir}"
  52. done
  53. ### For cert9 (SQL)
  54. find ~/ -name "cert9.db" -print0 | while read -r certDB
  55. do
  56. certdir=$(dirname "${certDB}");
  57. certutil -D -n "${certname}" -i ${certfile} -d sql:"${certdir}"
  58. certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d sql:"${certdir}"
  59. done
  60. sudo mv rootCA.pem /usr/local/share/ca-certificates/rootCA.crt
  61. sudo update-ca-certificates
  62. fi