test_abd_verify_and.sh 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env bash
  2. trap "gnunet-arm -e -c test_abd_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_abd_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 AND GNUnet.user
  18. # (4) GNUnet.developer -> Alice
  19. which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
  20. gnunet-arm -s -c test_abd_lookup.conf
  21. gnunet-identity -C service -c test_abd_lookup.conf
  22. gnunet-identity -C alice -c test_abd_lookup.conf
  23. gnunet-identity -C gnu -c test_abd_lookup.conf
  24. gnunet-identity -C gnunet -c test_abd_lookup.conf
  25. GNU_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnu | grep -v gnunet | awk '{print $3}')
  26. ALICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep alice | awk '{print $3}')
  27. GNUNET_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep gnunet | awk '{print $3}')
  28. SERVICE_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep service | awk '{print $3}')
  29. USER_ATTR="user"
  30. GNU_PROJECT_ATTR="project"
  31. MEMBER_ATTR="member"
  32. DEVELOPER_ATTR="developer"
  33. DEV_ATTR="developer"
  34. gnunet-identity -d
  35. # (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
  36. gnunet-abd --createIssuerSide --ego=service --attribute="$USER_ATTR" --subject="$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
  37. gnunet-namestore -D -z service
  38. # (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
  39. gnunet-abd --createIssuerSide --ego=gnu --attribute="$GNU_PROJECT_ATTR" --subject="$GNUNET_KEY" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
  40. gnunet-namestore -D -z gnu
  41. # (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
  42. gnunet-abd --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $DEVELOPER_ATTR, $GNUNET_KEY $USER_ATTR" --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf
  43. gnunet-namestore -D -z gnunet
  44. # (5) GNUnet signes the delegates and Alice stores it
  45. SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=gnunet --attribute=$DEV_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
  46. gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
  47. SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=gnunet --attribute=$USER_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
  48. gnunet-abd --createSubjectSide --ego=alice --import="$SIGNED" --private
  49. gnunet-namestore -D -z alice
  50. # Starting to resolve
  51. echo "+++ Starting to Resolve +++"
  52. DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$SERVICE_KEY --attribute=$USER_ATTR --ego=alice --backward -c test_abd_lookup.conf | paste -d, -s - -`
  53. echo $DELS
  54. echo gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_abd_lookup.conf
  55. gnunet-abd --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_abd_lookup.conf
  56. RES=$?
  57. # Cleanup properly
  58. gnunet-namestore -z alice -d -n "@" -t DEL -c test_abd_lookup.conf
  59. gnunet-namestore -z gnu -d -n $GNU_PROJECT_ATTR -t ATTR -c test_abd_lookup.conf
  60. gnunet-namestore -z gnunet -d -n $MEMBER_ATTR -t ATTR -c test_abd_lookup.conf
  61. gnunet-namestore -z service -d -n $USER_ATTR -t ATTR -c test_abd_lookup.conf
  62. gnunet-arm -e -c test_abd_lookup.conf
  63. if [ "$RES" == 0 ]
  64. then
  65. exit 0
  66. else
  67. echo "FAIL: Failed to verify credentials."
  68. exit 1
  69. fi