[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 03/03: worked on splitter...
From: |
gnunet |
Subject: |
[taler-anastasis] 03/03: worked on splitter... |
Date: |
Wed, 20 May 2020 23:51:50 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 445ff4d1b251135d010d37b23dd5acb67d14762b
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed May 20 21:51:32 2020 +0000
worked on splitter...
---
src/cli/anastasis-cli-splitter.c | 335 +++++++++++++++++++++++++++++++++++++--
src/lib/anastasis.c | 3 +-
2 files changed, 328 insertions(+), 10 deletions(-)
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index a1310eb..38b663f 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -33,9 +33,9 @@
struct TruthUploadState
{
/**
- * Label of this command.
+ * Index of the truth.
*/
- const char *label;
+ unsigned int index;
/**
* The ID data to generate user identifier
@@ -209,6 +209,84 @@ struct ConfigState
// FIXME add configs
};
+/**
+ * State for a "policy create" CMD.
+ */
+struct PolicyCreateState
+{
+ /**
+ * Array of References to TruthUploadStates.
+ */
+ struct TruthUploadState **tu_states;
+
+ /**
+ * Lengths of truths.
+ */
+ unsigned int tu_states_len;
+
+ /**
+ * Policy object
+ */
+ const struct ANASTASIS_Policy *policy;
+};
+
+/**
+ * State for a "secret share" CMD.
+ */
+struct SecretShareState
+{
+ /**
+ * 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.
+ */
+ const char *payment_order_id;
+
+ /**
+ * Details of a past payment
+ */
+ struct ANASTASIS_PaymentDetails *pd;
+};
+
+
/**
* Global option '--me' to import json containing details of user.
*/
@@ -239,26 +317,157 @@ static struct GNUNET_CURL_RescheduleContext *rc;
*/
static struct TruthUploadState *tu_states;
+/**
+ * Amount of truth upload states
+ */
+static unsigned int tu_states_length = 0;
+
/**
* Information about the servers.
*/
static struct ServerInfo *servers;
/**
- * Amount of truth upload states
+ * Amount of servers.
*/
-static unsigned int tu_states_length = 0;
+static unsigned int servers_length = 0;
/**
- * Amount of servers
+ * State for a "policy create" CMD.
*/
-static unsigned int servers_length = 0;
+static struct PolicyCreateState *pc_states;
+
+/**
+ * Amount of policy create states.
+ */
+static unsigned int pc_states_length = 0;
static void
start_read_keyboard (void);
+/**
+ * Function called for payment routine.
+ *
+ * @param cls closure
+ * @param taler_pay_url url for the payment (taler://pay/Foo)
+ * @param ec status of the request
+ */
+static void
+secret_share_payment_cb (void *cls,
+ const char *taler_pay_url,
+ enum TALER_ErrorCode ec)
+{
+ const char *m;
+ struct SecretShareState *sss = cls;
+ sss->sso = NULL;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d we are in SPC\n",
+ __FILE__, __LINE__);
+ if (sss->http_status != MHD_HTTP_PAYMENT_REQUIRED)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d in %s:%u\n",
+ sss->http_status,
+ (int) ec,
+ __FILE__,
+ __LINE__);
+ GNUNET_break (0);
+ return;
+ }
+
+ if (0 != strncmp (taler_pay_url,
+ "taler://pay/http",
+ strlen ("taler://pay/http")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ taler_pay_url);
+ GNUNET_break (0);
+ return;
+ }
+ m = strstr (taler_pay_url, "/-/-/");
+ if (NULL == m)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find `%s' in `%s'\n",
+ "/-/-/",
+ taler_pay_url);
+ /* 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);
+
+ keyboard_task = NULL;
+ start_read_keyboard ();
+}
+
+
+/**
+ * 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 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 enum TALER_ErrorCode ec,
+ unsigned int http_status)
+{
+ struct SecretShareState *sss = cls;
+ sss->sso = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d we are in SRC\n",
+ __FILE__, __LINE__);
+ if (NULL != sss)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d etag is %s-%llu b\n", __FILE__, __LINE__,
+ TALER_B2S (¤t_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 (http_status != sss->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d in %s:%u\n",
+ http_status,
+ (int) ec,
+ __FILE__,
+ __LINE__);
+ GNUNET_break (0);
+ return;
+ }
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
+ GNUNET_break (0);
+ return;
+}
+
+
/**
* Initiates a callback for the payment of the truth upload
*
@@ -286,6 +495,7 @@ truth_payment_cb (void *cls,
*
* @param cls closure for callback
* @param t Truth object (contains provider url and uuid)
+* @param t_size size of t
*/
static void
truth_upload_cb (void *cls,
@@ -299,6 +509,7 @@ truth_upload_cb (void *cls,
GNUNET_break (0);
return;
}
+ tus->truth = t;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -681,7 +892,7 @@ read_keyboard_command (void *cls)
error.position);
return;
}
-
+ tus->index = (tu_states_length > 0) ? tu_states_length - 1 : 0;
tus->tuo = ANASTASIS_truth_upload (ctx,
tus->id_data,
servers[server_num].backend_url,
@@ -704,8 +915,9 @@ read_keyboard_command (void *cls)
GNUNET_array_append (tu_states,
tu_states_length,
*tus);
- printf ("Truth #%u added",
- tu_states_length);
+ printf ("Truth #%u added for server #%u\n",
+ tus->index,
+ server_num);
}
else
printf ("Sorry, server#%u does not support '%s'\n",
@@ -783,6 +995,23 @@ read_keyboard_command (void *cls)
&& (characters == strlen ("policy")))
{
// FIXME "policy" logic here
+ if (NULL != pc_states)
+ {
+ for (unsigned int i = 0; i < servers_length; i++)
+ {
+ if (NULL != pc_states[i].tu_states)
+ {
+ printf ("Policy#%u: ", i);
+ for (unsigned int j = 0; j < pc_states[i].tu_states_len; j++)
+ printf ("truth#%u ", pc_states[i].tu_states[j]->index);
+ printf ("\n");
+ }
+ else
+ printf ("Policy#%u: no truths added yet\n", i);
+ }
+ }
+ else
+ printf ("Please add a policy before!\n");
GNUNET_free (buffer);
buffer = NULL;
keyboard_task = NULL;
@@ -794,6 +1023,37 @@ read_keyboard_command (void *cls)
strlen ("policy add")))
{
// FIXME "policy add" logic here
+ struct PolicyCreateState *pcs = GNUNET_new (struct PolicyCreateState);
+ char *token_start = &buffer[strlen ("policy add ")];
+ char *token = strtok (token_start, " ");
+ while (token != NULL)
+ {
+ unsigned int tus_index;
+ if (0 != strncmp ("truth#",
+ token,
+ strlen ("truth#")))
+ {
+ printf ("Wrong argument: %s!\n", token);
+ GNUNET_free (buffer);
+ buffer = NULL;
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
+ tus_index = (int) token[strlen ("truth#")] - 48;
+
+ GNUNET_array_append (pcs->tu_states,
+ pcs->tu_states_len,
+ &tu_states[tus_index]);
+ token = strtok (NULL, " ");
+ }
+
+ GNUNET_array_append (pc_states,
+ pc_states_length,
+ *pcs);
+ printf ("Policy #%u defined\n",
+ (pc_states_length > 0) ? pc_states_length - 1 : 0);
+
GNUNET_free (buffer);
buffer = NULL;
keyboard_task = NULL;
@@ -807,6 +1067,63 @@ read_keyboard_command (void *cls)
&& (characters == strlen ("publish")))
{
// FIXME "publish" logic here
+ if (NULL != pc_states)
+ {
+ struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
+ const struct ANASTASIS_Policy *policies[pc_states_length];
+
+ for (unsigned int i = 0; i < pc_states_length; i++)
+ {
+ const struct ANASTASIS_Truth *truths[pc_states[i].tu_states_len];
+
+ for (unsigned int j = 0; j < pc_states[i].tu_states_len; j++)
+ {
+ truths[j] = pc_states[i].tu_states[j]->truth;
+ }
+
+ pc_states[i].policy = ANASTASIS_policy_create (truths,
+ pc_states[i].
+ tu_states_len);
+ policies[i] = pc_states[i].policy;
+ }
+
+ json_error_t error;
+ if (NULL == (sss->id_data = json_load_file (import_id,
+ JSON_DECODE_ANY,
+ &error)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse `%s': %s at %d:%d (%d)\n",
+ import_id,
+ error.text,
+ error.line,
+ error.column,
+ error.position);
+ return;
+ }
+ // core secret here is just for testing, if payment is needed
+ sss->core_secret = "test_payment";
+ sss->core_secret_size = strlen ("test_payment");
+ sss->sso = ANASTASIS_secret_share (ctx,
+ sss->id_data,
+ NULL,
+ policies,
+ pc_states_length,
+ NULL,
+ NULL,
+ &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;
+ }
+ return;
+ }
GNUNET_free (buffer);
buffer = NULL;
keyboard_task = NULL;
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 263c182..de2a9c4 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1118,7 +1118,8 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
if (NULL != tu->tc)
{
tu->tc (tu->tc_cls,
- t);
+ t,
+ sizeof (*t));
tu->tc = NULL;
}
// FIXME PAYMENT CALLBACK
--
To stop receiving notification emails like this one, please contact
address@hidden.