test_credential_verify.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. trap "gnunet-arm -e -c test_credential_lookup.conf" SIGINT
  3. LOCATION=$(which gnunet-config)
  4. if [ -z $LOCATION ]
  5. then
  6. LOCATION="gnunet-config"
  7. fi
  8. $LOCATION --version 1> /dev/null
  9. if test $? != 0
  10. then
  11. echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
  12. exit 77
  13. fi
  14. rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f`
  15. # (1) Service.user -> GNU.project.member
  16. # (2) GNU.project -> GNUnet
  17. # (3) GNUnet.member -> GNUnet.developer
  18. # (4) GNUnet.member -> GNUnet.user
  19. # (5) GNUnet.developer -> Alice
  20. which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
  21. gnunet-arm -s -c test_credential_lookup.conf
  22. gnunet-identity -C service -c test_credential_lookup.conf
  23. gnunet-identity -C alice -c test_credential_lookup.conf
  24. gnunet-identity -C gnu -c test_credential_lookup.conf
  25. gnunet-identity -C gnunet -c test_credential_lookup.conf
  26. GNU_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep gnu | grep -v gnunet | awk '{print $3}')
  27. ALICE_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep alice | awk '{print $3}')
  28. GNUNET_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep gnunet | awk '{print $3}')
  29. SERVICE_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep service | awk '{print $3}')
  30. USER_ATTR="user"
  31. GNU_PROJECT_ATTR="project"
  32. MEMBER_ATTR="member"
  33. DEVELOPER_ATTR="developer"
  34. DEV_ATTR="developer"
  35. TEST_CREDENTIAL="mygnunetcreds"
  36. # (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
  37. gnunet-namestore -p -z service -a -n $USER_ATTR -t ATTR -V "$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" -e 5m -c test_credential_lookup.conf
  38. # (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
  39. gnunet-namestore -p -z gnu -a -n $GNU_PROJECT_ATTR -t ATTR -V "$GNUNET_KEY" -e 5m -c test_credential_lookup.conf
  40. # (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
  41. gnunet-namestore -p -z gnunet -a -n $MEMBER_ATTR -t ATTR -V "$GNUNET_KEY $DEVELOPER_ATTR" -e 5m -c test_credential_lookup.conf
  42. gnunet-namestore -p -z gnunet -a -n $MEMBER_ATTR -t ATTR -V "$GNUNET_KEY $USER_ATTR" -e 5m -c test_credential_lookup.conf
  43. # (5) GNUnet issues Alice the credential "developer"
  44. CRED=`$DO_TIMEOUT gnunet-credential --issue --ego=gnunet --subject=$ALICE_KEY --attribute=$DEV_ATTR --ttl=5m -c test_credential_lookup.conf`
  45. # Alice stores the credential under "mygnunetcreds"
  46. gnunet-namestore -p -z alice -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c test_credential_lookup.conf
  47. CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$SERVICE_KEY --attribute=$USER_ATTR --ego=alice -c test_credential_lookup.conf | paste -d, -s`
  48. echo gnunet-credential --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --credential=\'$CREDS\' -c test_credential_lookup.conf
  49. #TODO2 Add -z swich like in gnunet-gns
  50. gnunet-credential --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --credential="$CREDS" -c test_credential_lookup.conf
  51. #TODO cleanup properly
  52. gnunet-namestore -z alice -d -n $TEST_CREDENTIAL -t CRED -e never -c test_credential_lookup.conf
  53. gnunet-namestore -z gnu -d -n $GNU_PROJECT_ATTR -t ATTR -c test_credential_lookup.conf
  54. gnunet-namestore -z gnunet -d -n $MEMBER_ATTR -t ATTR -c test_credential_lookup.conf
  55. gnunet-namestore -z service -d -n $USER_ATTR -t ATTR -c test_credential_lookup.conf
  56. gnunet-arm -e -c test_credential_lookup.conf
  57. if [ "$RES_CRED" != "Failed." ]
  58. then
  59. # TODO: replace echo -e bashism
  60. echo -e "${RES_CRED}"
  61. exit 0
  62. else
  63. echo "FAIL: Failed to verify credential $RES_CRED."
  64. exit 1
  65. fi