1
0

jose-jws-sig 2.3 KB

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