authenticode_check.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # Copyright (c) 2019, The Tor Project, Inc.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. #
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. #
  16. # * Neither the names of the copyright owners nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. # Usage:
  32. # 1) Let OSSLSIGNCODE point to your osslsigncode binary
  33. # 2) Change into the directory containing the .exe files and the sha256sums-unsigned-build.txt
  34. # 3) Run /path/to/authenticode_check.sh
  35. if [ -z "$OSSLSIGNCODE" ]
  36. then
  37. echo "The path to your osslsigncode binary is missing!"
  38. exit 1
  39. fi
  40. UNSIGNED_BUNDLES=0
  41. BADSIGNED_BUNDLES=0
  42. mkdir tmp
  43. for f in `ls *.exe`; do
  44. SHA256_TXT=`grep "$f" sha256sums-unsigned-build.txt`
  45. # Test 1: Is the .exe file still unsigned? I.e. does its SHA-256 sum still
  46. # match the one we had before we signed the .exe file? If so, notify us
  47. # later and exit.
  48. if [ "$SHA256_TXT" = "`sha256sum $f`" ]
  49. then
  50. echo "$f has still the SHA-256 sum of the unsigned bundle!"
  51. UNSIGNED_BUNDLES=`expr $UNSIGNED_BUNDLES + 1`
  52. fi
  53. # Test 2: Do we get the old SHA-256 sum after stripping the authenticode
  54. # signature? If not, notify us later and exit.
  55. if [ "$UNSIGNED_BUNDLES" = "0" ]
  56. then
  57. # At least we seem to have attempted to sign the bundle. Let's see if we
  58. # succeeded by stripping the signature. This behavior is reproducible.
  59. # Thus, we know if we don't get the same SHA-256 sum we did not sign the
  60. # bundle correctly.
  61. echo "Trying to strip the authenticode signature of $f..."
  62. ${OSSLSIGNCODE} remove-signature $f tmp/$f
  63. cd tmp
  64. if ! [ "$SHA256_TXT" = "`sha256sum $f`" ]
  65. then
  66. echo "$f does not have the SHA-256 sum of the unsigned bundle!"
  67. BADSIGNED_BUNDLES=`expr $BADSIGNED_BUNDLES + 1`
  68. fi
  69. rm $f
  70. cd ..
  71. fi
  72. done
  73. rm -rf tmp/
  74. if ! [ "$UNSIGNED_BUNDLES" = "0" ]
  75. then
  76. echo "We got $UNSIGNED_BUNDLES unsigned bundle(s), exiting..."
  77. exit 1
  78. fi
  79. if ! [ "$BADSIGNED_BUNDLES" = "0" ]
  80. then
  81. echo "We got $BADSIGNED_BUNDLES badly signed bundle(s), exiting..."
  82. exit 1
  83. fi
  84. echo "The signatures are fine."
  85. exit 0