create_self-signed.sh 762 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. if [ -z "$1" ]
  3. then
  4. echo "Generates a self-signed DER certificate for localhost\n"
  5. echo "usage ./create_self-signed.sh <output directory>"
  6. exit 1
  7. fi
  8. #cd in the directory where script is located
  9. cd "$(dirname "$0")"
  10. openssl req \
  11. -new \
  12. -newkey rsa:1024 \
  13. -nodes \
  14. -subj "/C=DE/ST=/L=/O=open62541/CN=www.open62541.org" \
  15. -config localhost.cnf \
  16. -keyout localhost.key \
  17. -out localhost.csr
  18. openssl x509 -req \
  19. -days 3650 \
  20. -in localhost.csr \
  21. -signkey localhost.key \
  22. -out localhost.crt \
  23. -extensions v3_req \
  24. -extfile localhost.cnf
  25. openssl x509 -in localhost.crt -outform der -out localhost.der
  26. rm localhost.key #we will need it later
  27. rm localhost.crt
  28. rm localhost.csr
  29. if [ -n "$1" ]
  30. then
  31. mv localhost.der $1
  32. fi