error handling
[oweals/gnunet.git] / src / abd / test_abd_verify_simple.sh
1 #!/usr/bin/env bash
2 trap "gnunet-arm -e -c test_abd_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_abd_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18 #  (1) Issuer.user -> Subject
19
20
21 which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
22 gnunet-arm -s -c test_abd_lookup.conf
23 gnunet-identity -C testissuer -c test_abd_lookup.conf
24 gnunet-identity -C testsubject -c test_abd_lookup.conf
25
26 TEST_ATTR="user"
27 SUBJECT_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testsubject | awk '{print $3}')
28 ISSUER_KEY=$(gnunet-identity -d -c test_abd_lookup.conf | grep testissuer | awk '{print $3}')
29
30 gnunet-identity -d
31
32 # Create delegate (1)
33 SIGNED=`$DO_TIMEOUT gnunet-abd --signSubjectSide --ego=testissuer --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --ttl="2019-12-12 10:00:00" -c test_abd_lookup.conf`
34 gnunet-abd --createSubjectSide --ego=testsubject --import="$SIGNED" --private
35 gnunet-namestore -D -z testsubject
36
37 # Starting to resolve
38 echo "+++ Starting to Resolve +++"
39
40 DELS=`$DO_TIMEOUT gnunet-abd --collect --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --ego=testsubject -c test_abd_lookup.conf | paste -d, -s - -`
41 echo $DELS
42 gnunet-abd --verify --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --delegate="$DELS" -c test_abd_lookup.conf
43
44 RES=$?
45
46 # Cleanup properly
47 gnunet-namestore -z testsubject -d -n "@" -t DEL -c test_abd_lookup.conf
48 gnunet-arm -e -c test_abd_lookup.conf
49
50 if [ "$RES" == 0 ]
51 then
52   exit 0
53 else
54   echo "FAIL: Failed to verify credential."
55   exit 1
56 fi