[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/04: playing with pointers...
From: |
gnunet |
Subject: |
[taler-anastasis] 02/04: playing with pointers... |
Date: |
Thu, 07 May 2020 03:26:55 +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 0138994cb143d64e3ae6ecd86141247cf013f3f6
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed May 6 20:45:25 2020 +0000
playing with pointers...
---
src/include/anastasis_testing_lib.h | 8 +-
src/lib/anastasis.c | 151 ++++++++++++++++++++----------------
src/lib/test_anastasis.c | 9 ++-
src/lib/testing_cmd_secret_share.c | 139 +++++++++++++++++++++------------
src/lib/testing_cmd_truth_upload.c | 2 +-
src/lib/testing_trait_truth.c | 2 +-
6 files changed, 191 insertions(+), 120 deletions(-)
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
index 0bf4aaa..3a0b87a 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -483,7 +483,7 @@ ANASTASIS_TESTING_get_trait_truth (const struct
TALER_TESTING_Command *cmd,
*/
struct TALER_TESTING_Trait
ANASTASIS_TESTING_make_trait_truth (unsigned int index,
- const struct ANASTASIS_Truth **t);
+ const struct ANASTASIS_Truth *t);
/**
* Creates a sample of id_data.
@@ -595,6 +595,8 @@ enum ANASTASIS_TESTING_SecretShareOption
* @param label command label
* @param anastasis_url base URL of the anastasis serving our requests.
* @param id_data ID data to generate user identifier
+ * @param core_secret core secret to backup/recover
+ * @param core_secret_size size of core_secret
* @param http_status expected HTTP status.
* @param sso secret share options
* @param ... NULL-terminated list of policy create commands
@@ -603,7 +605,9 @@ enum ANASTASIS_TESTING_SecretShareOption
struct TALER_TESTING_Command
ANASTASIS_TESTING_cmd_secret_share (const char *label,
const char *anastasis_url,
- json_t *id_data,
+ const json_t *id_data,
+ const void *core_secret,
+ size_t core_secret_size,
unsigned int http_status,
enum
ANASTASIS_TESTING_SecretShareOption sso,
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 7ae6041..64a25b1 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -650,34 +650,41 @@ struct ANASTASIS_Truth
* url to the server
*/
const char *url;
+
/**
* identification of the truth
*/
uuid_t uuid;
+
/**
* method used for this truth
*/
const char *method;
+
/**
* method used for this truth
*/
const char *instructions;
+
/**
* mime type of the truth
*/
const char *mime_type;
+
/**
* keyshare of this truth, used to generate policy keys
*/
struct ANASTASIS_CRYPTO_KeyShareP key_share;
+
/**
* key used to encrypt this truth
*/
struct ANASTASIS_CRYPTO_TruthKeyP truth_key;
+
/**
- * salt used to encrypt the truth
+ * server salt used to derive user identifier
*/
- struct ANASTASIS_CRYPTO_SaltP *salt;
+ const struct ANASTASIS_CRYPTO_SaltP *salt;
};
/**
@@ -858,6 +865,7 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
t->method = method;
t->instructions = instructions;
t->mime_type = mime_type;
+ t->salt = salt;
uuid_generate (t->uuid);
GNUNET_assert (NULL != &t->uuid);
@@ -1014,24 +1022,17 @@ ANASTASIS_policy_create (struct ANASTASIS_Truth
*truths[],
uuid_t uuids[truths_len];
p = GNUNET_new (struct ANASTASIS_Policy);
- truth = truths;
GNUNET_assert (NULL != *truths);
GNUNET_assert (truths_len > 0);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d truth array is %s\n", __FILE__, __LINE__,
- TALER_b2s (truths,
- truths_len
- * sizeof (struct ANASTASIS_Truth)));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d truth array length is %i\n", __FILE__, __LINE__,
truths_len);
for (unsigned int i = 0; i < truths_len; i++)
{
- if (i > 0)
- truth = &truth[1];
+ truth = truths[i];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
TALER_B2S (truth),
@@ -1087,41 +1088,6 @@ ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p)
}
-/**
-* Defines a recovery document upload process (recovery document consists of
multiple policies)
-*/
-struct ANASTASIS_SecretShare
-{
- /**
- * Callback which gives back the payment details
- */
- ANASTASIS_SharePaymentCallback spc;
- /**
- * Closure for the payment callback
- */
- void *spc_cls;
- /**
- * Callback which gives back the result of the POST Request
- */
- ANASTASIS_ShareResultCallback src;
- /**
- * Closure for the Result Callback
- */
- void *src_cls;
- /**
- * Closure for the Result Callback
- */
- struct GNUNET_CURL_Context *ctx;
- /**
- * References for the upload states and operations (size of truths passed)
- */
- struct PolicyStoreState **pss;
- /**
- * Closure for the Result Callback
- */
- unsigned int pss_length;
-};
-
/**
* State for a "policy store" CMD.
*/
@@ -1152,6 +1118,11 @@ struct PolicyStoreState
*/
unsigned int http_status;
+ /**
+ * Server salt
+ */
+ const struct ANASTASIS_CRYPTO_SaltP *server_salt;
+
/**
* Status of the transaction
*/
@@ -1207,6 +1178,41 @@ struct PolicyStoreState
int payment_requested;
};
+/**
+* Defines a recovery document upload process (recovery document consists of
multiple policies)
+*/
+struct ANASTASIS_SecretShare
+{
+ /**
+ * Callback which gives back the payment details
+ */
+ ANASTASIS_SharePaymentCallback spc;
+ /**
+ * Closure for the payment callback
+ */
+ void *spc_cls;
+ /**
+ * Callback which gives back the result of the POST Request
+ */
+ ANASTASIS_ShareResultCallback src;
+ /**
+ * Closure for the Result Callback
+ */
+ void *src_cls;
+ /**
+ * Closure for the Result Callback
+ */
+ struct GNUNET_CURL_Context *ctx;
+ /**
+ * References for the upload states and operations (size of truths passed)
+ */
+ struct PolicyStoreState **pss;
+ /**
+ * Closure for the Result Callback
+ */
+ unsigned int pss_length;
+};
+
static void
policy_store_cb (void *cls,
enum ANASTASIS_ErrorCode ec,
@@ -1402,6 +1408,7 @@ ANASTASIS_secret_share (const json_t *id_data,
{
struct ANASTASIS_SecretShare *ss;
+ struct ANASTASIS_Policy *policy;
unsigned int pss_length = ANASTASIS_get_uuids_length (policies,
policies_len);
@@ -1430,9 +1437,16 @@ ANASTASIS_secret_share (const json_t *id_data,
// json array
json_t *esc_methods;
+ policy = policies;
for (unsigned int i = 0; i < policies_len; i++)
{
- policy_keys[i] = policies[i]->policy_key;
+ if (i > 0)
+ policy = &policy[1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "At %s:%d policy is %s-%llu b\n", __FILE__, __LINE__,
+ TALER_B2S (policy),
+ (unsigned long long) sizeof (struct ANASTASIS_Policy));
+ policy_keys[i] = policy->policy_key;
}
ANASTASIS_CRYPTO_core_secret_encrypt (policy_keys,
@@ -1446,9 +1460,12 @@ ANASTASIS_secret_share (const json_t *id_data,
esc_methods = json_array ();
unsigned int all_uuids_length = 0;
int index_pss = 0;
+ policy = policies;
for (unsigned int k = 0; k < policies_len; k++ )
{
- all_uuids_length += policies[k]->uuid_length;
+ if (k > 0)
+ policy = &policy[1];
+ all_uuids_length += policy->uuid_length;
json_t *dec_policy = json_pack ("{s:o," /* encrypted master key */
" s:o," /* policy uuids */
" s:i}",/* policy uuids length */
@@ -1456,11 +1473,11 @@ ANASTASIS_secret_share (const json_t *id_data,
GNUNET_JSON_from_data_auto (
&encrypted_master_keys[k]),
"uuids",
- GNUNET_JSON_from_data (policies[k]->uuids,
- policies[k]->
+ GNUNET_JSON_from_data (policy->uuids,
+ policy->
uuid_length
* sizeof(uuid_t)),
- "uuid_length", &policies[k]->uuid_length);
+ "uuid_length", &policy->uuid_length);
GNUNET_assert (NULL != dec_policy);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"dec policy json before upload 0: %s\n",
@@ -1473,7 +1490,7 @@ ANASTASIS_secret_share (const json_t *id_data,
json_dumps (dec_policies, JSON_COMPACT));
// FIXME CHALLENGE
- for (unsigned int l = 0; l < policies[k]->uuid_length; l++)
+ for (unsigned int l = 0; l < policy->uuid_length; l++)
{
// creates a json array for saving
json_t *esc_method = json_pack ("{s:o," /* truth uuid */
@@ -1483,15 +1500,15 @@ ANASTASIS_secret_share (const json_t *id_data,
" s:s}", /* escrow method */
"uuid",
GNUNET_JSON_from_data (
- policies[k]->truths[l]->uuid,
+ policy->truths[l]->uuid,
sizeof(uuid_t)),
- "url", policies[k]->truths[l]->url,
+ "url", policy->truths[l]->url,
"truth_key", GNUNET_JSON_from_data_auto (
- &policies[k]->truths[l]->truth_key),
+ &policy->truths[l]->truth_key),
"salt", GNUNET_JSON_from_data_auto (
- policies[k]->truths[l]->salt),
+ policy->truths[l]->salt),
"escrow_method",
- policies[k]->truths[l]->method);
+ policy->truths[l]->method);
GNUNET_assert (NULL != esc_method);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1502,18 +1519,25 @@ ANASTASIS_secret_share (const json_t *id_data,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Esc methods json append before upload 0: %s\n",
json_dumps (esc_methods, JSON_COMPACT));
+
// prepares policy store operation
+ int contains_url = 0;
for (unsigned int j = 0; j < ss->pss_length; j++)
{
if (0 == strcmp (ss->pss[j]->anastasis_url,
- policies[k]->truths[l]->url))
+ policy->truths[l]->url))
{
- ss->pss[index_pss]->anastasis_url = policies[k]->truths[l]->url;
- ss->pss[index_pss]->prev_hash = *last_etag;
- index_pss++;
+ contains_url = 1;
break;
}
}
+ if (0 == contains_url)
+ {
+ ss->pss[index_pss]->anastasis_url = policy->truths[l]->url;
+ ss->pss[index_pss]->prev_hash = *last_etag;
+ ss->pss[index_pss]->server_salt = policy->truths[l]->salt;
+ index_pss++;
+ }
}
}
@@ -1537,15 +1561,10 @@ ANASTASIS_secret_share (const json_t *id_data,
{
ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
ss->pss[l]->st->http_status = MHD_HTTP_OK;
- ss->pss[l]->st->so = ANASTASIS_salt (ss->ctx,
- ss->pss[l]->anastasis_url,
- &salt_cb,
- ss->pss[l]->st);
ANASTASIS_CRYPTO_user_identifier_derive (id_data,
- &ss->pss[l]->st->so->salt,
+ &ss->pss[l]->server_salt,
&ss->pss[l]->id);
- salt_cleanup (ss->pss[l]->st);
ANASTASIS_CRYPTO_account_private_key_derive (&ss->pss[l]->id,
&ss->pss[l]->anastasis_priv);
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index 7348529..931fdfb 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -241,13 +241,18 @@ run (void *cls,
"truth-create-2",
"truth-create-3",
NULL),
- /*
+
ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
anastasis_url,
+ ANASTASIS_TESTING_make_id_data_example
(
+ "MaxMuster123456789"),
+ "core secret",
+ strlen ("core secret"),
MHD_HTTP_PAYMENT_REQUIRED,
ANASTASIS_TESTING_SSO_NONE,
+ "policy-create-1",
NULL),
-
+ /*
ANASTASIS_TESTING_cmd_recover_secret ("recover-secret-1",
anastasis_url,
MHD_HTTP_PAYMENT_REQUIRED,
diff --git a/src/lib/testing_cmd_secret_share.c
b/src/lib/testing_cmd_secret_share.c
index d2c0958..6a97520 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -27,30 +27,6 @@
#include <taler/taler_testing_lib.h>
-/**
-* Policy object to upload
-*/
-struct Policy
-{
- /**
- * Encrypted policy master key
- */
- struct ANASTASIS_CRYPTO_PolicyKeyP policy_key;
- /**
- * salt used to encrypt the master key
- */
- struct ANASTASIS_CRYPTO_SaltP salt;
- /**
- * set of truths inside this policy
- */
- uuid_t *uuids;
- /**
- * length of methods used
- */
- unsigned int uuid_length;
-};
-
-
/**
* State for a "secret share" CMD.
*/
@@ -71,6 +47,21 @@ struct SecretShareState
*/
const char **cmd_label_array;
+ /**
+ * 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;
+
/**
* Length of array of command labels (cmd_label_array).
*/
@@ -100,9 +91,65 @@ struct SecretShareState
* Options for how we are supposed to do the upload.
*/
enum ANASTASIS_TESTING_SecretShareOption ssopt;
+
+ /**
+ * closure for the payment callback
+ */
+ void *spc_cls;
+
+ /**
+ * closure for the result callback
+ */
+ void *src_cls;
};
+/**
+ * Function called for payment routine.
+ *
+ * @param cls closure
+ * @param ec ANASTASIS error code
+ * @param http_status HTTP status of the request
+ */
+static void
+secret_share_payment_cb (void *cls,
+ enum ANASTASIS_ErrorCode ec,
+ unsigned int http_status)
+{
+
+}
+
+
+/**
+ * Function called with the results of a #secret_share().
+ *
+ * @param cls closure
+ * @param ec ANASTASIS error code
+ * @param http_status HTTP status of the request
+ * @param ud details about the upload operation
+ */
+static void
+secret_share_result_cb (void *cls,
+ enum ANASTASIS_ErrorCode ec,
+ unsigned int http_status,
+ const struct ANASTASIS_UploadDetails *ud)
+{
+ struct SecretShareState *sss = cls;
+ sss->sso = NULL;
+ if (http_status != sss->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d to command %s in %s:%u\n",
+ http_status,
+ (int) ec,
+ sss->is->commands[sss->is->ip].label,
+ __FILE__,
+ __LINE__);
+ TALER_TESTING_interpreter_fail (sss->is);
+ return;
+ }
+}
+
/**
* Run a "secret share" CMD.
*
@@ -116,7 +163,7 @@ secret_share_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct SecretShareState *sss = cls;
- struct Policy policies[sss->cmd_label_array_length];
+ struct Policy *policies[sss->cmd_label_array_length];
GNUNET_assert (sss->cmd_label_array_length > 0);
GNUNET_assert (NULL != sss->cmd_label_array);
@@ -156,31 +203,20 @@ secret_share_run (void *cls,
return;
}
GNUNET_assert (NULL != policy);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d policy is %s-%llu b\n", __FILE__, __LINE__,
- TALER_B2S (policy),
- (unsigned long long) sizeof (*policy));
- policies[i] = *policy;
- GNUNET_assert (0 ==
- GNUNET_memcmp (&policies[i],
- policy));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d policy is %s-%llu b\n", __FILE__, __LINE__,
- TALER_B2S (&policies[i]),
- (unsigned long long) sizeof (policies[i]));
+ policies[i] = policy;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d policy array is %s\n", __FILE__, __LINE__,
- TALER_b2s (&policies,
- sss->cmd_label_array_length
- * sizeof (struct Policy)));
- // sss->sso = ANASTASIS_secret_share ();
-
-
- sss->is = is;
- // FIXME: Whole secret share procedure here
+ sss->sso = ANASTASIS_secret_share (sss->id_data,
+ NULL,
+ policies,
+ sss->cmd_label_array_length,
+ &secret_share_payment_cb,
+ sss->spc_cls,
+ &secret_share_result_cb,
+ sss->src_cls,
+ sss->core_secret,
+ sss->core_secret_size);
if (NULL == sss->sso)
{
@@ -243,6 +279,8 @@ secret_share_traits (void *cls,
* @param label command label
* @param anastasis_url base URL of the anastasis serving our requests.
* @param id_data ID data to generate user identifier
+ * @param core_secret core secret to backup/recover
+ * @param core_secret_size size of core_secret
* @param http_status expected HTTP status.
* @param sso secret share options
* @param ... NULL-terminated list of policy create commands
@@ -251,7 +289,9 @@ secret_share_traits (void *cls,
struct TALER_TESTING_Command
ANASTASIS_TESTING_cmd_secret_share (const char *label,
const char *anastasis_url,
- json_t *id_data,
+ const json_t *id_data,
+ const void *core_secret,
+ size_t core_secret_size,
unsigned int http_status,
enum
ANASTASIS_TESTING_SecretShareOption sso,
@@ -265,6 +305,9 @@ ANASTASIS_TESTING_cmd_secret_share (const char *label,
sss->ssopt = sso;
sss->anastasis_url = anastasis_url;
sss->label = label;
+ sss->id_data = id_data;
+ sss->core_secret = core_secret;
+ sss->core_secret_size = core_secret_size;
va_start (ap, sso);
char *policy_create_cmd;
diff --git a/src/lib/testing_cmd_truth_upload.c
b/src/lib/testing_cmd_truth_upload.c
index ec7c38b..519fcab 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -260,7 +260,7 @@ truth_upload_traits (void *cls,
struct TruthUploadState *tus = cls;
struct TALER_TESTING_Trait traits[] = {
ANASTASIS_TESTING_make_trait_truth (0,
- &tus->truth),
+ tus->truth),
TALER_TESTING_trait_end ()
};
diff --git a/src/lib/testing_trait_truth.c b/src/lib/testing_trait_truth.c
index 5974a5d..51696e1 100644
--- a/src/lib/testing_trait_truth.c
+++ b/src/lib/testing_trait_truth.c
@@ -59,7 +59,7 @@ ANASTASIS_TESTING_get_trait_truth (const struct
TALER_TESTING_Command *cmd,
struct TALER_TESTING_Trait
ANASTASIS_TESTING_make_trait_truth
(unsigned int index,
- const struct ANASTASIS_Truth **t)
+ const struct ANASTASIS_Truth *t)
{
struct TALER_TESTING_Trait ret = {
.index = index,
--
To stop receiving notification emails like this one, please contact
address@hidden.