gencerts.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. set -e
  3. if ! [[ "$0" =~ "./gencerts.sh" ]]; then
  4. echo "must be run from 'fixtures-expired'"
  5. exit 255
  6. fi
  7. if which cfssl >/dev/null; then
  8. echo "cfssl is installed; generating certs"
  9. else
  10. echo "cfssl is not installed; exiting"
  11. exit 255
  12. fi
  13. cat > ./etcd-root-ca-csr.json <<EOF
  14. {
  15. "key": {
  16. "algo": "rsa",
  17. "size": 4096
  18. },
  19. "names": [
  20. {
  21. "O": "etcd",
  22. "OU": "etcd Security",
  23. "L": "San Francisco",
  24. "ST": "California",
  25. "C": "USA"
  26. }
  27. ],
  28. "CN": "etcd-root-ca",
  29. "ca": {
  30. "expiry": "1h"
  31. }
  32. }
  33. EOF
  34. cfssl gencert --initca=true ./etcd-root-ca-csr.json | cfssljson --bare ./etcd-root-ca
  35. cat > ./etcd-gencert.json <<EOF
  36. {
  37. "signing": {
  38. "default": {
  39. "usages": [
  40. "signing",
  41. "key encipherment",
  42. "server auth",
  43. "client auth"
  44. ],
  45. "expiry": "1h"
  46. }
  47. }
  48. }
  49. EOF
  50. cat > ./server-ca-csr.json <<EOF
  51. {
  52. "key": {
  53. "algo": "rsa",
  54. "size": 4096
  55. },
  56. "names": [
  57. {
  58. "O": "etcd",
  59. "OU": "etcd Security",
  60. "L": "San Francisco",
  61. "ST": "California",
  62. "C": "USA"
  63. }
  64. ],
  65. "CN": "example.com",
  66. "hosts": [
  67. "127.0.0.1",
  68. "localhost"
  69. ]
  70. }
  71. EOF
  72. cfssl gencert \
  73. --ca ./etcd-root-ca.pem \
  74. --ca-key ./etcd-root-ca-key.pem \
  75. --config ./etcd-gencert.json \
  76. ./server-ca-csr.json | cfssljson --bare ./server
  77. rm ./*.json
  78. rm ./*.csr
  79. if which openssl >/dev/null; then
  80. openssl x509 -in ./etcd-root-ca.pem -text -noout
  81. openssl x509 -in ./server.pem -text -noout
  82. fi