authenticode_verify_timestamp.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. # Copyright (c) 2021, 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_verify_timestamp.sh
  35. if [ -z "$OSSLSIGNCODE" ]
  36. then
  37. echo "The path to your osslsigncode binary is missing!"
  38. exit 1
  39. fi
  40. #set -x
  41. VERIFIED_PACKAGES=0
  42. MISSING_TIMESTAMP=0
  43. for f in `ls *.exe`; do
  44. echo -n "$f timestamped: "
  45. ${OSSLSIGNCODE} extract-signature -pem -in $f -out $f.sigs 1>/dev/null
  46. ts=`openssl pkcs7 -print -in $f.sigs | grep -A 227 unauth_attr`
  47. ts_len=`openssl pkcs7 -print -in $f.sigs | grep -A 227 unauth_attr | wc -l`
  48. rm $f.sigs
  49. if [ $ts_len -ne 228 ]; then
  50. echo "timestamp format changed. Expected 228 lines, but received $ts_len"
  51. fi
  52. missing_attrs=0
  53. # Random selection. We can choose better ones later.
  54. for exp in "d=1 hl=2 l= 9 prim: OBJECT :pkcs7-signedData" \
  55. "d=4 hl=2 l= 11 prim: OBJECT :id-smime-ct-TSTInfo" \
  56. "d=9 hl=2 l= 40 prim: PRINTABLESTRING :DigiCert SHA2 Assured ID Timestamping CA" \
  57. "d=9 hl=2 l= 23 prim: PRINTABLESTRING :DigiCert Timestamp 2021" \
  58. "d=7 hl=2 l= 9 prim: OBJECT :signingTime"; do
  59. #echo "Checking '$exp'"
  60. if ! `echo $ts | grep -q "$exp"`; then
  61. missing_attrs=`expr $missing_attrs + 1`
  62. echo "no: missing attribute: $exp"
  63. fi
  64. done
  65. if [ $missing_attrs -ne 0 ]; then
  66. MISSING_TIMESTAMP=`expr $MISSING_TIMESTAMP + 1`
  67. else
  68. echo yes
  69. fi
  70. CHECKED_PACKAGES=`expr ${CHECKED_PACKAGES} + 1`
  71. done
  72. if [ "${MISSING_TIMESTAMP}" -ne 0 ]; then
  73. echo "${MISSING_TIMESTAMP} packages not timestamped."
  74. exit 1
  75. fi
  76. if [ "${CHECKED_PACKAGES}" -ne `ls *.exe | wc -l` ]; then
  77. echo "Some packages were not verified!."
  78. exit 1
  79. fi
  80. echo "Successfully verified are ${CHECKED_PACKAGES} timestamped"
  81. exit 0