gencerts.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. if ! [[ "$0" =~ "./gencerts.sh" ]]; then
  3. echo "must be run from 'fixtures'"
  4. exit 255
  5. fi
  6. if ! which cfssl; then
  7. echo "cfssl is not installed"
  8. exit 255
  9. fi
  10. cfssl gencert --initca=true ./ca-csr.json | cfssljson --bare ./ca
  11. mv ca.pem ca.crt
  12. if which openssl >/dev/null; then
  13. openssl x509 -in ca.crt -noout -text
  14. fi
  15. # generate DNS: localhost, IP: 127.0.0.1, CN: example.com certificates
  16. cfssl gencert \
  17. --ca ./ca.crt \
  18. --ca-key ./ca-key.pem \
  19. --config ./gencert.json \
  20. ./server-ca-csr.json | cfssljson --bare ./server
  21. mv server.pem server.crt
  22. mv server-key.pem server.key.insecure
  23. # generate DNS: localhost, IP: 127.0.0.1, CN: example.com certificates (ECDSA)
  24. cfssl gencert \
  25. --ca ./ca.crt \
  26. --ca-key ./ca-key.pem \
  27. --config ./gencert.json \
  28. ./server-ca-csr-ecdsa.json | cfssljson --bare ./server-ecdsa
  29. mv server-ecdsa.pem server-ecdsa.crt
  30. mv server-ecdsa-key.pem server-ecdsa.key.insecure
  31. # generate IP: 127.0.0.1, CN: example.com certificates
  32. cfssl gencert \
  33. --ca ./ca.crt \
  34. --ca-key ./ca-key.pem \
  35. --config ./gencert.json \
  36. ./server-ca-csr-ip.json | cfssljson --bare ./server-ip
  37. mv server-ip.pem server-ip.crt
  38. mv server-ip-key.pem server-ip.key.insecure
  39. # generate IPv6: [::1], CN: example.com certificates
  40. cfssl gencert \
  41. --ca ./ca.crt \
  42. --ca-key ./ca-key.pem \
  43. --config ./gencert.json \
  44. ./server-ca-csr-ipv6.json | cfssljson --bare ./server-ip
  45. mv server-ip.pem server-ipv6.crt
  46. mv server-ip-key.pem server-ipv6.key.insecure
  47. # generate DNS: localhost, IP: 127.0.0.1, CN: example2.com certificates
  48. cfssl gencert \
  49. --ca ./ca.crt \
  50. --ca-key ./ca-key.pem \
  51. --config ./gencert.json \
  52. ./server-ca-csr2.json | cfssljson --bare ./server2
  53. mv server2.pem server2.crt
  54. mv server2-key.pem server2.key.insecure
  55. # generate DNS: localhost, IP: 127.0.0.1, CN: "" certificates
  56. cfssl gencert \
  57. --ca ./ca.crt \
  58. --ca-key ./ca-key.pem \
  59. --config ./gencert.json \
  60. ./server-ca-csr3.json | cfssljson --bare ./server3
  61. mv server3.pem server3.crt
  62. mv server3-key.pem server3.key.insecure
  63. # generate revoked certificates and crl
  64. cfssl gencert --ca ./ca.crt \
  65. --ca-key ./ca-key.pem \
  66. --config ./gencert.json \
  67. ./server-ca-csr.json 2>revoked.stderr | cfssljson --bare ./server-revoked
  68. mv server-revoked.pem server-revoked.crt
  69. mv server-revoked-key.pem server-revoked.key.insecure
  70. grep serial revoked.stderr | awk ' { print $9 } ' >revoke.txt
  71. cfssl gencrl revoke.txt ca.crt ca-key.pem | base64 --decode >revoke.crl
  72. # generate wildcard certificates DNS: *.etcd.local
  73. cfssl gencert \
  74. --ca ./ca.crt \
  75. --ca-key ./ca-key.pem \
  76. --config ./gencert.json \
  77. ./server-ca-csr-wildcard.json | cfssljson --bare ./server-wildcard
  78. mv server-wildcard.pem server-wildcard.crt
  79. mv server-wildcard-key.pem server-wildcard.key.insecure
  80. rm -f *.csr *.pem *.stderr *.txt