ssl-verifier.sh 856 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. KEY=$1
  3. CRT=$2
  4. IMM=$3
  5. if [ "`cat $KEY | grep ENCRYPTED`" ]; then
  6. echo >&2 "Key is password-protected"
  7. exit 1
  8. fi
  9. KEYMOD=`openssl rsa -noout -modulus -in $KEY`
  10. CRTMOD=`openssl x509 -noout -modulus -in $CRT`
  11. if [ "$KEYMOD" != "$CRTMOD" ]; then
  12. echo >&2 "Key doesn't match the certificate"
  13. exit 1
  14. fi
  15. if [ -n "$IMM" ]; then
  16. cat $CRT $IMM > bundle.crt
  17. if [ "`openssl verify bundle.crt`" == "$CRT: OK" ]; then
  18. echo "Done (bundle ok)"
  19. exit 0
  20. fi
  21. fi
  22. while true; do
  23. if [ "`openssl verify $CRT`" == "$CRT: OK" ]; then
  24. echo "Done"
  25. exit 0
  26. fi
  27. NEXT=`openssl x509 -noout -issuer_hash -in $CRT`
  28. if [ ! -f $NEXT ]; then
  29. echo >&2 "Could not generate trusted bundle"
  30. exit 1
  31. fi
  32. cat $CRT $NEXT > tmp.crt
  33. mv tmp.crt bundle.crt
  34. CRT="bundle.crt"
  35. done