cert-chain-check.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # This Works is placed under the terms of the Copyright Less License,
  3. # see file COPYRIGHT.CLL. USE AT OWN RISK, ABSOLUTELY NO WARRANTY.
  4. #
  5. # COPYRIGHT.CLL can be found at http://permalink.de/tino/cll
  6. # (CLL is CC0 as long as not covered by any Copyright)
  7. OOPS() { echo "OOPS: $*" >&2; exit 23; }
  8. [ -z "`pidof openssl`" ] || OOPS "openssl running, consider: killall openssl"
  9. PID=
  10. kick() { [ -n "$PID" ] && kill "$PID" && sleep .2; PID=; }
  11. trap 'kick' 0
  12. serve()
  13. {
  14. kick
  15. PID=
  16. openssl s_server -key "$KEY" -cert "$CRT" "$@" -www &
  17. PID=$!
  18. sleep .5 # give it time to startup
  19. }
  20. check()
  21. {
  22. while read -r line
  23. do
  24. case "$line" in
  25. 'Verify return code: 0 (ok)') return 0;;
  26. 'Verify return code: '*) return 1;;
  27. # *) echo "::: $line :::";;
  28. esac
  29. done < <(echo | openssl s_client -verify 8 -CApath /etc/ssl/certs/)
  30. OOPS "Something failed, verification output not found!"
  31. return 2
  32. }
  33. ARG="${1%.}"
  34. KEY="$ARG.key"
  35. CRT="$ARG.crt"
  36. BND="$ARG.bundle"
  37. for a in "$KEY" "$CRT" "$BND"
  38. do
  39. [ -s "$a" ] || OOPS "missing $a"
  40. done
  41. serve
  42. check && echo "!!! =========> CA-Bundle is not needed! <========"
  43. echo
  44. serve -CAfile "$BND"
  45. check
  46. ret=$?
  47. kick
  48. echo
  49. case $ret in
  50. 0) echo "EVERYTHING OK"
  51. echo "SSLCertificateKeyFile $KEY"
  52. echo "SSLCertificateFile $CRT"
  53. echo "SSLCACertificateFile $BND"
  54. ;;
  55. *) echo "!!! =========> something is wrong, verification failed! <======== ($ret)";;
  56. esac
  57. exit $ret