cert.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # ./cert.sh foo@foo.com 127.0.0.1
  3. # Found: https://gist.github.com/ncw/9253562#file-makecert-sh
  4. if [ "$1" == "" ]; then
  5. echo "Need email as argument"
  6. exit 1
  7. fi
  8. if [ "$2" == "" ]; then
  9. echo "Need CN as argument"
  10. exit 1
  11. fi
  12. PRIVKEY="test"
  13. EMAIL=$1
  14. CN=$2
  15. rm -rf tmp
  16. mkdir tmp
  17. cd tmp
  18. echo "make CA"
  19. openssl req -new -x509 -days 3650 -keyout ca.key -out ca.pem \
  20. -config ../openssl.conf -extensions ca \
  21. -subj "/CN=ca" \
  22. -passout pass:$PRIVKEY
  23. echo "make server cert"
  24. openssl genrsa -out server.key 2048
  25. openssl req -new -sha256 -key server.key -out server.req \
  26. -subj "/emailAddress=${EMAIL}/C=DE/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=${CN}"
  27. openssl x509 -req -days 3650 -sha256 -in server.req -CA ca.pem -CAkey ca.key -CAcreateserial -passin pass:$PRIVKEY -out server.pem \
  28. -extfile ../openssl.conf -extensions server
  29. echo "make client cert"
  30. openssl genrsa -out client.key 2048
  31. openssl req -new -sha256 -key client.key -out client.req \
  32. -subj "/emailAddress=${EMAIL}/C=DE/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=${CN}"
  33. openssl x509 -req -days 3650 -sha256 -in client.req -CA ca.pem -CAkey ca.key -CAserial ca.srl -passin pass:$PRIVKEY -out client.pem \
  34. -extfile ../openssl.conf -extensions client
  35. cd ..
  36. mv tmp/* certs
  37. rm -rf tmp