marsigning_check.sh 3.5 KB

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