adv 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash -x
  2. # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2016 Red Hat, Inc.
  5. # Author: Nathaniel McCallum <npmccallum@redhat.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. function on_exit() {
  21. if [ "$PID" ]; then kill $PID; wait $PID || true; fi
  22. [ -d "$TMP" ] && rm -rf $TMP
  23. }
  24. trap 'on_exit' EXIT
  25. trap 'exit' ERR
  26. export TMP=`mktemp -d`
  27. mkdir -p $TMP/db
  28. mkdir -p $TMP/cache
  29. tangd-keygen $TMP/db sig exc
  30. jose jwk gen -i '{"alg": "ES512"}' -o $TMP/db/.sig.jwk
  31. jose jwk gen -i '{"alg": "ES512"}' -o $TMP/db/.oth.jwk
  32. tangd-update $TMP/db $TMP/cache
  33. for addr in "127.0.0.1" "[::1]"; do
  34. port=`shuf -i 1024-65536 -n 1`
  35. $SD_ACTIVATE -l "$addr:$port" -a $VALGRIND tangd $TMP/cache &
  36. export PID=$!
  37. sleep 0.5
  38. # Make sure requests on the root fail
  39. ! curl -sfg http://$addr:$port/
  40. # The request should fail (404) for non-signature key IDs
  41. ! curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/exc.jwk`
  42. ! curl -sfg http://$addr:$port/adv/`jose jwk thp -a S512 -i $TMP/db/exc.jwk`
  43. # The default advertisement fetch should succeed and pass verification
  44. curl -sfg http://$addr:$port/adv
  45. curl -sfg http://$addr:$port/adv | jose jws ver -i- -k $TMP/db/sig.jwk
  46. curl -sfg http://$addr:$port/adv/ | jose jws ver -i- -k $TMP/db/sig.jwk
  47. # Fetching by any thumbprint should work
  48. curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/sig.jwk` | jose jws ver -i- -k $TMP/db/sig.jwk
  49. curl -sfg http://$addr:$port/adv/`jose jwk thp -a S512 -i $TMP/db/sig.jwk` | jose jws ver -i- -k $TMP/db/sig.jwk
  50. # Requesting an adv by an advertised key ID should't be signed by hidden keys
  51. ! curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/sig.jwk` | jose jws ver -i- -k $TMP/db/.sig.jwk
  52. ! curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/sig.jwk` | jose jws ver -i- -k $TMP/db/.oth.jwk
  53. # Verify that the default advertisement is not signed with hidden signature keys
  54. ! curl -sfg http://$addr:$port/adv/ | jose jws ver -i- -k $TMP/db/.oth.jwk
  55. ! curl -sfg http://$addr:$port/adv/ | jose jws ver -i- -k $TMP/db/.sig.jwk
  56. # A private key advertisement is signed by all advertised keys and the requested private key
  57. curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/.sig.jwk` | jose jws ver -i- -k $TMP/db/sig.jwk
  58. curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/.sig.jwk` | jose jws ver -i- -k $TMP/db/.sig.jwk
  59. ! curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/.sig.jwk` | jose jws ver -i- -k $TMP/db/.oth.jwk
  60. # Verify that the advertisements contain the cty parameter
  61. curl -sfg http://$addr:$port/adv \
  62. | jose fmt -j- -Og protected -SyOg cty -Sq "jwk-set+json" -E
  63. curl -sfg http://$addr:$port/adv/`jose jwk thp -i $TMP/db/.sig.jwk` \
  64. | jose fmt -j- -Og signatures -A \
  65. -g 0 -Og protected -SyOg cty -Sq "jwk-set+json" -EUUUUU \
  66. -g 1 -Og protected -SyOg cty -Sq "jwk-set+json" -EUUUUU
  67. kill $PID
  68. wait $PID || true
  69. unset PID
  70. done