gencerts.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. openssl x509 -in ca.crt -noout -text
  13. # generate DNS: localhost, IP: 127.0.0.1, CN: example.com certificates
  14. cfssl gencert \
  15. --ca ./ca.crt \
  16. --ca-key ./ca-key.pem \
  17. --config ./gencert.json \
  18. ./server-ca-csr.json | cfssljson --bare ./server
  19. mv server.pem server.crt
  20. mv server-key.pem server.key.insecure
  21. # generate IPv6: [::1], CN: example.com certificates
  22. cfssl gencert \
  23. --ca ./ca.crt \
  24. --ca-key ./ca-key.pem \
  25. --config ./gencert.json \
  26. ./server-ca-csr-ipv6.json | cfssljson --bare ./server-ip
  27. mv server-ip.pem server-ipv6.crt
  28. mv server-ip-key.pem server-ipv6.key.insecure
  29. # generate DNS: localhost, IP: 127.0.0.1, CN: example2.com certificates
  30. cfssl gencert \
  31. --ca ./ca.crt \
  32. --ca-key ./ca-key.pem \
  33. --config ./gencert.json \
  34. ./server-ca-csr2.json | cfssljson --bare ./server2
  35. mv server2.pem server2.crt
  36. mv server2-key.pem server2.key.insecure
  37. # generate revoked certificates and crl
  38. cfssl gencert --ca ./ca.crt \
  39. --ca-key ./ca-key.pem \
  40. --config ./gencert.json \
  41. ./server-ca-csr.json 2>revoked.stderr | cfssljson --bare ./server-revoked
  42. mv server-revoked.pem server-revoked.crt
  43. mv server-revoked-key.pem server-revoked.key.insecure
  44. grep serial revoked.stderr | awk ' { print $9 } ' >revoke.txt
  45. cfssl gencrl revoke.txt ca.crt ca-key.pem | base64 --decode >revoke.crl
  46. # generate wildcard certificates DNS: *.etcd.local
  47. cfssl gencert \
  48. --ca ./ca.crt \
  49. --ca-key ./ca-key.pem \
  50. --config ./gencert.json \
  51. ./server-ca-csr-wildcard.json | cfssljson --bare ./server-wildcard
  52. mv server-wildcard.pem server-wildcard.crt
  53. mv server-wildcard-key.pem server-wildcard.key.insecure
  54. rm -f *.csr *.pem *.stderr *.txt