generate_testing_certs.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. #
  3. # This script is used to generate all cert related files for etcd testing.
  4. # location for temporary depot
  5. depot=".depot"
  6. # The passphrases for the keys are `asdf`.
  7. passphrase="--passphrase asdf"
  8. # etcd-ca could be found at github.com/coreos/etcd-ca
  9. if [ $# -eq 0 ]; then
  10. # try to find it through $GOPATH
  11. IFS=':' read -a paths <<< "${GOPATH}"
  12. for path in ${paths[@]}; do
  13. if [ -f "${path}/bin/etcd-ca" ]; then
  14. ca="${path}/bin/etcd-ca --depot-path $depot"
  15. break
  16. fi
  17. done
  18. if [ "$ca" == "" ]; then echo "Failed finding etcd-ca binary"; exit 1; fi
  19. else
  20. # treat the first argument as the path to etcd-ca binary
  21. ca="$1 --depot-path $depot"
  22. fi
  23. rm -rf $depot 2>/dev/null
  24. # create ca, which is assumed to be the broken one
  25. $ca init $passphrase
  26. # export out and rename files
  27. $ca export | tar xvf -
  28. mv ca.crt broken_ca.crt
  29. mv ca.key broken_ca.key
  30. # create certificate
  31. $ca new-cert $passphrase --ip 127.0.0.1 server
  32. $ca sign $passphrase server
  33. # export out and rename files
  34. $ca export --insecure $passphrase server | tar xvf -
  35. mv server.crt broken_server.crt
  36. mv server.key.insecure broken_server.key.insecure
  37. rm -rf $depot 2>/dev/null
  38. # create ca
  39. $ca init $passphrase
  40. $ca export | tar xvf -
  41. # create certificate for server
  42. $ca new-cert $passphrase --ip 127.0.0.1 server
  43. $ca sign $passphrase server
  44. $ca export --insecure $passphrase server | tar xvf -
  45. $ca chain server > server-chain.pem
  46. # create certificate for server2
  47. $ca new-cert $passphrase --ip 127.0.0.1 server2
  48. $ca sign $passphrase server2
  49. $ca export --insecure $passphrase server2 | tar xvf -
  50. rm -rf $depot 2>/dev/null