1
0

jose-jws-sig 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh -ex
  2. ALGS=`jose alg -k sign`
  3. tmpdir=`mktemp -d 2>/dev/null || mktemp -d -t jose`
  4. onexit() {
  5. rm -rf $tmpdir
  6. }
  7. trap onexit EXIT
  8. msg=$tmpdir/msg.txt
  9. printf "hi" > $msg
  10. for a in $ALGS; do
  11. jwk=$tmpdir/$a.jwk
  12. jws=$tmpdir/$a.jws
  13. jose jwk gen -i "{\"alg\":\"$a\"}" -o $jwk
  14. jose jwk pub -i $jwk -o $jwk.pub
  15. old=$prv
  16. prv=$jwk
  17. done
  18. for a in $ALGS; do
  19. jwk=$tmpdir/$a.jwk
  20. jws=$tmpdir/$a.jws
  21. printf "hi" | jose jws sig -I- -k $jwk | jose jws ver -i- -k $jwk
  22. printf "hi" | jose jws sig -I- -k $jwk -c | jose jws ver -i- -k $jwk
  23. jose jws sig -o $jws -k $jwk -I $msg
  24. jose jws ver -i $jws -k $jwk
  25. rm -f $jws
  26. jose jws sig -o $jws -k $jwk -I $msg -c
  27. jose jws ver -i $jws -k $jwk
  28. rm -f $jws
  29. det=`jose jws sig -I $msg -k $jwk -o /dev/null -O-`
  30. [ "$det" = "hi" ]
  31. jws=`jose jws sig -I $msg -k $jwk -O /dev/null`
  32. ! jose jws ver -i "$jws" -k $jwk
  33. det=`jose jws ver -i "$jws" -k $jwk -I $msg -O-`
  34. [ "$det" = "hi" ]
  35. jws=`jose jws sig -I $msg -k $jwk`
  36. det=`jose jws ver -i "$jws" -k $jwk`
  37. [ "$det" = "" ]
  38. det=`jose jws ver -i "$jws" -k $jwk -O-`
  39. [ "$det" = "hi" ]
  40. jws=`jose jws sig -I $msg -k $jwk -c`
  41. det=`jose jws ver -i "$jws" -k $jwk`
  42. [ "$det" = "" ]
  43. det=`jose jws ver -i "$jws" -k $jwk -O-`
  44. [ "$det" = "hi" ]
  45. jws=`jose jws sig -k $jwk -I $msg -s "{\"protected\":{\"alg\":\"$a\"}}"`
  46. jose jws ver -i "$jws" -k $jwk
  47. jws=`jose jws sig -k $jwk -i "{\"payload\":\"aGkK\"}"`
  48. jose jws ver -i "$jws" -k $jwk
  49. for b in $ALGS; do
  50. [ $a = $b ] && continue
  51. ! jose jws sig -I $msg -k $jwk -s "{\"protected\":{\"alg\":\"$b\"}}"
  52. jws=`jose jws sig -I $msg -k $jwk`
  53. ! jose jws ver -i "$jws" -k $tmpdir/$b.jwk
  54. done
  55. jws=`jose jws sig -I $msg -k $jwk -k $prv`
  56. jose jws ver -i "$jws" -k $jwk
  57. jose jws ver -i "$jws" -k $prv
  58. ! jose jws ver -i "$jws" -k $old
  59. jose jws ver -i "$jws" -k $jwk -k $prv -a
  60. ! jose jws ver -i "$jws" -k $jwk -k $prv -k $old -a
  61. old=$prv
  62. prv=$jwk
  63. done
  64. for tmpl in '{"kty":"oct","bytes":32}' '{"kty":"RSA","bits":2048}' '{"kty":"EC","crv":"P-256"}'; do
  65. jose jwk gen -i "$tmpl" -o $tmpdir/jwk
  66. printf '%s' "$msg" | jose jws sig -I- -k $tmpdir/jwk -o $tmpdir/jws
  67. [ "`jose jws ver -i $tmpdir/jws -k $tmpdir/jwk -O-`" = "$msg" ]
  68. done