icert2pem.sh 657 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. usage() {
  4. cat <<EOF
  5. Converts an Intel certificate from DER encoding to PEM encoding, writing the
  6. result to stdout.
  7. Usage: $0 [options] FILE
  8. Options:
  9. -h print this help text.
  10. EOF
  11. exit 0
  12. }
  13. while getopts ":h" opt; do
  14. case $opt in
  15. h)
  16. usage
  17. ;;
  18. \?)
  19. echo "Invalid option: -$OPTARG" >&2
  20. exit 1
  21. ;;
  22. esac
  23. done
  24. if [ "$#" -ne 1 ]; then
  25. (>&2 echo "Error: expected 1 certificate file parameter, got: $#")
  26. exit 1
  27. fi
  28. sed 's/-/+/g;s/_/\//g;s/%3D/=/g;s/^{.*certificate":"//g;s/"}$//g;' $1 |
  29. base64 --decode |
  30. openssl x509 -inform DER -outform PEM
  31. exit 0