sign_installer.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. #
  3. # Script to sign the IDF Tools installer for Windows, built with build_installer.sh.
  4. #
  5. set -e
  6. set -u
  7. if [[ -z "${KEYFILE:-}" || -z "${CERTCHAIN:-}" ]]; then
  8. echo "To sign the installer, set the following environment variables:"
  9. echo " KEYFILE - private key file"
  10. echo " KEYPASSWORD - password for the private key file (optional, will prompt for password if not set)"
  11. echo " CERTCHAIN - certificate chain file"
  12. exit 1
  13. fi
  14. umask 770 # for the process substitution FIFO
  15. VERSION=`grep "#define MyAppVersion " idf_tool_setup.iss | cut -d ' ' -f3 | tr -d '"'`
  16. echo "Installer version ${VERSION}"
  17. IN_FILE="Output/esp-idf-tools-setup-unsigned.exe"
  18. OUT_FILE="Output/esp-idf-tools-setup-${VERSION}.exe"
  19. if [[ -n "${KEYPASSWORD:-}" ]]; then
  20. PASSARG="-readpass <(echo \"$KEYPASSWORD\")"
  21. else
  22. PASSARG="-askpass"
  23. fi
  24. echo "Signing the installer (${IN_FILE})..."
  25. # Note: The cert chain passed to -certs needs to contain the intermediate
  26. # cert(s) as well, appended after the code signing cert, or Windows may see
  27. # it as "Unknown Publisher"
  28. #
  29. # See https://stackoverflow.com/a/52637050 for full details
  30. #
  31. osslsigncode -certs ${CERTCHAIN} -key ${KEYFILE} \
  32. ${PASSARG} \
  33. -in ${IN_FILE} \
  34. -out ${OUT_FILE} \
  35. -h sha256 \
  36. -n "Espressif Systems (Shanghai) Co., Ltd." \
  37. -i "https://www.espressif.com/" \
  38. -ts http://timestamp.digicert.com
  39. chmod 644 ${OUT_FILE} # make up for the umask
  40. echo "Generated ${OUT_FILE}"