marsigning_check.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 SIGNMAR point to your signmar binary
  33. # 2) Let LD_LIBRARY_PATH point to the mar-tools directory
  34. # 3) Change into the directory containing the MAR files and the
  35. # sha256sums-unsigned-build.txt/sha256sums-unsigned-build.incrementals.txt.
  36. # 4) Run /path/to/marsigning_check.sh
  37. if [ -z "$SIGNMAR" ]
  38. then
  39. echo "The path to your signmar binary is missing!"
  40. exit 1
  41. fi
  42. if [ -z "$LD_LIBRARY_PATH" ]
  43. then
  44. echo "The library search path to your mar-tools directory is missing!"
  45. exit 1
  46. fi
  47. UNSIGNED_MARS=0
  48. BADSIGNED_MARS=0
  49. mkdir tmp
  50. for f in `ls *.mar`; do
  51. case $f in
  52. *.incremental.mar) SHA256_TXT=`grep "$f" \
  53. sha256sums-unsigned-build.incrementals.txt`;;
  54. *) SHA256_TXT=`grep "$f" sha256sums-unsigned-build.txt`;;
  55. esac
  56. # Test 1: Is the .mar file still unsigned? I.e. does its SHA-256 sum still
  57. # match the one we had before we signed it? If so, notify us later and exit.
  58. if [ "$SHA256_TXT" = "`sha256sum $f`" ]
  59. then
  60. echo "$f has still the SHA-256 sum of the unsigned MAR file!"
  61. UNSIGNED_MARS=`expr $UNSIGNED_MARS + 1`
  62. fi
  63. # Test 2: Do we get the old SHA-256 sum after stripping the MAR signature? If
  64. # not, notify us later and exit.
  65. if [ "$UNSIGNED_MARS" = "0" ]
  66. then
  67. # At least we seem to have attempted to sign the MAR file. Let's see if we
  68. # succeeded by stripping the signature. This behavior is reproducible.
  69. # Thus, we know if we don't get the same SHA-256 sum we did not sign the
  70. # bundle correctly.
  71. echo "Trying to strip the MAR signature of $f..."
  72. ${SIGNMAR} -r $f tmp/$f
  73. cd tmp
  74. if ! [ "$SHA256_TXT" = "`sha256sum $f`" ]
  75. then
  76. echo "$f does not have the SHA-256 sum of the unsigned MAR file!"
  77. BADSIGNED_MARS=`expr $BADSIGNED_MARS + 1`
  78. fi
  79. rm $f
  80. cd ..
  81. fi
  82. done
  83. rm -rf tmp/
  84. if ! [ "$UNSIGNED_MARS" = "0" ]
  85. then
  86. echo "We got $UNSIGNED_MARS unsigned MAR file(s), exiting..."
  87. exit 1
  88. fi
  89. if ! [ "$BADSIGNED_MARS" = "0" ]
  90. then
  91. echo "We got $BADSIGNED_MARS badly signed MAR file(s), exiting..."
  92. exit 1
  93. fi
  94. echo "The signatures are fine."
  95. exit 0