[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: work on backup reduxer implemen
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: work on backup reduxer implementation |
Date: |
Wed, 24 Feb 2021 20:49:35 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 52d4838 work on backup reduxer implementation
52d4838 is described below
commit 52d4838102db81a9ab3afaea95d88cbf0c71fb26
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 24 20:49:33 2021 +0100
work on backup reduxer implementation
---
src/cli/Makefile.am | 10 +-
src/cli/resources/03-backup.json | 157 ++++++++++
.../test_anastasis_reducer_add_authentication.sh | 60 ++--
...astasis_reducer_backup_enter_user_attributes.sh | 117 ++++++--
src/cli/test_anastasis_reducer_select_country.sh | 79 +----
src/include/anastasis.h | 2 +-
src/lib/anastasis_recovery.c | 12 +-
src/reducer/anastasis_api_backup_redux.c | 45 +--
src/reducer/anastasis_api_recovery_redux.c | 320 +++++++++++++++++----
src/restclient/anastasis_api_policy_lookup.c | 25 +-
10 files changed, 613 insertions(+), 214 deletions(-)
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index ad2f81f..aff7925 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -14,11 +14,11 @@ check_SCRIPTS = \
test_anastasis_reducer_select_continent.sh \
test_anastasis_reducer_select_country.sh \
test_anastasis_reducer_backup_enter_user_attributes.sh \
- test_anastasis_reducer_add_authentication.sh \
- test_anastasis_reducer_done_authentication.sh \
- test_anastasis_reducer_done_policy_review.sh \
- test_anastasis_reducer_enter_secret.sh \
- test_anastasis_reducer_recovery_enter_user_attributes.sh
+ test_anastasis_reducer_add_authentication.sh
+# test_anastasis_reducer_done_authentication.sh \
+# test_anastasis_reducer_done_policy_review.sh \
+# test_anastasis_reducer_enter_secret.sh \
+# test_anastasis_reducer_recovery_enter_user_attributes.sh
AM_TESTS_ENVIRONMENT=export
ANASTASIS_PREFIX=$${ANASTASIS_PREFIX:-@libdir@};export
PATH=$${ANASTASIS_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset
XDG_CONFIG_HOME;
diff --git a/src/cli/resources/03-backup.json b/src/cli/resources/03-backup.json
new file mode 100644
index 0000000..c433dcf
--- /dev/null
+++ b/src/cli/resources/03-backup.json
@@ -0,0 +1,157 @@
+{
+ "continents": [
+ "Europe",
+ "North America",
+ "Testcontinent"
+ ],
+ "backup_state": "AUTHENTICATIONS_EDITING",
+ "selected_continent": "Testcontinent",
+ "countries": [
+ {
+ "code": "xx",
+ "name": "Testland",
+ "continent": "Testcontinent",
+ "continent_i18n": {
+ "xx": "Testkontinent"
+ },
+ "name_i18n": {
+ "de_DE": "Testlandt",
+ "de_CH": "Testlandi",
+ "fr": "Testpais",
+ "en": "Testland"
+ },
+ "currency": "TESTKUDOS"
+ },
+ {
+ "code": "xy",
+ "name": "Demoland",
+ "continent": "Testcontinent",
+ "continent_i18n": {
+ "xx": "Testkontinent"
+ },
+ "name_i18n": {
+ "de_DE": "Demolandt",
+ "de_CH": "Demolandi",
+ "fr": "Demopais",
+ "en": "Demoland"
+ },
+ "currency": "KUDOS"
+ }
+ ],
+ "authentication_providers": {
+ "http://localhost:8086/": {
+ "methods": [
+ {
+ "method": "question",
+ "usage_fee": "TESTKUDOS:0"
+ }
+ ],
+ "annual_fee": "TESTKUDOS:4.99",
+ "truth_upload_fee": "TESTKUDOS:0.01",
+ "liability_limit": "TESTKUDOS:1",
+ "truth_lifetime": {
+ "d_ms": 63115200000
+ },
+ "currency": "TESTKUDOS",
+ "business_name": "Data loss #1 Inc.",
+ "storage_limit_in_megabytes": 1,
+ "salt": "F0HEYJQW81ZAZ3VYMZHFG8T1Z0"
+ },
+ "http://localhost:8087/": {
+ "methods": [
+ {
+ "method": "question",
+ "usage_fee": "TESTKUDOS:0"
+ }
+ ],
+ "annual_fee": "TESTKUDOS:4.99",
+ "truth_upload_fee": "TESTKUDOS:0.01",
+ "liability_limit": "TESTKUDOS:1",
+ "truth_lifetime": {
+ "d_ms": 63115200000
+ },
+ "currency": "TESTKUDOS",
+ "business_name": "Data loss #2 Inc.",
+ "storage_limit_in_megabytes": 1,
+ "salt": "D378FWXHJB8JHPQFQRZGGV9PWG"
+ },
+ "http://localhost:8088/": {
+ "methods": [
+ {
+ "method": "question",
+ "usage_fee": "TESTKUDOS:0"
+ }
+ ],
+ "annual_fee": "TESTKUDOS:4.99",
+ "truth_upload_fee": "TESTKUDOS:0.01",
+ "liability_limit": "TESTKUDOS:1",
+ "truth_lifetime": {
+ "d_ms": 63115200000
+ },
+ "currency": "TESTKUDOS",
+ "business_name": "Data loss #3 Inc.",
+ "storage_limit_in_megabytes": 1,
+ "salt": "7W9W4A4TTWSWRPJ76RNDPJHSPR"
+ },
+ "http://localhost:8089/": {
+ "methods": [
+ {
+ "method": "question",
+ "usage_fee": "TESTKUDOS:0"
+ }
+ ],
+ "annual_fee": "TESTKUDOS:4.99",
+ "truth_upload_fee": "TESTKUDOS:0.01",
+ "liability_limit": "TESTKUDOS:1",
+ "truth_lifetime": {
+ "d_ms": 63115200000
+ },
+ "currency": "TESTKUDOS",
+ "business_name": "Data loss #4 Inc.",
+ "storage_limit_in_megabytes": 1,
+ "salt": "PN0VJF6KDSBYN40SGRCEXPB07M"
+ }
+ },
+ "selected_country": "xx",
+ "currency": "TESTKUDOS",
+ "required_attributes": [
+ {
+ "type": "string",
+ "name": "full_name",
+ "label": "Full name",
+ "label_i18n": {
+ "de_DE": "Vollstaendiger Name",
+ "de_CH": "Vollstaendiger Name"
+ },
+ "widget": "anastasis_gtk_ia_full_name"
+ },
+ {
+ "type": "date",
+ "name": "birthdate",
+ "label": "Birthdate",
+ "label_i18n": {
+ "de_CH": "Geburtsdatum"
+ },
+ "widget": "anastasis_gtk_ia_birthdate"
+ },
+ {
+ "type": "string",
+ "name": "ahv_number",
+ "label": "AHV number",
+ "label_i18n": {
+ "de_DE": "AHV-Nummer",
+ "de_CH": "AHV-Nummer"
+ },
+ "widget": "anastasis_gtk_ia_ahv",
+ "validation-regex": "^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$",
+ "validation-logic": "CH_AVH_check"
+ }
+ ],
+ "identity_attributes": {
+ "full_name": "Max Musterman",
+ "ahv_number": "756.9217.0769.85",
+ "birth_year": 2000,
+ "birth_month": 1,
+ "birth_day": 1
+ }
+}
\ No newline at end of file
diff --git a/src/cli/test_anastasis_reducer_add_authentication.sh
b/src/cli/test_anastasis_reducer_add_authentication.sh
index 0ec7922..062d23b 100755
--- a/src/cli/test_anastasis_reducer_add_authentication.sh
+++ b/src/cli/test_anastasis_reducer_add_authentication.sh
@@ -4,13 +4,13 @@ set -eu
# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
- echo $1
+ echo " SKIP: $1"
exit 77
}
# Exit, with error message (hard failure)
function exit_fail() {
- echo $1
+ echo " ERROR: $1"
exit 1
}
@@ -21,18 +21,14 @@ function cleanup()
do
kill $n 2> /dev/null || true
done
- rm -f $SFILE $TFILE
+ rm -f $TFILE $SFILE
wait
}
-# Install cleanup handler (except for kill -9)
-AFN=`which anastasis-reducer`
-ADN=`dirname $AFN`
-RESOURCES=$ADN/../share/anastasis
SFILE=`mktemp test_reducer_stateXXXXXX`
TFILE=`mktemp test_reducer_stateXXXXXX`
-UFILE=$RESOURCES/test_reducer_stateAESTATE
+# Install cleanup handler (except for kill -9)
trap cleanup EXIT
# Check we can actually run
@@ -40,76 +36,80 @@ echo -n "Testing for jq"
jq -h > /dev/null || exit_skip "jq required"
echo " FOUND"
-echo " "
-echo "Beginning with actual reducer test"
+echo -n "Testing for anastasis-reducer ..."
+anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
+echo " FOUND"
+
+echo -n "Testing for anastasis-httpd"
+anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
+echo " FOUND"
+
+echo -n "Test add authentication ..."
-# Test add authentication in a backup state
# First method
-echo " "
-echo "Test add authentication in a backup state"
-./anastasis-reducer -a \
+anastasis-reducer -a \
'{"authentication_method": {
"method": "question",
"data": {
"question": "Whats your name?",
"answer": "Hans"
}}}' \
- add_authentication $UFILE $SFILE
+ add_authentication resources/03-backup.json $TFILE
-STATE=`jq -r -e .backup_state < $SFILE`
+STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "AUTHENTICATIONS_EDITING"
then
- exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+ exit_fail "Expected new state to be 'AUTHENTICATIONS_EDITING', got
'$STATE'"
fi
-ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $SFILE`
+ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $TFILE`
if test $ARRAY_LENGTH != 1
then
- exit_fail "Expected array length to be 1, got $ARRAY_LENGTH"
+ exit_fail "Expected array length to be 1, got '$ARRAY_LENGTH'"
fi
-#Second method
-./anastasis-reducer -a \
+# Second method
+anastasis-reducer -a \
'{"authentication_method": {
"method": "question",
"data": {
"question": "How old are you?",
"answer": "123"
}}}' \
- add_authentication $SFILE $TFILE
+ add_authentication $TFILE $SFILE
STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "AUTHENTICATIONS_EDITING"
then
- exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+ exit_fail "Expected new state to be 'AUTHENTICATIONS_EDITING', got
'$STATE'"
fi
ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $TFILE`
if test $ARRAY_LENGTH != 2
then
- exit_fail "Expected array length to be 2, got $ARRAY_LENGTH"
+ exit_fail "Expected array length to be 2, got '$ARRAY_LENGTH'"
fi
-#Third method
-./anastasis-reducer -a \
+# Third method
+anastasis-reducer -a \
'{"authentication_method": {
"method": "question",
"data": {
"question": "Where do you live?",
"answer": "Mars"
}}}' \
- add_authentication $TFILE $SFILE
+ add_authentication $SFILE $TFILE
-STATE=`jq -r -e .backup_state < $SFILE`
+STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "AUTHENTICATIONS_EDITING"
then
- exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+ exit_fail "Expected new state to be 'AUTHENTICATIONS_EDITING', got
'$STATE'"
fi
ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $SFILE`
if test $ARRAY_LENGTH != 3
then
- exit_fail "Expected array length to be 3, got $ARRAY_LENGTH"
+ exit_fail "Expected array length to be 3, got '$ARRAY_LENGTH'"
fi
exit 0
diff --git a/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
index ce4d63a..e68149d 100755
--- a/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
@@ -4,13 +4,13 @@ set -eu
# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
- echo $1
+ echo " SKIP: $1"
exit 77
}
# Exit, with error message (hard failure)
function exit_fail() {
- echo $1
+ echo " ERROR: $1"
exit 1
}
@@ -21,17 +21,16 @@ function cleanup()
do
kill $n 2> /dev/null || true
done
- rm -f $TFILE
wait
}
-# Install cleanup handler (except for kill -9)
-AFN=`which anastasis-reducer`
-ADN=`dirname $AFN`
-RESOURCES=$ADN/../share/anastasis
-SFILE=$RESOURCES/test_reducer_backup_stateUACSTATE
+CONF_1="test_anastasis_reducer_1.conf"
+CONF_2="test_anastasis_reducer_2.conf"
+CONF_3="test_anastasis_reducer_3.conf"
+CONF_4="test_anastasis_reducer_4.conf"
TFILE=`mktemp test_reducer_stateXXXXXX`
+# Install cleanup handler (except for kill -9)
trap cleanup EXIT
# Check we can actually run
@@ -39,33 +38,113 @@ echo -n "Testing for jq"
jq -h > /dev/null || exit_skip "jq required"
echo " FOUND"
-echo " "
-echo "Beginning with actual reducer test"
+echo -n "Testing for anastasis-reducer ..."
+anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
+echo " FOUND"
+
+echo -n "Testing for anastasis-httpd"
+anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
+echo " FOUND"
+
+
+# Name of the Postgres database we will use for the script.
+# Will be dropped, do NOT use anything that might be used
+# elsewhere
+TARGET_DB_1=`anastasis-config -c $CONF_1 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
+TARGET_DB_2=`anastasis-config -c $CONF_2 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
+TARGET_DB_3=`anastasis-config -c $CONF_3 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
+TARGET_DB_4=`anastasis-config -c $CONF_4 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
+
+echo -n "Initialize anastasis database ..."
+dropdb $TARGET_DB_1 >/dev/null 2>/dev/null || true
+createdb $TARGET_DB_1 || exit_skip "Could not create database $TARGET_DB_1"
+anastasis-dbinit -c $CONF_1 2> anastasis-dbinit_1.log
+dropdb $TARGET_DB_2 >/dev/null 2>/dev/null || true
+createdb $TARGET_DB_2 || exit_skip "Could not create database $TARGET_DB_2"
+anastasis-dbinit -c $CONF_2 2> anastasis-dbinit_2.log
+dropdb $TARGET_DB_3 >/dev/null 2>/dev/null || true
+createdb $TARGET_DB_3 || exit_skip "Could not create database $TARGET_DB_3"
+anastasis-dbinit -c $CONF_3 2> anastasis-dbinit_3.log
+dropdb $TARGET_DB_4 >/dev/null 2>/dev/null || true
+createdb $TARGET_DB_4 || exit_skip "Could not create database $TARGET_DB_4"
+anastasis-dbinit -c $CONF_4 2> anastasis-dbinit_4.log
+
+echo " OK"
+
+echo -n "Launching anastasis service ..."
+anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log &
+anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log &
+anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log &
+anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log &
+
+# Wait for anastasis service to be available
+for n in `seq 1 50`
+do
+ echo -n "."
+ sleep 0.1
+ OK=0
+ # anastasis_01
+ wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null ||
continue
+ # anastasis_02
+ wget http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null ||
continue
+ # anastasis_03
+ wget http://localhost:8088/ -o /dev/null -O /dev/null >/dev/null ||
continue
+ # anastasis_04
+ wget http://localhost:8089/ -o /dev/null -O /dev/null >/dev/null ||
continue
+ OK=1
+ break
+done
+
+if [ 1 != $OK ]
+then
+ exit_skip "Failed to launch anastasis services"
+fi
+echo " OK"
# Test user attributes collection in a backup state
-echo " "
-echo "Test user attributes collection in a backup state"
-./anastasis-reducer -a \
+echo -n "Test user attributes collection in a backup state ..."
+anastasis-reducer -a \
'{"identity_attributes": {
"full_name": "Max Musterman",
"ahv_number": "756.9217.0769.85",
"birth_year": 2000,
- "birth_month": 1,
+ "birth_month": 1,
"birth_day": 1}}' \
- enter_user_attributes $SFILE $TFILE
+ enter_user_attributes resources/02-backup.json $TFILE
STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "AUTHENTICATIONS_EDITING"
then
- exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+ exit_fail "Expected new state to be 'AUTHENTICATIONS_EDITING', got
'$STATE'"
fi
SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
-if test "$SELECTED_COUNTRY" != "ch"
+if test "$SELECTED_COUNTRY" != "xx"
then
- exit_fail "Expected selected country to be ch, got $SELECTED_COUNTRY"
+ exit_fail "Expected selected country to be 'xx', got '$SELECTED_COUNTRY'"
fi
-# Test country selection in a recovery state
+echo "OK"
+
+
+echo -n "Test user attributes collection in a recovery state ..."
+anastasis-reducer -a \
+ '{"identity_attributes": {
+ "full_name": "Max Musterman",
+ "ahv_number": "756.9217.0769.85",
+ "birth_year": 2000,
+ "birth_month": 1,
+ "birth_day": 1}}' \
+ enter_user_attributes resources/02-recovery.json $TFILE 2> /dev/null &&
exit_fail "Expected recovery to fail due to lacking policy data"
+
+CODE=`jq -r -e .code < $TFILE`
+if test "$CODE" != "8410"
+then
+ exit_fail "Expected error code to be '8410', got '$CODE'"
+fi
+
+echo "OK"
+
+rm -f $TFILE
exit 0
diff --git a/src/cli/test_anastasis_reducer_select_country.sh
b/src/cli/test_anastasis_reducer_select_country.sh
index 2d4e22f..42d0e23 100755
--- a/src/cli/test_anastasis_reducer_select_country.sh
+++ b/src/cli/test_anastasis_reducer_select_country.sh
@@ -21,21 +21,15 @@ function cleanup()
do
kill $n 2> /dev/null || true
done
- rm -f $SFILE $TFILE $UFILE
+ rm -f $TFILE
wait
}
-# Install cleanup handler (except for kill -9)
-CONF_1="test_anastasis_reducer_1.conf"
-CONF_2="test_anastasis_reducer_2.conf"
-CONF_3="test_anastasis_reducer_3.conf"
-CONF_4="test_anastasis_reducer_4.conf"
-SFILE=`mktemp test_reducer_stateXXXXXX`
TFILE=`mktemp test_reducer_stateXXXXXX`
-UFILE=`mktemp test_reducer_stateXXXXXX`
+# Install cleanup handler (except for kill -9)
trap cleanup EXIT
# Check we can actually run
@@ -47,64 +41,7 @@ echo -n "Testing for anastasis-reducer ..."
anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
echo " FOUND"
-echo -n "Testing for anastasis-httpd"
-anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-
-
-# Name of the Postgres database we will use for the script.
-# Will be dropped, do NOT use anything that might be used
-# elsewhere
-TARGET_DB_1=`anastasis-config -c $CONF_1 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
-TARGET_DB_2=`anastasis-config -c $CONF_2 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
-TARGET_DB_3=`anastasis-config -c $CONF_3 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
-TARGET_DB_4=`anastasis-config -c $CONF_4 -s stasis-postgres -o CONFIG | sed -e
"s/^postgres:\/\/\///"`
-
-echo -n "Initialize anastasis database ..."
-dropdb $TARGET_DB_1 >/dev/null 2>/dev/null || true
-createdb $TARGET_DB_1 || exit_skip "Could not create database $TARGET_DB_1"
-anastasis-dbinit -c $CONF_1 2> anastasis-dbinit_1.log
-dropdb $TARGET_DB_2 >/dev/null 2>/dev/null || true
-createdb $TARGET_DB_2 || exit_skip "Could not create database $TARGET_DB_2"
-anastasis-dbinit -c $CONF_2 2> anastasis-dbinit_2.log
-dropdb $TARGET_DB_3 >/dev/null 2>/dev/null || true
-createdb $TARGET_DB_3 || exit_skip "Could not create database $TARGET_DB_3"
-anastasis-dbinit -c $CONF_3 2> anastasis-dbinit_3.log
-dropdb $TARGET_DB_4 >/dev/null 2>/dev/null || true
-createdb $TARGET_DB_4 || exit_skip "Could not create database $TARGET_DB_4"
-anastasis-dbinit -c $CONF_4 2> anastasis-dbinit_4.log
-echo " OK"
-
-echo -n "Launching anastasis service ..."
-anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log &
-anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log &
-anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log &
-anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log &
-
-# Wait for anastasis service to be available
-for n in `seq 1 50`
-do
- echo -n "."
- sleep 0.1
- OK=0
- # anastasis_01
- wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null ||
continue
- # anastasis_02
- wget http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null ||
continue
- # anastasis_03
- wget http://localhost:8088/ -o /dev/null -O /dev/null >/dev/null ||
continue
- # anastasis_04
- wget http://localhost:8089/ -o /dev/null -O /dev/null >/dev/null ||
continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- exit_skip "Failed to launch anastasis services"
-fi
-echo " OK"
# Test continent re-selection
echo -n "Test continent re-selection ..."
@@ -170,33 +107,33 @@ echo -n "Test country selection ..."
anastasis-reducer -a \
'{"country_code": "xx",
"currency":"TESTKUDOS"}' \
- select_country resources/01-backup.json $UFILE
+ select_country resources/01-backup.json $TFILE
-STATE=`jq -r -e .backup_state < $UFILE`
+STATE=`jq -r -e .backup_state < $TFILE`
if test "$STATE" != "USER_ATTRIBUTES_COLLECTING"
then
exit_fail "Expected new state to be 'USER_ATTRIBUTES_COLLECTING', got
'$STATE'"
fi
echo -n "."
-SELECTED_COUNTRY=`jq -r -e .selected_country < $UFILE`
+SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
if test "$SELECTED_COUNTRY" != "xx"
then
exit_fail "Expected selected country to be 'xx', got '$SELECTED_COUNTRY'"
fi
echo -n "."
-SELECTED_CURRENCY=`jq -r -e .currency < $UFILE`
+SELECTED_CURRENCY=`jq -r -e .currency < $TFILE`
if test "$SELECTED_CURRENCY" != "TESTKUDOS"
then
exit_fail "Expected selected currency to be 'TESTKUDOS', got
'$SELECTED_CURRENCY'"
fi
echo -n "."
-REQ_ATTRIBUTES=`jq -r -e .required_attributes < $UFILE`
+REQ_ATTRIBUTES=`jq -r -e .required_attributes < $TFILE`
if test "$REQ_ATTRIBUTES" == NULL
then
exit_fail "Expected required attributes array not to be NULL"
fi
echo -n "."
-AUTH_PROVIDERS=`jq -r -e .authentication_providers < $UFILE`
+AUTH_PROVIDERS=`jq -r -e .authentication_providers < $TFILE`
if test "$AUTH_PROVIDERS" == NULL
then
exit_fail "Expected authentication_providers array not to be NULL"
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 6e71220..0c53ceb 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -418,7 +418,7 @@ enum ANASTASIS_RecoveryStatus
* This function is called whenever the recovery process ends.
* On success, the secret is returned in @a secret.
*
- * @param cls handle for the callback
+ * @param cls closure
* @param ec error code
* @param secret contains the core secret which is passed to the user
* @param secret_size defines the size of the core secret
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index a270549..9d3ef20 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -515,8 +515,18 @@ policy_lookup_cb (void *cls,
json_t *esc_methods;
r->plo = NULL;
- if (MHD_HTTP_OK != http_status)
+ switch (http_status)
{
+ case MHD_HTTP_OK:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ r->csc (r->csc_cls,
+ ANASTASIS_RS_POLICY_DOWNLOAD_FAILED,
+ NULL,
+ 0);
+ ANASTASIS_recovery_abort (r);
+ return;
+ default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u in %s:%u\n",
http_status,
diff --git a/src/reducer/anastasis_api_backup_redux.c
b/src/reducer/anastasis_api_backup_redux.c
index 062d95b..9d9193e 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -2487,7 +2487,7 @@ abort_backup_begin_cb (void *cls)
* into the main state, trigger the continuation and free our
* state.
*
- * @param[in] main state to merge into
+ * @param[in] bss main state to merge into
*/
static void
providers_complete (struct BackupStartState *bss)
@@ -2570,8 +2570,6 @@ ANASTASIS_REDUX_backup_begin_ (json_t *state,
void *cb_cls)
{
json_t *provider_list;
- json_t *prov;
- const char *url;
struct BackupStartState *bss;
provider_list = json_object_get (state,
@@ -2592,24 +2590,29 @@ ANASTASIS_REDUX_backup_begin_ (json_t *state,
bss->ra.cleanup_cls = bss;
bss->ra.cleanup = &abort_backup_begin_cb;
bss->pending = 1; /* decremented after initialization loop */
- json_object_foreach (provider_list, url, prov) {
- struct BackupStartStateProviderEntry *pe;
- json_t *istate;
-
- pe = GNUNET_new (struct BackupStartStateProviderEntry);
- pe->bss = bss;
- istate = json_object ();
- GNUNET_assert (NULL != istate);
- GNUNET_CONTAINER_DLL_insert (bss->pe_head,
- bss->pe_tail,
- pe);
- pe->ra = ANASTASIS_REDUX_add_provider_to_state_ (url,
- istate,
- &provider_added_cb,
- pe);
- json_decref (istate);
- if (NULL != pe->ra)
- bss->pending++;
+
+ {
+ json_t *prov;
+ const char *url;
+ json_object_foreach (provider_list, url, prov) {
+ struct BackupStartStateProviderEntry *pe;
+ json_t *istate;
+
+ pe = GNUNET_new (struct BackupStartStateProviderEntry);
+ pe->bss = bss;
+ istate = json_object ();
+ GNUNET_assert (NULL != istate);
+ GNUNET_CONTAINER_DLL_insert (bss->pe_head,
+ bss->pe_tail,
+ pe);
+ pe->ra = ANASTASIS_REDUX_add_provider_to_state_ (url,
+ istate,
+ &provider_added_cb,
+ pe);
+ json_decref (istate);
+ if (NULL != pe->ra)
+ bss->pending++;
+ }
}
bss->pending--;
if (0 == bss->pending)
diff --git a/src/reducer/anastasis_api_recovery_redux.c
b/src/reducer/anastasis_api_recovery_redux.c
index 2ffed7a..6bfa112 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -840,6 +840,44 @@ struct PolicyDownloadEntry
};
+/**
+ * Entry in the list of all known applicable Anastasis providers.
+ * Used to wait for it to complete downloading /config.
+ */
+struct RecoveryStartStateProviderEntry
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct RecoveryStartStateProviderEntry *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct RecoveryStartStateProviderEntry *prev;
+
+ /**
+ * Main operation this entry is part of.
+ */
+ struct RecoverSecretState *rss;
+
+ /**
+ * Resulting provider information, NULL if not (yet) available.
+ */
+ json_t *istate;
+
+ /**
+ * Ongoing reducer action to obtain /config, NULL if completed.
+ */
+ struct ANASTASIS_ReduxAction *ra;
+
+ /**
+ * Final result of the operation (once completed).
+ */
+ enum TALER_ErrorCode ec;
+};
+
+
/**
* State for a "recover secret" CMD.
*/
@@ -851,6 +889,16 @@ struct RecoverSecretState
*/
struct ANASTASIS_ReduxAction ra;
+ /**
+ * Head of list of provider /config operations we are doing.
+ */
+ struct RecoveryStartStateProviderEntry *pe_head;
+
+ /**
+ * Tail of list of provider /config operations we are doing.
+ */
+ struct RecoveryStartStateProviderEntry *pe_tail;
+
/**
* Identification data from the user
*/
@@ -886,6 +934,16 @@ struct RecoverSecretState
*/
unsigned int version;
+ /**
+ * Number of provider /config operations in @e ba_head that
+ * are still awaiting completion.
+ */
+ unsigned int pending;
+
+ /**
+ * Is @e version set?
+ */
+ bool have_version;
};
@@ -919,6 +977,49 @@ free_rss (void *cls)
}
+/**
+ * This function is called whenever the recovery process ends.
+ * In this case, that should not be possible as this callback
+ * is used before we even begin with the challenges. So if
+ * we are called, it is because of some fatal error.
+ *
+ * @param cls a `struct PolicyDownloadEntry`
+ * @param ec error code
+ * @param secret contains the core secret which is passed to the user
+ * @param secret_size defines the size of the core secret
+ */
+static void
+core_early_secret_cb (void *cls,
+ enum ANASTASIS_RecoveryStatus rc,
+ const void *secret,
+ size_t secret_size)
+{
+ struct PolicyDownloadEntry *pd = cls;
+ struct RecoverSecretState *rss = pd->rss;
+
+ pd->recovery = NULL;
+ GNUNET_assert (NULL == secret);
+ GNUNET_CONTAINER_DLL_remove (rss->pd_head,
+ rss->pd_tail,
+ pd);
+ GNUNET_free (pd->backend_url);
+ GNUNET_free (pd);
+ if (NULL != rss->pd_head)
+ return; /* wait for another one */
+ /* all failed! report failure! */
+ /* FIXME: return 'rc' to application more nicely */
+ set_state (rss->state,
+ ANASTASIS_GENERIC_STATE_ERROR);
+
+ ANASTASIS_redux_fail_ (rss->cb,
+ rss->cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_POLICY_LOOKUP_FAILED,
+ "Failed to obtain policy data");
+ rss->cb = NULL;
+ free_rss (rss);
+}
+
+
/**
* Callback which passes back the recovery document and its possible
* policies. Also passes back the version of the document for the user
@@ -1053,6 +1154,142 @@ policy_lookup_cb (void *cls,
}
+/**
+ * We finished downloading /config from all providers, merge
+ * into the main state, trigger the continuation and free our
+ * state.
+ *
+ * @param[in] rss main state to merge into
+ */
+static void
+providers_complete (struct RecoverSecretState *rss)
+{
+ bool launched = false;
+ struct RecoveryStartStateProviderEntry *pe;
+ json_t *tlist;
+
+ tlist = json_object_get (rss->state,
+ "authentication_providers");
+ if (NULL == tlist)
+ {
+ tlist = json_object ();
+ GNUNET_assert (NULL != tlist);
+ GNUNET_assert (0 ==
+ json_object_set_new (rss->state,
+ "authentication_providers",
+ tlist));
+ }
+ while (NULL != (pe = rss->pe_head))
+ {
+ json_t *provider_list;
+
+ GNUNET_CONTAINER_DLL_remove (rss->pe_head,
+ rss->pe_tail,
+ pe);
+ provider_list = json_object_get (pe->istate,
+ "authentication_providers");
+ /* merge provider_list into tlist (overriding existing entries) */
+ if (NULL != provider_list)
+ {
+ const char *url;
+ json_t *value;
+
+ json_object_foreach (provider_list, url, value) {
+ GNUNET_assert (0 ==
+ json_object_set (tlist,
+ url,
+ value));
+ }
+ }
+ json_decref (pe->istate);
+ GNUNET_free (pe);
+ }
+
+ /* now iterate over providers and begin downloading */
+ {
+ json_t *p_cfg;
+ const char *provider_url;
+
+ json_object_foreach (tlist, provider_url, p_cfg)
+ {
+ struct PolicyDownloadEntry *pd = GNUNET_new (struct PolicyDownloadEntry);
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("salt",
+ &pd->salt),
+ GNUNET_JSON_spec_end ()
+ };
+
+ GNUNET_CONTAINER_DLL_insert (rss->pd_head,
+ rss->pd_tail,
+ pd);
+ pd->backend_url = GNUNET_strdup (provider_url);
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (p_cfg,
+ spec,
+ NULL, NULL))
+ {
+ ANASTASIS_redux_fail_ (rss->cb,
+ rss->cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+ "could not begin parse
'authentication_provider' data");
+ rss->cb = NULL;
+ free_rss (rss);
+ return;
+ }
+ pd->rss = rss;
+ pd->recovery = ANASTASIS_recovery_begin (ANASTASIS_REDUX_ctx_,
+ rss->id_data,
+ rss->have_version
+ ? rss->version
+ : 0,
+ pd->backend_url,
+ &pd->salt,
+ &policy_lookup_cb,
+ pd,
+ &core_early_secret_cb,
+ pd);
+ if (NULL != pd->recovery)
+ launched = true;
+ }
+ }
+ if (! launched)
+ {
+ GNUNET_break (0);
+ ANASTASIS_redux_fail_ (rss->cb,
+ rss->cb_cls,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "Failed to begin recovery operation");
+ rss->cb = NULL;
+ free_rss (rss);
+ return;
+ }
+}
+
+
+/**
+ * Function called when the complete information about a provider
+ * was added to @a new_state.
+ *
+ * @param cls a `struct RecoveryStartStateProviderEntry`
+ * @param error error code
+ * @param new_state resulting new state
+ */
+static void
+provider_added_cb (void *cls,
+ enum TALER_ErrorCode error,
+ json_t *new_state)
+{
+ struct RecoveryStartStateProviderEntry *pe = cls;
+
+ pe->ra = NULL;
+ pe->istate = json_incref (new_state);
+ pe->ec = error;
+ pe->rss->pending--;
+ if (0 == pe->rss->pending)
+ providers_complete (pe->rss);
+}
+
+
struct ANASTASIS_ReduxAction *
ANASTASIS_REDUX_recovery_challenge_begin_ (json_t *state,
const json_t *arguments,
@@ -1093,67 +1330,44 @@ ANASTASIS_REDUX_recovery_challenge_begin_ (json_t
*state,
version = json_object_get (arguments,
"version");
if (NULL != version)
+ {
rss->version = (unsigned int) json_integer_value (version);
+ rss->have_version = true;
+ }
rss->state = json_incref (state);
rss->cb = cb;
rss->cb_cls = cb_cls;
+ rss->pending = 1; /* decremented after initialization loop */
{
- bool launched = false;
- json_t *p_cfg;
- const char *provider_url;
-
- json_object_foreach (providers, provider_url, p_cfg)
- {
- struct PolicyDownloadEntry *pd = GNUNET_new (struct PolicyDownloadEntry);
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("salt",
- &pd->salt),
- GNUNET_JSON_spec_end ()
- };
-
- GNUNET_CONTAINER_DLL_insert (rss->pd_head,
- rss->pd_tail,
- pd);
- pd->backend_url = GNUNET_strdup (provider_url);
- if (GNUNET_OK !=
- GNUNET_JSON_parse (p_cfg,
- spec,
- NULL, NULL))
- {
- GNUNET_break (0);
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "could not begin parse
'authentication_provider' data");
- free_rss (rss);
- return NULL;
- }
- pd->rss = rss;
- pd->recovery = ANASTASIS_recovery_begin (ANASTASIS_REDUX_ctx_,
- rss->id_data,
- (NULL != version)
- ? rss->version
- : 0,
- pd->backend_url,
- &pd->salt,
- &policy_lookup_cb,
- pd,
- NULL,
- NULL);
- if (NULL != pd->recovery)
- launched = true;
+ json_t *prov;
+ const char *url;
+ json_object_foreach (providers, url, prov) {
+ struct RecoveryStartStateProviderEntry *pe;
+ json_t *istate;
+
+ pe = GNUNET_new (struct RecoveryStartStateProviderEntry);
+ pe->rss = rss;
+ istate = json_object ();
+ GNUNET_assert (NULL != istate);
+ GNUNET_CONTAINER_DLL_insert (rss->pe_head,
+ rss->pe_tail,
+ pe);
+ pe->ra = ANASTASIS_REDUX_add_provider_to_state_ (url,
+ istate,
+ &provider_added_cb,
+ pe);
+ json_decref (istate);
+ if (NULL != pe->ra)
+ rss->pending++;
}
- if (! launched)
- {
- GNUNET_break (0);
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- "Failed to begin recovery operation");
- free_rss (rss);
+ }
+ rss->pending--;
+ if (0 == rss->pending)
+ {
+ providers_complete (rss);
+ if (NULL == rss->cb)
return NULL;
- }
}
rss->ra.cleanup = &free_rss;
rss->ra.cleanup_cls = rss;
diff --git a/src/restclient/anastasis_api_policy_lookup.c
b/src/restclient/anastasis_api_policy_lookup.c
index 2bc225e..a8a0dfb 100644
--- a/src/restclient/anastasis_api_policy_lookup.c
+++ b/src/restclient/anastasis_api_policy_lookup.c
@@ -164,13 +164,10 @@ handle_policy_lookup_finished (void *cls,
response_code = 0;
break;
}
- if (NULL != plo->cb)
- {
- plo->cb (plo->cb_cls,
- response_code,
- NULL);
- plo->cb = NULL;
- }
+ plo->cb (plo->cb_cls,
+ response_code,
+ NULL);
+ plo->cb = NULL;
ANASTASIS_policy_lookup_cancel (plo);
}
@@ -238,18 +235,19 @@ handle_header (char *buffer,
struct ANASTASIS_PolicyLookupOperation *
-ANASTASIS_policy_lookup (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct
- ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
- ANASTASIS_PolicyLookupCallback cb,
- void *cb_cls)
+ANASTASIS_policy_lookup (
+ struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
+ ANASTASIS_PolicyLookupCallback cb,
+ void *cb_cls)
{
struct ANASTASIS_PolicyLookupOperation *plo;
CURL *eh;
char *acc_pub_str;
char *path;
+ GNUNET_assert (NULL != cb);
plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
plo->account_pub = *anastasis_pub;
acc_pub_str = GNUNET_STRINGS_data_to_string_alloc (anastasis_pub,
@@ -297,6 +295,7 @@ ANASTASIS_policy_lookup_version (
char *path;
char version_s[14];
+ GNUNET_assert (NULL != cb);
plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
plo->account_pub = *anastasis_pub;
acc_pub_str = GNUNET_STRINGS_data_to_string_alloc (anastasis_pub,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: work on backup reduxer implementation,
gnunet <=