jose-jwk-exc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash -ex
  2. tmpdir=`mktemp -d 2>/dev/null || mktemp -d -t jose`
  3. function onexit() {
  4. rm -rf $tmpdir
  5. }
  6. trap exit ERR
  7. trap onexit EXIT
  8. for T in '{"alg":"ECDH"}' '{"alg":"ECDH","crv":"P-256"}' '{"kty":"EC","crv":"P-256"}'; do
  9. jose jwk gen -i "$T" -o $tmpdir/exc_a.jwk
  10. jose jwk gen -i "$T" -o $tmpdir/exc_b.jwk
  11. jose jwk pub -i $tmpdir/exc_a.jwk -o $tmpdir/exc_a.pub.jwk
  12. jose jwk pub -i $tmpdir/exc_b.jwk -o $tmpdir/exc_b.pub.jwk
  13. a=`jose jwk exc -l $tmpdir/exc_a.jwk -r $tmpdir/exc_b.pub.jwk`
  14. b=`jose jwk exc -l $tmpdir/exc_b.jwk -r $tmpdir/exc_a.pub.jwk`
  15. c=`jose jwk exc -l $tmpdir/exc_a.jwk -r $tmpdir/exc_b.jwk`
  16. d=`jose jwk exc -l $tmpdir/exc_b.jwk -r $tmpdir/exc_a.jwk`
  17. test "$a" == "$b"
  18. test "$c" == "$d"
  19. test "$a" == "$c"
  20. ! jose jwk exc -l $tmpdir/exc_a.pub.jwk -r $tmpdir/exc_b.jwk
  21. ! jose jwk exc -l $tmpdir/exc_b.pub.jwk -r $tmpdir/exc_a.jwk
  22. ! jose jwk exc -l $tmpdir/exc_a.pub.jwk -r $tmpdir/exc_b.pub.jwk
  23. ! jose jwk exc -l $tmpdir/exc_b.pub.jwk -r $tmpdir/exc_a.pub.jwk
  24. done
  25. jose jwk gen -i '{"alg":"ECDH","crv":"P-384"}' -o $tmpdir/exc_c.jwk
  26. ! jose jwk exc -l $tmpdir/exc_c.jwk -r $tmpdir/exc_a.pub.jwk
  27. jose jwk gen -i '{"kty":"EC","crv":"P-384"}' -o $tmpdir/exc_c.jwk
  28. ! jose jwk exc -l $tmpdir/exc_c.jwk -r $tmpdir/exc_a.pub.jwk
  29. jose jwk gen -i '{ "alg": "ES256" }' -o $tmpdir/exc_c.jwk
  30. ! jose jwk exc -l $tmpdir/exc_c.jwk -r $tmpdir/exc_a.pub.jwk
  31. srv=`jose jwk gen -i '{"alg":"ECMR"}'`
  32. clt=`jose jwk gen -i '{"alg":"ECMR"}'`
  33. eph=`jose jwk gen -i '{"alg":"ECMR"}'`
  34. spb=`echo "$srv" | jose jwk pub -i-`
  35. cpb=`echo "$clt" | jose jwk pub -i-`
  36. key=`echo "$clt$spb" | jose jwk exc -l- -r-`
  37. sub=`echo "$eph$spb" | jose jwk exc -l- -r- -i '{"alg":"ECMR"}'`
  38. req=`echo "$cpb$eph" | jose jwk exc -l- -r- -i '{"alg":"ECMR"}'`
  39. rep=`echo "$srv$req" | jose jwk exc -l- -r- -i '{"alg":"ECMR"}'`
  40. rec=`echo "$rep$sub" | jose jwk exc -l- -r-`
  41. echo "$key$rec" | jose fmt -j- -Oj- -OE