frosix

Multiparty signature service (experimental)
Log | Files | Refs | README | LICENSE

test-frosix.sh (4836B)


      1 #!/bin/bash
      2 # This file is in the public domain.
      3 
      4 set -eu
      5 
      6 # Exit, with status code "skip" (no 'real' failure)
      7 function exit_skip() {
      8     echo " SKIP: $1"
      9     exit 77
     10 }
     11 
     12 # Exit, with error message (hard failure)
     13 function exit_fail() {
     14     echo " FAIL: $@"
     15     exit 1
     16 }
     17 
     18 # Cleanup to run whenever we exit
     19 function cleanup()
     20 {
     21     for n in $(jobs -p)
     22     do
     23         kill $n 2> /dev/null || true
     24     done
     25     rm -f "$SIGN_DOCUMENT" "$SIGNATURE"
     26     wait
     27 }
     28 
     29 # Install cleanup handler (except for kill -9)
     30 trap cleanup EXIT
     31 
     32 #echo -n "Testing for jq"
     33 #jq -h > /dev/null || exit_skip "jq required"
     34 #echo " FOUND"
     35 echo -n "Testing for wget"
     36 wget -h > /dev/null || exit_skip "wget required"
     37 echo " FOUND"
     38 echo -n "Testing for frosix-httpd ..."
     39 frosix-httpd -h > /dev/null || exit_skip "frosix-httpd required"
     40 echo " FOUND"
     41 echo -n "Testing for frosix-reducer ..."
     42 frosix-reducer -h > /dev/null || exit_skip "frosix-reducer required"
     43 echo " FOUND"
     44 
     45 # Files and config
     46 SIGN_DOCUMENT=$(mktemp sign_documentXXXXXX.json)
     47 SIGNATURE=$(mktemp signatureXXXXXX.json)
     48 
     49 PLIST="test-frosix_providerlist.json"
     50 
     51 CONF_1="test-frosix_1.conf"
     52 CONF_2="test-frosix_2.conf"
     53 CONF_3="test-frosix_3.conf"
     54 CONF_4="test-frosix_4.conf"
     55 CONF_5="test-frosix_5.conf"
     56 
     57 BURL_1="http://localhost:9967"
     58 BURL_2="http://localhost:9968"
     59 BURL_3="http://localhost:9969"
     60 BURL_4="http://localhost:9970"
     61 BURL_5="http://localhost:9971"
     62 
     63 AUTH='{"1":"Tobias","3":"Tobias","5":"Tobias"}'
     64 MSG="My very important message!"
     65 
     66 # Init db
     67 echo -n "Initialize frosix database ..."
     68 TARGET_DB_1=`frosix-config -c "${CONF_1}" -s frosixdb-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
     69 TARGET_DB_2=`frosix-config -c "${CONF_2}" -s frosixdb-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
     70 TARGET_DB_3=`frosix-config -c "${CONF_3}" -s frosixdb-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
     71 TARGET_DB_4=`frosix-config -c "${CONF_4}" -s frosixdb-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
     72 TARGET_DB_5=`frosix-config -c "${CONF_5}" -s frosixdb-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
     73 
     74 dropdb "${TARGET_DB_1}" >/dev/null 2>/dev/null || true
     75 createdb "${TARGET_DB_1}" || exit_skip "Could not create database ${TARGET_DB_1}"
     76 frosix-dbinit -c "${CONF_1}" &> dbinit_1.log
     77 dropdb "${TARGET_DB_2}" >/dev/null 2>/dev/null || true
     78 createdb "${TARGET_DB_2}"|| exit_skip "Could not create database ${TARGET_DB_2}"
     79 frosix-dbinit -c "${CONF_2}" &> dbinit_2.log
     80 dropdb "${TARGET_DB_3}" >/dev/null 2>/dev/null || true
     81 createdb "${TARGET_DB_3}" || exit_skip "Could not create database ${TARGET_DB_3}"
     82 frosix-dbinit -c "${CONF_3}" &> dbinit_3.log
     83 dropdb "${TARGET_DB_4}" >/dev/null 2>/dev/null || true
     84 createdb "${TARGET_DB_4}" || exit_skip "Could not create database ${TARGET_DB_4}"
     85 frosix-dbinit -c "${CONF_4}" &> dbinit_4.log
     86 dropdb "${TARGET_DB_5}" >/dev/null 2>/dev/null || true
     87 createdb "${TARGET_DB_5}" || exit_skip "Could not create database ${TARGET_DB_5}"
     88 frosix-dbinit -c "${CONF_5}" &> dbinit_5.log
     89 
     90 echo " OK"
     91 
     92 echo -n "Start frosix-httpd ..."
     93 frosix-httpd -L DEBUG -c "${CONF_1}" &> httpd_1.log &
     94 frosix-httpd -L DEBUG -c "${CONF_2}" &> httpd_2.log &
     95 frosix-httpd -L DEBUG -c "${CONF_3}" &> httpd_3.log &
     96 frosix-httpd -L DEBUG -c "${CONF_4}" &> httpd_4.log &
     97 frosix-httpd -L DEBUG -c "${CONF_5}" &> httpd_5.log &
     98 
     99 echo " OK"
    100 
    101 echo -n "Waiting for frosix services ..."
    102 
    103 # Wait for frosix to be available
    104 for n in $(seq 1 50)
    105 do
    106     echo -n "."
    107     sleep 0.1
    108     OK=0
    109     # bankfrosix_01
    110     wget --tries=1 --timeout=1 "${BURL_1}/config" -o /dev/null -O /dev/null >/dev/null || continue
    111     # bankfrosix_02
    112     wget --tries=1 --timeout=1 "${BURL_2}/config" -o /dev/null -O /dev/null >/dev/null || continue
    113     # bankfrosix_03
    114     wget --tries=1 --timeout=1 "${BURL_3}/config" -o /dev/null -O /dev/null >/dev/null || continue
    115     # bankfrosix_04
    116     wget --tries=1 --timeout=1 "${BURL_4}/config" -o /dev/null -O /dev/null >/dev/null || continue
    117     # bankfrosix_05
    118     wget --tries=1 --timeout=1 "${BURL_5}/config" -o /dev/null -O /dev/null >/dev/null || continue
    119     OK=1
    120     break
    121 done
    122 if [ 1 != $OK ]
    123 then
    124     exit_skip "Failed to launch frosix service"
    125 fi
    126 
    127 echo " OK"
    128 
    129 # Start with key generation
    130 echo -n "Start distributed key generation ..."
    131 frosix-cli keygen -o "${SIGN_DOCUMENT}" < "${PLIST}"
    132 RET_KG=$?
    133 
    134 if [ "$RET_KG" != "0" ]
    135 then
    136   exit_fail "Key generation failed! Expected return code 0, got $RET_KG"
    137 fi
    138 
    139 echo " OK"
    140 
    141 # Sign a message
    142 echo -n "Sign a message ..."
    143 frosix-cli sign -a "${AUTH}" -m "${MSG}" -o "${SIGNATURE}" < "${SIGN_DOCUMENT}"
    144 RET_S=$?
    145 
    146 if [ "$RET_S" != "0" ]
    147 then
    148   exit_fail "Signing failed! Expected return code 0, got $RET_S"
    149 fi
    150 
    151 echo " OK"
    152 
    153 # Verify the signature
    154 echo -n "Verify the signature ..."
    155 frosix-cli verify -m "${MSG}" < "${SIGNATURE}"
    156 RET_V=$?
    157 
    158 if [ "$RET_V" != "0" ]
    159 then
    160   exit_fail "Verification of signature failed!"
    161 fi
    162 
    163 exit 0