Cleanup TODOs, bugfix in cleanup and start of bidirectional chain resolution:
[oweals/gnunet.git] / src / credential / test_credential_verify.sh
1 #!/usr/bin/env bash
2 trap "gnunet-arm -e -c test_credential_lookup.conf" SIGINT
3
4 LOCATION=$(which gnunet-config)
5 if [ -z $LOCATION ]
6 then
7   LOCATION="gnunet-config"
8 fi
9 $LOCATION --version 1> /dev/null
10 if test $? != 0
11 then
12         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13         exit 77
14 fi
15
16 rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18 #  (1) Service.user -> GNU.project.member
19 #  (2) GNU.project -> GNUnet
20 #  (3) GNUnet.member -> GNUnet.developer
21 #  (4) GNUnet.member -> GNUnet.user
22 #  (5) GNUnet.developer -> Alice
23
24
25 which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
26 gnunet-arm -s -c test_credential_lookup.conf
27 gnunet-identity -C service -c test_credential_lookup.conf
28 gnunet-identity -C alice -c test_credential_lookup.conf
29 gnunet-identity -C gnu -c test_credential_lookup.conf
30 gnunet-identity -C gnunet -c test_credential_lookup.conf
31
32 GNU_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep gnu | grep -v gnunet | awk '{print $3}')
33 ALICE_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep alice | awk '{print $3}')
34 GNUNET_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep gnunet | awk '{print $3}')
35 SERVICE_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep service | awk '{print $3}')
36
37 USER_ATTR="user"
38 GNU_PROJECT_ATTR="project"
39 MEMBER_ATTR="member"
40 DEVELOPER_ATTR="developer"
41 DEV_ATTR="developer"
42 TEST_CREDENTIAL="mygnunetcreds"
43
44 # (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
45 gnunet-credential --createIssuerSide --ego=service --attribute="$USER_ATTR" --subject="$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" --ttl="2019-12-12 10:00:00" -c test_credential_lookup.conf
46 gnunet-namestore -D -z service
47
48 # (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
49 gnunet-credential --createIssuerSide --ego=gnu --attribute="$GNU_PROJECT_ATTR" --subject="$GNUNET_KEY" --ttl="2019-12-12 10:00:00" -c test_credential_lookup.conf
50 gnunet-namestore -D -z gnu
51
52 # (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
53 gnunet-credential --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $DEVELOPER_ATTR" --ttl="2019-12-12 10:00:00" -c test_credential_lookup.conf
54 gnunet-credential --createIssuerSide --ego=gnunet --attribute="$MEMBER_ATTR" --subject="$GNUNET_KEY $USER_ATTR" --ttl="2019-12-12 10:00:00" -c test_credential_lookup.conf
55 gnunet-namestore -D -z gnunet
56
57 # (5) GNUnet signes the delegate and Alice stores it
58 SIGNED=`$DO_TIMEOUT gnunet-credential --signSubjectSide --ego=gnunet --attribute=$DEV_ATTR --subject=$ALICE_KEY --ttl="2019-12-12 10:00:00"`
59 gnunet-credential --createSubjectSide --ego=alice --import "$SIGNED" --private
60 gnunet-namestore -D -z alice
61
62 # Starting to resolve
63 echo "+++ Starting to Resolve +++"
64
65 DELS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$SERVICE_KEY --attribute=$USER_ATTR --ego=alice --backward -c test_credential_lookup.conf | paste -d, -s`
66 echo $DELS
67 echo gnunet-credential --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate=\'$DELS\' --backward -c test_credential_lookup.conf
68 gnunet-credential --verify --issuer=$SERVICE_KEY --attribute=$USER_ATTR --subject=$ALICE_KEY --delegate="$DELS" --backward -c test_credential_lookup.conf
69
70 RES=$?
71
72 # Cleanup properly
73 gnunet-namestore -z alice -d -n "@" -t DEL -c test_credential_lookup.conf
74 gnunet-namestore -z gnu -d -n $GNU_PROJECT_ATTR -t ATTR -c test_credential_lookup.conf
75 gnunet-namestore -z gnunet -d -n $MEMBER_ATTR -t ATTR -c test_credential_lookup.conf
76 gnunet-namestore -z service -d -n $USER_ATTR -t ATTR -c test_credential_lookup.conf
77 gnunet-arm -e -c test_credential_lookup.conf
78
79 if [ "$RES" == 0 ]
80 then
81   exit 0
82 else
83   echo "FAIL: Failed to verify credential."
84   exit 1
85 fi