guix-authenticate.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test the 'guix authenticate' command-line utility.
  20. #
  21. guix authenticate --version
  22. sig="t-signature-$$"
  23. hash="t-hash-$$"
  24. rm -f "$sig" "$hash"
  25. trap 'rm -f "$sig" "$hash"' EXIT
  26. # A hexadecimal string as long as a sha256 hash.
  27. echo "2749f0ea9f26c6c7be746a9cff8fa4c2f2a02b000070dba78429e9a11f87c6eb" \
  28. > "$hash"
  29. guix authenticate rsautl -sign \
  30. -inkey "$abs_top_srcdir/tests/signing-key.sec" \
  31. -in "$hash" > "$sig"
  32. test -f "$sig"
  33. hash2="`guix authenticate rsautl -verify \
  34. -inkey $abs_top_srcdir/tests/signing-key.pub \
  35. -pubin -in $sig`"
  36. test "$hash2" = `cat "$hash"`
  37. # Same thing in a pipeline, using the command line syntax that Nix/Crypto.pm
  38. # uses.
  39. hash2="` \
  40. cat "$hash" \
  41. | guix authenticate rsautl -sign \
  42. -inkey "$abs_top_srcdir/tests/signing-key.sec" \
  43. | guix authenticate rsautl -verify \
  44. -inkey $abs_top_srcdir/tests/signing-key.pub \
  45. -pubin`"
  46. test "$hash2" = `cat "$hash"`
  47. # Detect corrupt signatures.
  48. if guix authenticate rsautl -verify \
  49. -inkey "$abs_top_srcdir/tests/signing-key.pub" \
  50. -pubin -in /dev/null
  51. then false
  52. else true
  53. fi
  54. # Detect invalid signatures.
  55. # The signature has (payload (data ... (hash sha256 #...#))). We proceed by
  56. # modifying this hash.
  57. sed -i "$sig" \
  58. -e's|#[A-Z0-9]\{64\}#|#0000000000000000000000000000000000000000000000000000000000000000#|g'
  59. if guix authenticate rsautl -verify \
  60. -inkey "$abs_top_srcdir/tests/signing-key.pub" \
  61. -pubin -in "$sig"
  62. then false
  63. else true
  64. fi
  65. # Test for <http://bugs.gnu.org/17312>: make sure 'guix authenticate' produces
  66. # valid signatures when run in the C locale.
  67. echo "5eff0b55c9c5f5e87b4e34cd60a2d5654ca1eb78c7b3c67c3179fed1cff07b4c" \
  68. > "$hash"
  69. LC_ALL=C
  70. export LC_ALL
  71. guix authenticate rsautl -sign \
  72. -inkey "$abs_top_srcdir/tests/signing-key.sec" \
  73. -in "$hash" > "$sig"
  74. guix authenticate rsautl -verify \
  75. -inkey "$abs_top_srcdir/tests/signing-key.pub" \
  76. -pubin -in "$sig"
  77. hash2="`guix authenticate rsautl -verify \
  78. -inkey $abs_top_srcdir/tests/signing-key.pub \
  79. -pubin -in $sig`"
  80. test "$hash2" = `cat "$hash"`