gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated (c21a333 -> 3f7c3b8)


From: gnunet
Subject: [taler-anastasis] branch master updated (c21a333 -> 3f7c3b8)
Date: Thu, 26 Nov 2020 12:54:07 +0100

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from c21a333  client library update and tests
     new fc1c24b  worked on rec doc upload
     new 25da8a0  fix
     new eea4fd2  worked on rec doc upload
     new 0d9dbd5  work on rec doc upload
     new 98339a2  fix
     new 62170bf  Merge branch 'master' of ssh://git.taler.net/anastasis
     new 3f7c3b8  worked on rec doc upload

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cli/test_anastasis_reducer_enter_secret.sh |  95 ++++-
 src/cli/test_reducerEUWWNI.conf                | 301 ---------------
 src/include/anastasis.h                        |   4 +-
 src/lib/anastasis.c                            |  46 ++-
 src/lib/anastasis_api_backup_redux.c           | 485 +++++++++++++++++++++++--
 src/lib/anastasis_api_policy_store.c           |   6 +
 src/lib/anastasis_api_redux.c                  |   3 +
 src/lib/testing_cmd_secret_share.c             |   2 +
 8 files changed, 592 insertions(+), 350 deletions(-)
 delete mode 100644 src/cli/test_reducerEUWWNI.conf

diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 63f9c6b..1cac54a 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -21,11 +21,13 @@ function cleanup()
     do
         kill $n 2> /dev/null || true
     done
-    rm -f $SFILE $TFILE $CONF_1 $CONF_2 $CONF_3 $CONF_4 
+    rm -f $SFILE $TFILE $CONF $CONF_1 $CONF_2 $CONF_3 $CONF_4 
     wait
 }
 
 # Install cleanup handler (except for kill -9)
+WALLET_DB=`mktemp test_reducer_walletXXXXXX`
+CONF=`mktemp test_reducerXXXXXX.conf`
 CONF_1=`mktemp test_reducerXXXXXX_1.conf`
 CONF_2=`mktemp test_reducerXXXXXX_2.conf`
 CONF_3=`mktemp test_reducerXXXXXX_3.conf`
@@ -40,6 +42,18 @@ echo -n "Testing for jq"
 jq -h > /dev/null || exit_skip "jq required"
 echo " FOUND"
 
+echo -n "Testing for taler"
+taler-exchange-httpd -h > /dev/null || exit_skip " taler-exchange required"
+taler-merchant-httpd -h > /dev/null || exit_skip " taler-merchant required"
+echo " FOUND"
+
+echo -n "Testing for taler-bank-manage"
+taler-bank-manage --help >/dev/null </dev/null || exit_skip " MISSING"
+echo " FOUND"
+echo -n "Testing for taler-wallet-cli"
+taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING"
+echo " FOUND"
+
 echo -n "Testing for anastasis-httpd"
 anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
 echo " FOUND"
@@ -47,21 +61,81 @@ 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=anastasischeck
+TALER_DB=talercheck
+ANASTASIS_DB=anastasischeck
+
+# delete existing wallet database
+rm -f $WALLET_DB
 
 # Configuration file will be edited, so we create one
 # from the template.
+cp test_reducer.conf $CONF
 cp test_anastasis_reducer.conf $CONF_1
 cp test_anastasis_reducer_1.conf $CONF_2
 cp test_anastasis_reducer_2.conf $CONF_3
 cp test_anastasis_reducer_3.conf $CONF_4
 
+# Clean up
+DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME`
+rm -rf $DATA_DIR || true
+
 # reset database
-dropdb $TARGET_DB >/dev/null 2>/dev/null || true
-createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
+dropdb $TALER_DB >/dev/null 2>/dev/null || true
+createdb $TALER_DB || exit_skip "Could not create database $TALER_DB"
+dropdb $ANASTASIS_DB >/dev/null 2>/dev/null || true
+createdb $ANASTASIS_DB || exit_skip "Could not create database $ANASTASIS_DB"
+
+# obtain key configuration data
+MASTER_PRIV_FILE=`taler-config -f -c $CONF -s EXCHANGE -o MASTER_PRIV_FILE`
+MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE`
+mkdir -p $MASTER_PRIV_DIR
+gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null
+MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE`
+EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
+MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT`
+MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
+BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
+BANK_URL=http://localhost:${BANK_PORT}/
+AUDITOR_URL=http://localhost:8083/
+
+# patch configuration
+taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB
+taler-config -c $CONF -s merchant-exchange-default -o MASTER_KEY -V $MASTER_PUB
+# FIXME: SQL_DIR not usefull in general
+taler-config -c $CONF -s exchangedb-postgres -o SQL_DIR -V 
${HOME}/.local/share/taler/sql/exchange/
+taler-config -c $CONF -s exchangedb-postgres -o CONFIG -V postgres:///$TALER_DB
+# FIXME: SQL_DIR not usefull in general
+taler-config -c $CONF -s auditordb-postgres -o SQL_DIR -V 
${HOME}/.local/share/taler/sql/exchange/
+taler-config -c $CONF -s auditordb-postgres -o CONFIG -V postgres:///$TALER_DB
+taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TALER_DB
+taler-config -c $CONF -s bank -o database -V postgres:///$TALER_DB
+
+# setup exchange
+echo "Setting up exchange"
+taler-exchange-dbinit -c $CONF
+taler-exchange-wire -c $CONF 2> taler-exchange-wire.log
+taler-exchange-keyup -L INFO -c $CONF -o e2a.dat 2> taler-exchange-keyup.log
+
+# setup auditor
+echo "Setting up auditor"
+taler-auditor-dbinit -c $CONF
+taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL
+taler-auditor-sign -c $CONF -u $AUDITOR_URL -r e2a.dat -o a2e.dat -m 
$MASTER_PUB
+rm -f e2a.dat
+
+# provide auditor's signature to exchange
+ABD=`taler-config -c $CONF -s EXCHANGEDB -o AUDITOR_BASE_DIR -f`
+mkdir -p $ABD
+mv a2e.dat $ABD
 
 # Launch services
 echo "Launching anastasis service"
+taler-bank-manage-testing $CONF postgres:///$TALER_DB serve &
+taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log &
+taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
+taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log &
+taler-auditor-httpd -c $CONF 2> taler-auditor-httpd.log &
+
 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 &
@@ -73,6 +147,14 @@ do
     echo -n "."
     sleep 0.1
     OK=0
+    # exchange
+    wget http://localhost:8081/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # merchant
+    wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # bank
+    wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    # Auditor
+    wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || 
continue
     # anastasis_01
     wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || 
continue
     # anastasis_02
@@ -90,6 +172,11 @@ then
     exit_skip "Failed to launch anastasis services"
 fi
 
+# Setup merchant
+
+curl -H "Content-Type: application/json" -X POST -d 
'{"payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1",
 
"default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms"
 : 3600000},"default_pay_delay":{"d_ms": 3600000}}' 
http://localhost:9966/private/instances
+
+
 echo " ANASTASIS SETUP DONE"
 echo " "
 echo " "
diff --git a/src/cli/test_reducerEUWWNI.conf b/src/cli/test_reducerEUWWNI.conf
deleted file mode 100644
index ca7a6e9..0000000
--- a/src/cli/test_reducerEUWWNI.conf
+++ /dev/null
@@ -1,301 +0,0 @@
-# This file is in the public domain.
-#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_anastasis_api_home/
-
-# Persistent data storage
-TALER_DATA_HOME = $TALER_TEST_HOME/.local/share/taler/
-
-# Configuration files
-TALER_CONFIG_HOME = $TALER_TEST_HOME/.config/taler/
-
-# Cached data, no big deal if lost
-TALER_CACHE_HOME = $TALER_TEST_HOME/.cache/taler/
-
-[taler]
-# What currency do we use?
-#currency = EUR
-currency = TESTKUDOS
-#CURRENCY_ROUND_UNIT = EUR:0.01
-#CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
-
-[bank]
-HTTP_PORT = 8082
-#BASE_URL = https://bank.test.taler.net/
-
-##########################################
-# Configuration for Anastasis #
-##########################################
-
-[anastasis]
-PORT = 8086
-
-DB = postgres
-
-# Base URL of anastasis.
-# BASE_URL = http://localhost:8086/
-
-# Where does our payment backend run?  Must match PORT under [merchant]
-PAYMENT_BACKEND_URL = http://localhost:8080/
-
-# Annual fee we charge.
-#ANNUAL_FEE = EUR:4.99
-ANNUAL_FEE = TESTKUDOS:4.99
-#ANNUAL_FEE = EUR:0
-
-# Cost of authentication by question
-#QUESTION_COST = EUR:0
-QUESTION_COST = TESTKUDOS:0
-
-# Upload limit
-UPLOAD_LIMIT_MB = 1
-
-SUPPORTED_METHODS = question
-
-# Insurance
-INSURANCE = TESTKUDOS:1.0
-
-# This specifies which database the postgres backend uses.
-[anastasisdb-postgres]
-CONFIG = postgres:///anastasischeck
-
-##########################################
-# Configuration for the merchant backend #
-##########################################
-
-[test]
-INSTANCES = default tor
-
-[merchant]
-
-# Which port do we run the backend on? (HTTP server)
-PORT = 8080
-
-# How quickly do we want the exchange to send us our money?
-# Used only if the frontend does not specify a value.
-WIRE_TRANSFER_DELAY = 0 s
-
-# Which plugin (backend) do we use for the DB.
-DB = postgres
-
-# Default choice for maximum wire fee.
-DEFAULT_MAX_WIRE_FEE = TESTKUDOS:0.10
-
-# Default choice for maximum deposit fee.
-DEFAULT_MAX_DEPOSIT_FEE = TESTKUDOS:0.10
-
-
-# This specifies which database the postgres backend uses.
-[merchantdb-postgres]
-CONFIG = postgres:///talercheck
-
-# Different instances operated by this merchant:
-[instance-default]
-KEYFILE = ${TALER_CONFIG_HOME}/merchant/default.priv
-NAME = Kudos Inc.
-
-# Account of the MERCHANT
-[merchant-account-merchant]
-# What is the merchant's bank account?
-PAYTO_URI = "payto://x-taler-bank/localhost:8082/3"
-
-# This is the *salted* response we give out for /contract requests.
-# File is generated on first use, no need for merchants to generate
-# the salt!
-WIRE_RESPONSE = ${TALER_CONFIG_HOME}/merchant/account-3.json
-
-# Accept payments to this account in instance-default
-HONOR_default = YES
-
-# Advertise in new contracts of instance-default
-ACTIVE_default = YES
-
-# Sections starting with "exchange-" specify trusted exchanges
-# (by the merchant)
-[merchant-exchange-default]
-#MASTER_KEY = T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG
-#EXCHANGE_BASE_URL = http://localhost:8081/
-MASTER_KEY = DY95EXAHQ2BKM2WK9YHZHYG1R7PPMMJPY14FNGP662DAKE35AKQG
-EXCHANGE_BASE_URL = https://exchange.test.taler.net/
-#CURRENCY = EUR
-CURRENCY = TESTKUDOS
-
-
-
-# only fixes skips.
-[auditor]
-BASE_URL = http://the.auditor/
-#BASE_URL = https://auditor.test.taler.net/
-#AUDITOR_KEY = DSDASDXAMDAARMNAD53ZA4AFAHA2QADAMAHHASWDAWXN84SDAA11
-# If currency does not match [TALER] section, the auditor
-# will be ignored!
-CURRENCY = TESTKUDOS
-
-# Auditors must be in sections "auditor-", the rest of the section
-# name could be anything.
-[auditor-ezb]
-# Informal name of the auditor. Just for the user.
-NAME = European Central Bank
-
-# URL of the auditor (especially for in the future, when the
-# auditor offers an automated issue reporting system).
-# Not really used today.
-URL = http://taler.ezb.eu/
-
-# This is the important bit: the signing key of the auditor.
-PUBLIC_KEY = 9QXF7XY7E9VPV47B5Z806NDFSX2VJ79SVHHD29QEQ3BG31ANHZ60
-
-# Which currency is this auditor trusted for?
-CURRENCY = TESTKUDOS
-
-
-###################################################
-# Configuration for the exchange for the testcase #
-###################################################
-
-[exchange_keys]
-
-# how long is one signkey valid?
-signkey_duration = 4 weeks
-
-# how long are the signatures with the signkey valid?
-legal_duration = 2 years
-
-# how long do we generate denomination and signing keys
-# ahead of time?
-lookahead_sign = 32 weeks 1 day
-
-# how long do we provide to clients denomination and signing keys
-# ahead of time?
-lookahead_provide = 4 weeks 1 day
-
-
-[exchange]
-# How to access our database
-DB = postgres
-
-# HTTP port the exchange listens to
-#PORT = 8081
-
-# Our public key
-MASTER_PUBLIC_KEY = T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG
-
-# Base URL of the exchange.
-BASE_URL = "http://localhost:8081/";
-#BASE_URL = https://exchange.test.taler.net/
-
-
-##############################################################
-## Added following lines because they were complaint in log ##
-# START
-
-# Where do we store the private keys the exchange needs at
-# runtime? (Denomination and signing keys are then stored
-# in respective subdirectories.)
-KEYDIR = ${TALER_DATA_HOME}/exchange/live-keys/
-
-# Directory where the exchange expects to find revocation
-# certificates (and where taler-exchange-keyup will write them).
-REVOCATION_DIR = ${TALER_DATA_HOME}/exchange/revocations/
-
-# Network configuration for the normal API/service HTTP server
-# serve via tcp socket (on PORT)
-SERVE = tcp
-
-# END
-##############################################################
-
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Account of the EXCHANGE
-[exchange-account-exchange]
-# What is the exchange's bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost:8082/2"
-
-# This is the response we give out for the /wire request.  It provides
-# wallets with the bank information for transfers to the exchange.
-WIRE_RESPONSE = ${TALER_CONFIG_HOME}/exchange/account-2.json
-
-WIRE_GATEWAY_URL = "http://localhost:8082/2/";
-WIRE_GATEWAY_AUTH_METHOD = NONE
-
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-
-# wire fees
-[fees-x-taler-bank]
-
-# Fees for the foreseeable future...
-# If you see this after 2018, update to match the next 10 years...
-WIRE-FEE-2018 = TESTKUDOS:0.01
-WIRE-FEE-2019 = TESTKUDOS:0.01
-WIRE-FEE-2020 = TESTKUDOS:0.01
-WIRE-FEE-2021 = TESTKUDOS:0.01
-WIRE-FEE-2022 = TESTKUDOS:0.01
-WIRE-FEE-2023 = TESTKUDOS:0.01
-WIRE-FEE-2024 = TESTKUDOS:0.01
-WIRE-FEE-2025 = TESTKUDOS:0.01
-WIRE-FEE-2026 = TESTKUDOS:0.01
-WIRE-FEE-2027 = TESTKUDOS:0.01
-CLOSING-FEE-2018 = TESTKUDOS:0.01
-CLOSING-FEE-2019 = TESTKUDOS:0.01
-CLOSING-FEE-2020 = TESTKUDOS:0.01
-CLOSING-FEE-2021 = TESTKUDOS:0.01
-CLOSING-FEE-2022 = TESTKUDOS:0.01
-CLOSING-FEE-2023 = TESTKUDOS:0.01
-CLOSING-FEE-2024 = TESTKUDOS:0.01
-CLOSING-FEE-2025 = TESTKUDOS:0.01
-CLOSING-FEE-2026 = TESTKUDOS:0.01
-CLOSING-FEE-2027 = TESTKUDOS:0.01
-
-
-[coin_eur_ct_1]
-value = TESTKUDOS:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.00
-fee_deposit = TESTKUDOS:0.00
-fee_refresh = TESTKUDOS:0.01
-fee_refund = TESTKUDOS:0.01
-rsa_keysize = 1024
-
-[coin_eur_ct_10]
-value = TESTKUDOS:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_refund = TESTKUDOS:0.01
-rsa_keysize = 1024
-
-[coin_eur_1]
-value = TESTKUDOS:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_refund = TESTKUDOS:0.01
-rsa_keysize = 1024
-
-[coin_eur_5]
-value = TESTKUDOS:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_refund = TESTKUDOS:0.01
-rsa_keysize = 1024
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 5541f4a..705ed89 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -388,13 +388,15 @@ ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p);
  *
  * @param cls closure
  * @param @param current_etag sends back the etag of the upload (used to 
prevent redundant uploads)
+ * @param server_url url of the server to pay for
  * @param ec status code of the request
  * @param http_status http status code
  */
 typedef void
 (*ANASTASIS_ShareResultCallback)(void *cls,
                                  const struct GNUNET_HashCode *current_etag,
-                                 const enum TALER_ErrorCode ecs,
+                                 const char *server_url,
+                                 const enum TALER_ErrorCode ec,
                                  unsigned int http_status);
 
 /**
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index a9702d9..4e81a4c 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1584,7 +1584,31 @@ policy_store_cb (void *cls,
   struct PolicyStoreState *pss = cls;
   pss->pso = NULL;
   pss->ec = ec;
-
+  if ((http_status != pss->http_status) &&
+      (http_status != MHD_HTTP_PAYMENT_REQUIRED))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u/%d in %s:%u\n",
+                http_status,
+                (int) ec,
+                __FILE__,
+                __LINE__);
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ec,
+                               "hint",
+                               "Unexpected response code!");
+    if (NULL != pss->ss->src)
+    {
+      pss->ss->src (pss->ss->src_cls,
+                    &pss->curr_hash,
+                    pss->anastasis_url,
+                    ec,
+                    http_status);
+      pss->ss->src = NULL;
+    }
+    return;
+  }
   if (NULL != ud)
   {
     switch (ud->us)
@@ -1649,9 +1673,6 @@ policy_store_cb (void *cls,
                         ec);
           pss->ss->spc = NULL;
         }
-        // FIXME: Wrong place for cleanup!
-        // ANASTASIS_secret_share_cancel (pss->ss);
-        // policy_store_cleanup (pss);
       }
       return;
     case ANASTASIS_US_CONFLICTING_POLICY:
@@ -1669,18 +1690,15 @@ policy_store_cb (void *cls,
       GNUNET_break (0);
       return;
     }
-
     if (NULL != pss->ss->src)
     {
       pss->ss->src (pss->ss->src_cls,
                     &pss->curr_hash,
+                    pss->anastasis_url,
                     ec,
                     http_status);
       pss->ss->src = NULL;
     }
-    // FIXME: Wrong place for cleanup!
-    // ANASTASIS_secret_share_cancel (pss->ss);
-    // policy_store_cleanup (pss);
   }
 }
 
@@ -1829,10 +1847,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
   ss->src_cls = src_cls;
   ss->ctx = ctx;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "At %s:%d pss_length is %d\n", __FILE__, __LINE__,
-              ss->pss_length);
-
   for (unsigned int i = 0; i < policies_len; i++)
   {
     policy_keys[i] = policies[i]->policy_key;
@@ -2034,7 +2048,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
 
   for (unsigned int l = 0; l < ss->pss_length; l++)
   {
-    // ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
+    ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
 
     ANASTASIS_CRYPTO_user_identifier_derive (id_data,
                                              ss->pss[l]->server_salt,
@@ -2073,7 +2087,11 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                                               &ss->pss[l]->payment_secret,
                                               &policy_store_cb,
                                               ss->pss[l]);
-    GNUNET_assert (NULL != ss->pss[l]->pso);
+    if (NULL == ss->pss[l]->pso)
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   }
   return ss;
 }
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index e08736e..a57deca 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -73,6 +73,16 @@ struct TruthUploadState
    */
   const char *anastasis_url;
 
+  /**
+   * Salt of anastasis backend.
+   */
+  struct ANASTASIS_CRYPTO_PowSalt backend_salt;
+
+  /**
+   * Curl context.
+   */
+  struct GNUNET_CURL_Context *ctx;
+
   /**
    * The ID data to generate user identifier
    */
@@ -138,19 +148,106 @@ struct TruthUploadState
    * Redux json state.
    */
   json_t *state;
+
+  /**
+   * User id.
+   */
+  struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
+};
+
+
+/**
+ * State for a "secret share" oparation.
+ */
+struct SecretShareState
+{
+  /**
+   * Claim token we got back, if any. Otherwise all zeros.
+   */
+  struct TALER_ClaimTokenP token;
+
+  /**
+   * Data to derive user identifier from.
+   */
+  const json_t *id_data;
+
+  /**
+   * The core secret to backup/recover.
+   */
+  const void *core_secret;
+
+  /**
+   * Size of core_secret.
+   */
+  size_t core_secret_size;
+
+  /**
+   * URL of the anastasis backend.
+   */
+  const char *anastasis_url;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * The /truth GET operation handle.
+   */
+  struct ANASTASIS_SecretShare *sso;
+
+  /**
+   * closure for the payment callback
+   */
+  void *spc_cls;
+
+  /**
+   * closure for the result callback
+   */
+  void *src_cls;
+
+  /**
+   * Payment order ID we got back, if any. Otherwise NULL.
+   */
+  char *payment_order_id;
+
+  /**
+   * Action callback.
+   */
+  ANASTASIS_ActionCallback cb;
+
+  /**
+   * Closure for action callback #cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Json state.
+   */
+  json_t *state;
 };
 
 
 /**
  * Array of truth upload states.
  */
-static struct TruthUploadState *tus_arr;
+static struct TruthUploadState **tus_arr;
 
 /**
  * The length of the #tus_arr array.
  */
 static unsigned int tus_arr_length;
 
+/**
+ * Array of policies.
+ */
+const static struct ANASTASIS_Policy **policy_arr;
+
+/**
+ * The length of the #tus_arr array.
+ */
+static unsigned int policy_arr_length = 0;
+
 
 /**
  * Callback function FIXME: Description.
@@ -1062,7 +1159,6 @@ check_uploads (json_t *uploads)
   GNUNET_assert (json_is_array (uploads));
   size_t index;
   json_t *upload;
-  bool pass = true;
 
   json_array_foreach (uploads, index, upload)
   {
@@ -1070,11 +1166,302 @@ check_uploads (json_t *uploads)
                                                       "status"));
     if (status != 204)
     {
-      pass = false;
+      return false;
+    }
+  }
+  return true;
+}
+
+
+/**
+ * Initialize policies for recovery document.
+ *
+ * @param state json state to operate on
+ */
+static void
+initialize_policies (json_t *state)
+{
+  size_t p_index;
+  json_t *json_policy;
+  json_t *json_policies = json_object_get (state,
+                                           "policies");
+
+  GNUNET_assert (json_is_array (json_policies));
+  json_array_foreach (json_policies, p_index, json_policy)
+  {
+    size_t index;
+    unsigned int truth_index = 0;
+    json_t *auth_method;
+    json_t *auth_method_arr = json_object_get (json_policy,
+                                               "methods");
+    const struct ANASTASIS_Truth *truths[json_array_size (auth_method_arr)];
+
+    json_array_foreach (auth_method_arr,
+                        index,
+                        auth_method)
+    {
+      unsigned int auth_method_index = json_integer_value (json_object_get (
+                                                             auth_method,
+                                                             
"authentication_method"));
+      GNUNET_assert (NULL != tus_arr[0]->truth);
+      GNUNET_assert (NULL != tus_arr[auth_method_index]->truth);
+      truths[truth_index] = tus_arr[auth_method_index]->truth;
+      truth_index++;
+    }
+    struct ANASTASIS_Policy *policy = ANASTASIS_policy_create (truths,
+                                                               truth_index);
+    GNUNET_array_append (policy_arr,
+                         policy_arr_length,
+                         policy);
+  }
+}
+
+
+/**
+ * Function called for payment routine for secret sharing.
+ *
+ * @param cls closure
+ * @param taler_pay_url url for the payment (taler://pay/Foo)
+ * @param server_url url of the server to pay for
+ * @param ec status of the request
+ */
+static void
+secret_share_payment_cb (void *cls,
+                         const char *taler_pay_url,
+                         const char *server_url,
+                         enum TALER_ErrorCode ec)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d we are in SPC\n",
+              __FILE__, __LINE__);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d the taler pay url is %s\n",
+              __FILE__, __LINE__,
+              taler_pay_url);
+
+  const char *m;
+  size_t index;
+  json_t *upload;
+  struct SecretShareState *sss = cls;
+  json_t *rec_doc_uploads = json_object_get (sss->state,
+                                             "recovery_document_uploads");
+
+  GNUNET_assert (json_is_array (rec_doc_uploads));
+  sss->sso = NULL;
+
+  json_array_foreach (rec_doc_uploads, index, upload)
+  {
+    const char *url = json_string_value (
+      json_object_get (upload,
+                       "backend_url"));
+    if (0 == strcmp (url, server_url))
+    {
+      GNUNET_assert (0 ==
+                     json_object_set (upload,
+                                      "status",
+                                      json_integer ((json_int_t) 402)));
+      GNUNET_assert (0 ==
+                     json_object_set (upload,
+                                      "pay_url",
+                                      json_string (taler_pay_url)));
       break;
     }
   }
-  return pass;
+
+  m = strstr (taler_pay_url, "/-/-/");
+  if (NULL == m)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Did not find `%s' in `%s'\n",
+                "/-/-/",
+                taler_pay_url);
+    GNUNET_break (0);
+    /* NOTE: The above is a simplifying assumption for the
+        test-logic, hitting this code merely means that
+        the assumptions for the test (i.e. no instance) are
+        not satisfied, it is not inherently the case that
+        the above token must appear in the payment request!
+
+        So if you hit this, you might just want to modify
+        the code here to handle this better! */
+    return;
+  }
+  sss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d Order ID from Anastasis service is %s\n",
+              __FILE__, __LINE__,
+              sss->payment_order_id);
+  set_state (sss->state,
+             ANASTASIS_backup_state_to_string (
+               ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+  sss->cb (sss->cb_cls,
+           ANASTASIS_EC_NONE,
+           sss->state);
+  // FIXME: payment
+}
+
+
+/**
+ * Function called with the results of a #secret_share().
+ *
+ * @param cls closure
+ * @param @param current_etag sends back the etag of the upload (used to 
prevent redundant uploads)
+ * @param server_url url of the server to pay for
+ * @param ec status code of the request
+ * @param http_status http status code
+ */
+static void
+secret_share_result_cb (void *cls,
+                        const struct GNUNET_HashCode *current_etag,
+                        const char *server_url,
+                        const enum TALER_ErrorCode ec,
+                        unsigned int http_status)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "At %s:%d we are in SRC\n",
+              __FILE__, __LINE__);
+
+  size_t index;
+  json_t *upload;
+  struct SecretShareState *sss = cls;
+  json_t *rec_doc_uploads = json_object_get (sss->state,
+                                             "recovery_document_uploads");
+
+  GNUNET_assert (json_is_array (rec_doc_uploads));
+  sss->sso = NULL;
+
+  json_array_foreach (rec_doc_uploads, index, upload)
+  {
+    const char *url = json_string_value (
+      json_object_get (upload,
+                       "backend_url"));
+    if (0 == strcmp (url, server_url))
+    {
+      GNUNET_assert (0 ==
+                     json_object_set (upload,
+                                      "status",
+                                      json_integer ((json_int_t) 
http_status)));
+      break;
+    }
+  }
+
+  if (NULL != sss)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d etag is %s-%llu b\n", __FILE__, __LINE__,
+                TALER_B2S (&current_etag),
+                (unsigned long long) sizeof (struct GNUNET_HashCode));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d error code is %d\n", __FILE__, __LINE__,
+                ec);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "At %s:%d http status is %u\n", __FILE__, __LINE__,
+                http_status);
+
+    if (check_uploads (rec_doc_uploads))
+    {
+      set_state (sss->state,
+                 ANASTASIS_backup_state_to_string (
+                   ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
+    }
+    if (http_status == sss->http_status)
+    {
+      sss->cb (sss->cb_cls,
+               ANASTASIS_EC_NONE,
+               sss->state);
+      return;
+    }
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ec,
+                               "hint",
+                               "Unexpected response code!");
+    sss->cb (sss->cb_cls,
+             ANASTASIS_EC_INVALID,  // FIXME: ERROR CODE
+             error);
+    return;
+  }
+  GNUNET_break (0);
+}
+
+
+/**
+ * Upload recovery documents.
+ *
+ * @param state json state to operate on
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ */
+static void
+upload_rec_documents (json_t *state,
+                      struct GNUNET_CURL_Context *ctx,
+                      ANASTASIS_ActionCallback cb,
+                      void *cb_cls)
+{
+  if (0 == policy_arr_length)
+  {
+    initialize_policies (state);
+  }
+  struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
+
+  sss->cb = cb;
+  sss->cb_cls = cb_cls;
+  sss->http_status = MHD_HTTP_NO_CONTENT;
+
+  GNUNET_assert (NULL !=
+                 (sss->id_data = json_object_get (state,
+                                                  "identity_attributes")));
+  GNUNET_assert (NULL !=
+                 (sss->core_secret = json_object_get (state,
+                                                      "core_secret")));
+  json_t *core_secret = json_object_get (state,
+                                         "core_secret");
+  const char *secret_type = json_string_value (
+    json_object_get (core_secret,
+                     "type"));
+  if (0 == strcmp (secret_type, "password"))
+  {
+    sss->core_secret = json_string_value (
+      json_object_get (core_secret,
+                       "secret"));
+    sss->core_secret_size = strlen (sss->core_secret);
+  }
+  else
+  {
+    const char *string_secret = json_string_value (
+      json_object_get (core_secret,
+                       "secret"));
+    sss->core_secret_size = (size_t) json_integer_value (
+      json_object_get (core_secret,
+                       "size"));
+    GNUNET_STRINGS_string_to_data (string_secret,
+                                   strlen (string_secret),
+                                   (void *) sss->core_secret,
+                                   sss->core_secret_size);
+  }
+  sss->state = json_incref (state);
+  // FIXME: implement PaymentDetails
+  sss->sso = ANASTASIS_secret_share (ctx,
+                                     sss->id_data,
+                                     NULL,
+                                     policy_arr,
+                                     policy_arr_length,
+                                     NULL,
+                                     0,
+                                     &secret_share_payment_cb,
+                                     sss,
+                                     &secret_share_result_cb,
+                                     sss,
+                                     sss->core_secret,
+                                     sss->core_secret_size);
+
+  if (NULL == sss->sso)
+  {
+    GNUNET_break (0);
+    return;
+  }
 }
 
 
@@ -1100,9 +1487,9 @@ truth_upload_cb (void *cls,
                           "enter_secret or pay");
     return;
   }
-  json_t *uploads = json_object_get (tus->state,
-                                     "truth_uploads");
-  json_t *truth_upload = json_array_get (uploads,
+  json_t *truth_uploads = json_object_get (tus->state,
+                                           "truth_uploads");
+  json_t *truth_upload = json_array_get (truth_uploads,
                                          tus->index);
   GNUNET_assert (NULL != truth_upload);
   GNUNET_assert (0 ==
@@ -1111,17 +1498,53 @@ truth_upload_cb (void *cls,
                                   json_integer ((json_int_t) 204)));
   tus->truth = t;
 
-
-  if (check_uploads (uploads))
+  if (check_uploads (truth_uploads) &&
+      (json_array_size (
+         json_object_get (tus->state, "truths"))
+       == (size_t) tus_arr_length))
   {
-    set_state (tus->state,
-               ANASTASIS_backup_state_to_string (
-                 ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
-  }
+    // try uploading recovery document
+    size_t t_index;
+    size_t rd_index;
+    json_t *truth;
+    json_t *truths = json_object_get (tus->state,
+                                      "truths");
+    json_t *rec_doc_uploads = json_array ();
 
-  tus->cb (tus->cb_cls,
-           ANASTASIS_EC_NONE,
-           tus->state);
+    GNUNET_assert (json_is_array (truths));
+    GNUNET_assert (json_is_array (rec_doc_uploads));
+    json_array_foreach (truths, t_index, truth)
+    {
+      json_t *upload;
+      json_t *backend_url = json_object_get (truth,
+                                             "backend_url");
+
+      json_array_foreach (rec_doc_uploads, rd_index, upload)
+      {
+        if (1 == json_equal (backend_url, json_object_get (upload,
+                                                           "backend_url")))
+          break;
+
+        GNUNET_assert (0 ==
+                       json_object_set_new (upload,
+                                            "backend_url",
+                                            backend_url));
+        GNUNET_assert (0 ==
+                       json_object_set_new (upload,
+                                            "status",
+                                            json_integer ((json_int_t) 0)));
+      }
+    }
+    GNUNET_assert (0 ==
+                   json_object_set_new (tus->state,
+                                        "recovery_document_uploads",
+                                        rec_doc_uploads));
+
+    upload_rec_documents (tus->state,
+                          tus->ctx,
+                          tus->cb,
+                          tus->cb_cls);
+  }
 }
 
 
@@ -1237,10 +1660,8 @@ enter_secret (json_t *state,
     json_array_foreach (truths, truth_index, truth)
     {
       struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
-      struct ANASTASIS_CRYPTO_PowSalt backend_salt;
-      struct ANASTASIS_CRYPTO_UserIdentifierP user_id;
-      const char *backend_url = json_string_value (json_object_get (truth,
-                                                                    
"backend_url"));
+      tus->anastasis_url = json_string_value (json_object_get (truth,
+                                                               "backend_url"));
       tus->state = json_incref (state);
       tus->method = json_string_value (json_object_get (truth,
                                                         "method"));
@@ -1252,13 +1673,14 @@ enter_secret (json_t *state,
                                                                  
"backend_salt"));
       GNUNET_STRINGS_string_to_data (salt_str,
                                      strlen (salt_str),
-                                     &backend_salt,
+                                     &tus->backend_salt,
                                      sizeof (struct ANASTASIS_CRYPTO_PowSalt));
       tus->id_data = json_object_get (state,
                                       "identity_attributes");
       tus->index = truth_index;
       tus->cb = cb;
       tus->cb_cls = cb_cls;
+      tus->ctx = ctx;
 
       if (0 == strcmp ("question", tus->method))
       {
@@ -1278,28 +1700,31 @@ enter_secret (json_t *state,
                                                              "truth_uploads"),
                                             truth_upload));
       ANASTASIS_CRYPTO_user_identifier_derive (tus->id_data,
-                                               &backend_salt,
-                                               &user_id);
+                                               &tus->backend_salt,
+                                               &tus->user_id);
       GNUNET_array_append (tus_arr,
                            tus_arr_length,
-                           *tus);
-      tus->tuo = ANASTASIS_truth_upload (ctx,
-                                         &user_id,
-                                         backend_url,
+                           tus);
+      tus->tuo = ANASTASIS_truth_upload (tus->ctx,
+                                         &tus->user_id,
+                                         tus->anastasis_url,
                                          tus->method,
                                          tus->instructions,
                                          tus->mime_type,
-                                         &backend_salt,
+                                         &tus->backend_salt,
                                          tus->truth_data,
                                          tus->truth_data_size,
                                          &truth_payment_cb,
                                          tus,
                                          &truth_upload_cb,
                                          tus);
+      if (NULL == tus->tuo)
+      {
+        GNUNET_break (0);
+        return NULL;
+      }
     }
   }
-
-  // try uploading recovery document
   return NULL;
 }
 
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index ad9a839..d1418f6 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -184,6 +184,12 @@ handle_policy_store_finished (void *cls,
     ec = TALER_JSON_get_error_code2 (data,
                                      data_size);
     break;
+  case MHD_HTTP_INTERNAL_SERVER_ERROR:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Internal server error: `%.*s\n",
+                (int) data_size,
+                (const char *) data);
+    break;
   }
   if (NULL != pso->cb)
   {
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 8100b9e..2bbc4f6 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -174,6 +174,9 @@ struct SelectCountryHandle
    */
   ANASTASIS_ActionCallback cb;
 
+  /**
+   * Closure for action callback #cb.
+   */
   void *cb_cls;
 };
 
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index 8e1edb4..6669821 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -196,12 +196,14 @@ secret_share_payment_cb (void *cls,
  *
  * @param cls closure
  * @param @param current_etag sends back the etag of the upload (used to 
prevent redundant uploads)
+ * @param server_url url of the server to pay for
  * @param ec status code of the request
  * @param http_status http status code
  */
 static void
 secret_share_result_cb (void *cls,
                         const struct GNUNET_HashCode *current_etag,
+                        const char *server_url,
                         const enum TALER_ErrorCode ec,
                         unsigned int http_status)
 {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]