code-sign-exe.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ###########################################################################
  2. # code-sign-exe.sh #
  3. # --------------------- #
  4. # Date : March 2017 #
  5. # Author : Larry Shaffer #
  6. # Copyright : (C) 2017 by Boundless Spatial #
  7. # Email : lshaffer at boundlessgeo dot com #
  8. ###########################################################################
  9. # #
  10. # This program is free software; you can redistribute it and/or modify #
  11. # it under the terms of the GNU General Public License as published by #
  12. # the Free Software Foundation; either version 2 of the License, or #
  13. # (at your option) any later version. #
  14. # #
  15. ###########################################################################
  16. # Code-sign .exe file using signtool and installed DigiCert code-signing
  17. # cert/key and CA
  18. #
  19. # Requirements:
  20. # MinGW / msys shell
  21. # Need Win SDK 7.0 or higher
  22. # Need internet connection
  23. # Install signing cert/key bundle into Machine (all users) cert store
  24. # Install any intermediate CA into Machine cert store,
  25. # as signtool will include it
  26. # Use /sm if signing cert was imported to Machine (not My) cert store
  27. # SHA1 signature of cert MUST be uppercase
  28. #
  29. # You can also use the DigiCert GUI-based utility:
  30. # https://www.digicert.com/util/
  31. # NOTE: utility only does SHA1 signing of exe, so not useful for Win 10+
  32. #
  33. # signtool docs, circa 2016:
  34. # https://msdn.microsoft.com/en-us/library/aa387764(v=vs.85).aspx
  35. # example signing using Machine cert store and sha256
  36. # signtool sign /sm /tr http://timestamp.digicert.com /td sha256 ^
  37. # /fd sha256 /sha1 UPPERCASESHA1SIGNTURE some.exe
  38. set -e
  39. # set -x
  40. USAGE () {
  41. echo "usage: $0 certhash some.exe"
  42. echo " certhash: signing cert SHA1 hash; must be UPPERCASE"
  43. echo " some.exe: path of .exe to sign"
  44. }
  45. if [ "$#" -ne 2 ]; then
  46. usage
  47. exit 1
  48. fi
  49. if [ -z $1 ] || [ -z $2 ]; then
  50. USAGE
  51. exit 1
  52. fi
  53. if ! [ -f $2 ]; then
  54. echo "exe file not found"
  55. exit 1
  56. fi
  57. if ! [[ $2 == *.exe ]]; then
  58. echo "extension not .exe"
  59. exit 1
  60. fi
  61. export PATH="/c/Program Files/Microsoft SDKs/Windows/v7.1/Bin":/usr/bin:$PATH
  62. # echo $1
  63. # echo $2
  64. signtool sign //sm //fd sha256 //sha1 $1 $2
  65. signtool timestamp //tr http://timestamp.digicert.com //td sha256 $2
  66. signtool verify //V //pa $2