genKeyCert.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. sslDir=ssl
  3. clients=3
  4. mkdir -p $sslDir
  5. cd $sslDir
  6. if [ "$(ls -A)" ]; then
  7. echo "The directory $sslDir is not empty. Save and remove everything in the $sslDir folder."
  8. echo "Aborting ..."
  9. exit
  10. fi
  11. # CA private key and certificate
  12. echo "Creating CA private key and self signed CA certificate:"
  13. openssl genrsa -out ca_key.pem
  14. openssl req -new -key ca_key.pem -subj '/O=TraCINg CA/' -out ca.csr
  15. openssl x509 -req -days 3 -in ca.csr -signkey ca_key.pem -out ca_cert.pem
  16. rm ca.csr
  17. echo
  18. genKeyCert() {
  19. echo "Creating private key and CA signed certificate of $1"
  20. openssl genrsa -out ${1}_key.pem
  21. openssl req -new -key ${1}_key.pem -subj "/O=TraCINg/OU=Test/CN=$1" -out $1.csr
  22. openssl x509 -req -days 3 -in $1.csr -CA ca_cert.pem -CAkey ca_key.pem -CAcreateserial -out ${1}_cert.pem
  23. rm $1.csr
  24. echo
  25. }
  26. # Server private key and certificate
  27. genKeyCert server
  28. # Simulator private key and certificate
  29. genKeyCert simulator
  30. mkdir -p simulator
  31. mv simulator_* simulator
  32. # Client private key and certificate
  33. for ((i=0;i<$clients;i++))
  34. do
  35. genKeyCert client_$i
  36. done
  37. mkdir -p clients
  38. mv client_* clients