gencerts.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 revoked certificates and crl
  22. cfssl gencert --ca ./ca.crt \
  23. --ca-key ./ca-key.pem \
  24. --config ./gencert.json \
  25. ./server-ca-csr.json 2>revoked.stderr | cfssljson --bare ./server-revoked
  26. mv server-revoked.pem server-revoked.crt
  27. mv server-revoked-key.pem server-revoked.key.insecure
  28. grep serial revoked.stderr | awk ' { print $9 } ' >revoke.txt
  29. cfssl gencrl revoke.txt ca.crt ca-key.pem | base64 -d >revoke.crl
  30. # generate wildcard certificates DNS: *.etcd.local
  31. cfssl gencert \
  32. --ca ./ca.crt \
  33. --ca-key ./ca-key.pem \
  34. --config ./gencert.json \
  35. ./server-ca-csr-wildcard.json | cfssljson --bare ./server-wildcard
  36. mv server-wildcard.pem server-wildcard.crt
  37. mv server-wildcard-key.pem server-wildcard.key.insecure
  38. rm -f *.csr *.pem *.stderr *.txt