[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/04: worked on anastasis.c secret share
From: |
gnunet |
Subject: |
[taler-anastasis] 01/04: worked on anastasis.c secret share |
Date: |
Thu, 07 May 2020 03:26:54 +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 dfd6e2a3bbc1150bf21579d014b16182317f6135
Author: Dennis Neufeld <address@hidden>
AuthorDate: Tue May 5 19:06:07 2020 +0000
worked on anastasis.c secret share
---
src/include/anastasis.h | 4 +-
src/include/anastasis_testing_lib.h | 4 +-
src/lib/anastasis.c | 199 ++++++++++++++++++++++++++++--------
src/lib/testing_cmd_policy_create.c | 69 ++-----------
src/lib/testing_cmd_truth_upload.c | 2 +-
src/lib/testing_trait_truth.c | 2 +-
6 files changed, 169 insertions(+), 111 deletions(-)
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index aab80ed..df6f88d 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -378,10 +378,8 @@ struct ANASTASIS_SecretShare;
struct ANASTASIS_SecretShare *
ANASTASIS_secret_share (const json_t *id_data,
const struct GNUNET_HashCode *last_etag,
- struct ANASTASIS_Policy *policies[],
+ const struct ANASTASIS_Policy *policies[],
unsigned int policies_len,
- struct ANASTASIS_Truth *truths[],
- unsigned int truths_len,
ANASTASIS_SharePaymentCallback spc,
void *spc_cls,
ANASTASIS_ShareResultCallback src,
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
index ff45951..0bf4aaa 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -475,7 +475,7 @@ ANASTASIS_TESTING_get_trait_truth (const struct
TALER_TESTING_Command *cmd,
/**
- * Offer an truth.
+ * Offer a truth.
*
* @param index the truth's index number.
* @param t the truth to offer.
@@ -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.
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index e7a2016..7ae6041 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -976,18 +976,26 @@ struct ANASTASIS_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;
+
+ /**
+ * array of truths
+ */
+ struct ANASTASIS_Truth *truths[];
};
/**
@@ -1057,6 +1065,7 @@ ANASTASIS_policy_create (struct ANASTASIS_Truth *truths[],
(unsigned long long) sizeof (p->policy_key));
p->uuids = uuids;
p->uuid_length = truths_len;
+ *p->truths = truths;
GNUNET_assert (NULL != p->uuids);
GNUNET_assert (p->uuid_length == truths_len);
@@ -1122,60 +1131,74 @@ struct PolicyStoreState
* User identifier used as entropy source for the account public key
*/
struct ANASTASIS_CRYPTO_UserIdentifierP id;
+
/**
* Struct to obtain the salt from the server
*/
struct SaltState *st;
+
/**
* The policy data.
*/
void *recovery_data;
+
/**
* Number of bytes in @e recovery_data
*/
size_t recovery_data_size;
+
/**
* Expected status code.
*/
unsigned int http_status;
+
/**
* Status of the transaction
*/
enum ANASTASIS_ErrorCode ec;
+
/**
* Eddsa Publickey.
*/
struct ANASTASIS_CRYPTO_AccountPublicKeyP anastasis_pub;
+
/**
* Eddsa Privatekey.
*/
struct GNUNET_CRYPTO_EddsaPrivateKey anastasis_priv;
+
/**
* Hash of the previous upload (maybe bogus if
* #ANASTASIS_TESTING_UO_PREV_HASH_WRONG is set in @e uo).
* Maybe all zeros if there was no previous upload.
*/
struct GNUNET_HashCode prev_hash;
+
/**
* Hash of the current upload.
*/
struct GNUNET_HashCode curr_hash;
+
/**
* The /policy POST operation handle.
*/
struct ANASTASIS_PolicyStoreOperation *pso;
+
/**
* URL of the anastasis backend.
*/
const char *anastasis_url;
+
/**
* Payment identifier.
*/
struct ANASTASIS_PaymentSecretP payment_id;
+
/**
* Payment order ID we got back, if any. Otherwise NULL.
*/
char *payment_order_id;
+
/**
* Payment order ID we are to provide in the request, may be NULL.
*/
@@ -1274,6 +1297,83 @@ policy_store_cb (void *cls,
}
+/**
+ *
+ */
+static int
+ANASTASIS_check_array_contains_element (const void **array,
+ unsigned int array_len,
+ void *element)
+{
+ void *arr;
+
+ arr = array;
+ if (0 == array_len)
+ return 0;
+
+ for (unsigned int i = 0; i < array_len; i++)
+ {
+ if (i > 0)
+ arr = &array[1];
+
+ int ret = GNUNET_memcmp (element, arr);
+
+ if (0 == ret)
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+/**
+ *
+ */
+static unsigned int
+ANASTASIS_get_uuids_length (const struct ANASTASIS_Policy *policies[],
+ unsigned int policies_len)
+{
+ struct ANASTASIS_Policy *policy;
+ unsigned int len = 0;
+ unsigned int unique_uuids_len = 0;
+
+ policy = policies;
+
+ for (unsigned int i = 0; i < policies_len; i++)
+ {
+ if (i > 0)
+ policy = &policies[1];
+
+ len += policy->uuid_length;
+ }
+ {
+ uuid_t *uuids[len];
+
+ policy = policies;
+
+ for (unsigned int i = 0; i < policies_len; i++)
+ {
+ if (i > 0)
+ policy = &policies[1];
+
+ for (unsigned int j = 0; j < policy->uuid_length; j++)
+ {
+ if (0 == ANASTASIS_check_array_contains_element ((void **) &uuids,
+ len,
+ (void *)
&policy->uuids
+ [j]))
+ {
+ uuids[unique_uuids_len] = policy->uuids[j];
+ unique_uuids_len++;
+ }
+ }
+ }
+ }
+ return unique_uuids_len;
+}
+
+
/**
* Creates a recovery document with the created policies.
*
@@ -1291,10 +1391,8 @@ policy_store_cb (void *cls,
struct ANASTASIS_SecretShare *
ANASTASIS_secret_share (const json_t *id_data,
const struct GNUNET_HashCode *last_etag,
- struct ANASTASIS_Policy *policies[],
+ const struct ANASTASIS_Policy *policies[],
unsigned int policies_len,
- struct ANASTASIS_Truth *truths[],
- unsigned int truths_len,
ANASTASIS_SharePaymentCallback spc,
void *spc_cls,
ANASTASIS_ShareResultCallback src,
@@ -1304,12 +1402,16 @@ ANASTASIS_secret_share (const json_t *id_data,
{
struct ANASTASIS_SecretShare *ss;
+
+ unsigned int pss_length = ANASTASIS_get_uuids_length (policies,
+ policies_len);
+ struct PolicyStoreState pss[pss_length];
+ struct GNUNET_HashCode current_etags[pss_length];
+ enum TALER_ErrorCode ecs[pss_length];
+
ss = GNUNET_new (struct ANASTASIS_SecretShare);
- struct PolicyStoreState pss[truths_len];
- struct GNUNET_HashCode current_etags[truths_len];
- enum TALER_ErrorCode ecs[truths_len];
ss->pss = &pss;
- ss->pss_length = truths_len;
+ ss->pss_length = pss_length;
ss->spc = spc;
ss->spc_cls = spc_cls;
ss->src = src;
@@ -1341,8 +1443,12 @@ ANASTASIS_secret_share (const json_t *id_data,
encrypted_master_keys);
dec_policies = json_array ();
+ esc_methods = json_array ();
+ unsigned int all_uuids_length = 0;
+ int index_pss = 0;
for (unsigned int k = 0; k < policies_len; k++ )
{
+ all_uuids_length += policies[k]->uuid_length;
json_t *dec_policy = json_pack ("{s:o," /* encrypted master key */
" s:o," /* policy uuids */
" s:i}",/* policy uuids length */
@@ -1365,39 +1471,50 @@ ANASTASIS_secret_share (const json_t *id_data,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Dec policies json append before upload 0: %s\n",
json_dumps (dec_policies, JSON_COMPACT));
- }
- // FIXME CHALLENGE
- esc_methods = json_array ();
- for (unsigned int l = 0; l < truths_len; l++)
- {
- // creates a json array for saving
- json_t *esc_method = json_pack ("{s:o," /* truth uuid */
- " s:s," /* provider url */
- " s:o," /* truth key */
- " s:o," /* truth salt */
- " s:s}", /* escrow method */
- "uuid",
- GNUNET_JSON_from_data (truths[l]->uuid,
- sizeof(uuid_t)),
- "url", truths[l]->url,
- "truth_key", GNUNET_JSON_from_data_auto (
- &truths[l]->truth_key),
- "salt", GNUNET_JSON_from_data_auto (
- truths[l]->salt),
- "escrow_method", truths[l]->method);
-
- GNUNET_assert (NULL != esc_method);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "esc method json before upload 0: %s\n",
- json_dumps (esc_method, JSON_COMPACT));
- GNUNET_assert (0 ==
- json_array_append_new (esc_methods, esc_method));
- 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
- ss->pss[l]->anastasis_url = truths[l]->url;
- ss->pss[l]->prev_hash = *last_etag;
+
+ // FIXME CHALLENGE
+ for (unsigned int l = 0; l < policies[k]->uuid_length; l++)
+ {
+ // creates a json array for saving
+ json_t *esc_method = json_pack ("{s:o," /* truth uuid */
+ " s:s," /* provider url */
+ " s:o," /* truth key */
+ " s:o," /* truth salt */
+ " s:s}", /* escrow method */
+ "uuid",
+ GNUNET_JSON_from_data (
+ policies[k]->truths[l]->uuid,
+ sizeof(uuid_t)),
+ "url", policies[k]->truths[l]->url,
+ "truth_key", GNUNET_JSON_from_data_auto (
+ &policies[k]->truths[l]->truth_key),
+ "salt", GNUNET_JSON_from_data_auto (
+ policies[k]->truths[l]->salt),
+ "escrow_method",
+ policies[k]->truths[l]->method);
+
+ GNUNET_assert (NULL != esc_method);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "esc method json before upload 0: %s\n",
+ json_dumps (esc_method, JSON_COMPACT));
+ GNUNET_assert (0 ==
+ json_array_append_new (esc_methods, esc_method));
+ 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
+ for (unsigned int j = 0; j < ss->pss_length; j++)
+ {
+ if (0 == strcmp (ss->pss[j]->anastasis_url,
+ policies[k]->truths[l]->url))
+ {
+ ss->pss[index_pss]->anastasis_url = policies[k]->truths[l]->url;
+ ss->pss[index_pss]->prev_hash = *last_etag;
+ index_pss++;
+ break;
+ }
+ }
+ }
}
recovery_document = json_pack (
@@ -1416,7 +1533,7 @@ ANASTASIS_secret_share (const json_t *id_data,
// FIXME COMPRESSION
recovery_document_str = json_dumps (recovery_document, JSON_COMPACT);
recovery_document_size = strlen (recovery_document_str);
- for (unsigned int l = 0; l < truths_len; l++)
+ for (unsigned int l = 0; l < ss->pss_length; l++)
{
ss->pss[l]->http_status = MHD_HTTP_NO_CONTENT;
ss->pss[l]->st->http_status = MHD_HTTP_OK;
diff --git a/src/lib/testing_cmd_policy_create.c
b/src/lib/testing_cmd_policy_create.c
index cce0f25..dba47b4 100644
--- a/src/lib/testing_cmd_policy_create.c
+++ b/src/lib/testing_cmd_policy_create.c
@@ -58,48 +58,6 @@ struct PolicyCreateState
const struct ANASTASIS_Policy *policy;
};
-/**
- * Th Truth.
- * FIXME: Is there a more elegant way to fix "incomplete type" error?
- * see sizeof (*truth)
- */
-struct 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
- */
- struct ANASTASIS_CRYPTO_SaltP *salt;
-};
-
-
/**
* Run a "policy create" CMD.
@@ -114,7 +72,7 @@ policy_create_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct PolicyCreateState *pcs = cls;
- struct Truth truths[pcs->cmd_label_array_length];
+ struct Truth *truths[pcs->cmd_label_array_length];
GNUNET_assert (pcs->cmd_label_array_length > 0);
GNUNET_assert (NULL != pcs->cmd_label_array);
@@ -129,7 +87,7 @@ policy_create_run (void *cls,
for (unsigned int i = 0; i < pcs->cmd_label_array_length; i++)
{
const struct TALER_TESTING_Command *ref;
- struct Truth *truth;
+ const struct Truth *truth;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d truth upload cmd is %s\n", __FILE__, __LINE__,
@@ -154,28 +112,13 @@ policy_create_run (void *cls,
return;
}
GNUNET_assert (NULL != truth);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
- TALER_B2S (truth),
- (unsigned long long) sizeof (*truth));
- truths[i] = *truth;
- GNUNET_assert (0 ==
- GNUNET_memcmp (&truths[i],
- truth));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d truth is %s-%llu b\n", __FILE__, __LINE__,
- TALER_B2S (&truths[i]),
- (unsigned long long) sizeof (truths[i]));
+ truths[i] = truth;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "At %s:%d truth array is %s\n", __FILE__, __LINE__,
- TALER_b2s (&truths,
- pcs->cmd_label_array_length
- * sizeof (struct Truth)));
- pcs->policy = ANASTASIS_policy_create (&truths,
+
+ pcs->policy = ANASTASIS_policy_create (truths,
pcs->cmd_label_array_length);
- if (NULL == &pcs->policy)
+ if (NULL == pcs->policy)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (pcs->is);
diff --git a/src/lib/testing_cmd_truth_upload.c
b/src/lib/testing_cmd_truth_upload.c
index 519fcab..ec7c38b 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 51696e1..5974a5d 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.