[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/07: worked on rec doc upload
From: |
gnunet |
Subject: |
[taler-anastasis] 01/07: worked on rec doc upload |
Date: |
Thu, 26 Nov 2020 12:54:08 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit fc1c24bae7aa7add8824c385450fef22dc3dedd9
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Nov 24 15:57:49 2020 +0100
worked on rec doc upload
---
src/lib/anastasis_api_backup_redux.c | 360 ++++++++++++++++++++++++++++++++---
src/lib/anastasis_api_redux.c | 3 +
2 files changed, 338 insertions(+), 25 deletions(-)
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index e08736e..845358d 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,6 +148,83 @@ 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;
};
@@ -151,6 +238,16 @@ static struct TruthUploadState *tus_arr;
*/
static unsigned int tus_arr_length;
+/**
+ * Array of policies.
+ */
+static struct ANASTASIS_Policy **policy_arr;
+
+/**
+ * The length of the #tus_arr array.
+ */
+static unsigned int policy_arr_length;
+
/**
* Callback function FIXME: Description.
@@ -1078,6 +1175,215 @@ check_uploads (json_t *uploads)
}
+/**
+ * Initialize policies for recovery document.
+ *
+ * @param state json state to operate on
+ */
+static void
+initialize_policies (json_t *state)
+{
+ size_t 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, index, json_policy)
+ {
+ struct ANASTASIS_Truth *truths;
+ unsigned int truth_length;
+ size_t auth_method_index;
+ json_t *auth_method;
+
+ json_array_foreach (json_object_get (json_policy, "methods"),
+ auth_method_index,
+ auth_method)
+ {
+ unsigned int truth_index = json_integer_value (json_object_get (
+ auth_method,
+ "auth_method_index"));
+ GNUNET_array_append (truths,
+ truth_length,
+ tus_arr[truth_index].truth);
+ }
+ struct ANASTASIS_Policy *policy = ANASTASIS_policy_create (truths,
+ truth_length);
+ 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)
+{
+ 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__);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "At %s:%d the taler pay url is %s\n",
+ __FILE__, __LINE__,
+ taler_pay_url);
+
+ 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);
+
+ // 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 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);
+
+ sss->cb (sss->cb_cls,
+ ANASTASIS_EC_NONE,
+ sss->state);
+ 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 (! policy_arr_length)
+ {
+ initialize_policies (state);
+ }
+ struct SecretShareState *sss = cls;
+ GNUNET_assert (0 ==
+ (sss->id_data = json_object_get (state,
+ "identity_attributes")));
+ GNUNET_assert (0 ==
+ (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);
+ }
+ // 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;
+ }
+}
+
+
/**
* Upload information
* caller MUST free 't' using ANASTASIS_truth_free()
@@ -1100,9 +1406,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 +1417,19 @@ truth_upload_cb (void *cls,
json_integer ((json_int_t) 204)));
tus->truth = t;
-
- if (check_uploads (uploads))
+ if (check_uploads (truth_uploads))
{
- set_state (tus->state,
- ANASTASIS_backup_state_to_string (
- ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
+ // try uploading recovery document
+ GNUNET_assert (0 ==
+ json_object_set (state,
+ "recovery_document_uploads",
+ json_array ()));
+
+ upload_rec_documents (tus->state,
+ tus->ctx,
+ tus->cb,
+ tus->cb_cls);
}
-
- tus->cb (tus->cb_cls,
- ANASTASIS_EC_NONE,
- tus->state);
}
@@ -1237,10 +1545,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 +1558,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 +1585,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->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_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;
};
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (c21a333 -> 3f7c3b8), gnunet, 2020/11/26
- [taler-anastasis] 02/07: fix, gnunet, 2020/11/26
- [taler-anastasis] 05/07: fix, gnunet, 2020/11/26
- [taler-anastasis] 03/07: worked on rec doc upload, gnunet, 2020/11/26
- [taler-anastasis] 01/07: worked on rec doc upload,
gnunet <=
- [taler-anastasis] 04/07: work on rec doc upload, gnunet, 2020/11/26
- [taler-anastasis] 06/07: Merge branch 'master' of ssh://git.taler.net/anastasis, gnunet, 2020/11/26
- [taler-anastasis] 07/07: worked on rec doc upload, gnunet, 2020/11/26