[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/02: modified truth upload
From: |
gnunet |
Subject: |
[taler-anastasis] 01/02: modified truth upload |
Date: |
Wed, 08 Apr 2020 23:19:16 +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 59129aa1e3f09308be3a94fbadf1926222ad4533
Author: Dennis Neufeld <address@hidden>
AuthorDate: Wed Apr 8 16:56:56 2020 +0000
modified truth upload
---
src/backend/anastasis-httpd_policy.c | 9 +++++---
src/backend/anastasis-httpd_policy_upload.c | 2 +-
src/backend/anastasis-httpd_truth_upload.c | 18 +++++++++++----
src/include/anastasis_service.h | 2 +-
src/include/anastasis_testing_lib.h | 2 +-
src/lib/anastasis_api_policy_lookup.c | 20 +++++++++--------
src/lib/anastasis_api_policy_store.c | 11 +++++++--
src/lib/anastasis_api_truth_store.c | 35 ++++++++++++++++++++---------
src/lib/test_anastasis_api.c | 15 +++++++++++--
src/lib/testing_api_cmd_truth_store.c | 2 +-
10 files changed, 82 insertions(+), 34 deletions(-)
diff --git a/src/backend/anastasis-httpd_policy.c
b/src/backend/anastasis-httpd_policy.c
index 146b1ba..23d41a0 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -143,30 +143,33 @@ AH_return_policy (struct MHD_Connection *connection,
TALER_MHD_add_global_headers (resp);
{
char *sig_s;
- char *prev_s;
+ // char *prev_s;
char *etag;
sig_s = GNUNET_STRINGS_data_to_string_alloc (&account_sig,
sizeof (account_sig));
+ /*
prev_s = GNUNET_STRINGS_data_to_string_alloc (&prev_hash,
sizeof (prev_hash));
+ */
etag = GNUNET_STRINGS_data_to_string_alloc (&recovery_data_hash,
sizeof (recovery_data_hash));
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
"Anastasis-Policy-Signature",
sig_s));
- // FIXME: reasonable?
+ /*
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
"Anastasis-Previous",
prev_s));
+ */
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
MHD_HTTP_HEADER_ETAG,
etag));
GNUNET_free (etag);
- GNUNET_free (prev_s);
+ // GNUNET_free (prev_s);
GNUNET_free (sig_s);
}
ret = MHD_queue_response (connection,
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index bfd0682..bb08a87 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -795,7 +795,7 @@ AH_handler_policy_post (struct MHD_Connection *connection,
usp.purpose.size = htonl (sizeof (struct ANASTASIS_UploadSignaturePS));
usp.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD);
- usp.old_recovery_data_hash = puc->old_policy_upload_hash;
+ // usp.old_recovery_data_hash = puc->old_policy_upload_hash;
usp.new_recovery_data_hash = puc->new_policy_upload_hash;
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD,
diff --git a/src/backend/anastasis-httpd_truth_upload.c
b/src/backend/anastasis-httpd_truth_upload.c
index e1282e0..6bfb8d9 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -55,6 +55,9 @@ verify_and_execute_truth (struct MHD_Connection *connection,
&truth->nonce,
truth->method,
AH_truth_expiration);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Store truth db status: %i\n",
+ qs);
return qs;
}
@@ -88,9 +91,9 @@ AH_handler_truth_post (struct MHD_Connection *connection,
uuid_str = &url[strlen ("/truth/")];
uuid_parse (uuid_str, uuid);
- }
- {
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Uuid from Url: %s\n",
+ uuid_str);
}
{
struct GNUNET_JSON_Specification spec[] = {
@@ -103,6 +106,9 @@ AH_handler_truth_post (struct MHD_Connection *connection,
GNUNET_JSON_spec_string ("truth_mime", &truth.truth_mime),
GNUNET_JSON_spec_end ()
};
+ (void) con_cls;
+ (void) truth_data;
+ (void) truth_data_size;
res = TALER_MHD_parse_post_json (connection,
con_cls,
@@ -111,11 +117,15 @@ AH_handler_truth_post (struct MHD_Connection *connection,
&json);
if (GNUNET_SYSERR == res)
return MHD_NO;
- if ( (GNUNET_NO == res) || (NULL == json) )
+ if ( (GNUNET_NO == res) ||
+ (NULL == json) )
return MHD_YES;
res = TALER_MHD_parse_json_data (connection,
json,
spec);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Truth json from upload: %s\n",
+ TALER_b2s (json, sizeof (json)));
json_decref (json);
if (GNUNET_SYSERR == res)
return MHD_NO; /* hard failure */
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index f94fae4..95c82f3 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -65,7 +65,7 @@ struct ANASTASIS_UploadSignaturePS
/**
* Hash of the previous backup, all zeros for none.
*/
- struct GNUNET_HashCode old_recovery_data_hash;
+ // struct GNUNET_HashCode old_recovery_data_hash;
/**
* Hash of the new backup.
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
index bb994c6..e0c9c3e 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -338,7 +338,7 @@ ANASTASIS_TESTING_cmd_truth_store (const char *label,
unsigned int http_status,
enum
ANASTASIS_TESTING_TruthStoreOption tso,
- const void *truth_data,
+ const json_t *truth_data,
size_t truth_data_size);
/**
diff --git a/src/lib/anastasis_api_policy_lookup.c
b/src/lib/anastasis_api_policy_lookup.c
index fc8bfbb..8ca660d 100644
--- a/src/lib/anastasis_api_policy_lookup.c
+++ b/src/lib/anastasis_api_policy_lookup.c
@@ -135,23 +135,26 @@ handle_policy_lookup_finished (void *cls,
usp.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD);
usp.purpose.size = htonl (sizeof (struct ANASTASIS_UploadSignaturePS));
- usp.old_recovery_data_hash = plo->anastasis_previous;
+ // usp.old_recovery_data_hash = plo->anastasis_previous;
GNUNET_CRYPTO_hash (data,
data_size,
&usp.new_recovery_data_hash);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Account Signature to verify download: %s\n",
- TALER_B2S (&plo->account_sig));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Account Public Key for verification of signature: %s\n",
- TALER_B2S (&plo->account_pub));
-
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD,
&usp.purpose,
&plo->account_sig.eddsa_sig,
&plo->account_pub.pub))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hash of new recovery data (download): %s\n",
+ TALER_B2S (&usp.new_recovery_data_hash));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Account Signature to verify download: %s\n",
+ TALER_B2S (&plo->account_sig));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Account Public Key for verification of signature: %s\n",
+ TALER_B2S (&plo->account_pub));
+
GNUNET_break_op (0);
response_code = 0;
break;
@@ -258,7 +261,6 @@ handle_header (char *buffer,
return 0;
}
}
- /* FIXME: reasonable?*/
if (0 == strcasecmp (hdr_type,
"Anastasis-Previous"))
{
diff --git a/src/lib/anastasis_api_policy_store.c
b/src/lib/anastasis_api_policy_store.c
index e34d3d9..be3615f 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -259,7 +259,6 @@ handle_header (char *buffer,
*
* @param ctx the CURL context used to connect to the backend
* @param backend_url backend's base URL, including final "/"
- * @param anastasis_pub public key of the user's account
* @param anastasis_priv private key of the user's account
* @param prev_recovery_data_hash hash of the previous uploaded recovery
document
* @param recovery_data policy data to be stored
@@ -293,12 +292,17 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
memset (&usp, 0, sizeof (usp));
usp.purpose.purpose = htonl (TALER_SIGNATURE_ANASTASIS_POLICY_UPLOAD);
usp.purpose.size = htonl (sizeof (usp));
+ /* FIXME: delete
if (NULL != prev_recovery_data_hash)
usp.old_recovery_data_hash = *prev_recovery_data_hash;
+ */
GNUNET_CRYPTO_hash (recovery_data,
recovery_data_size,
&usp.new_recovery_data_hash);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hash of new recovery data (upload): %s\n",
+ TALER_B2S (&usp.new_recovery_data_hash));
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_sign (&anastasis_priv->priv,
&usp.purpose,
@@ -354,7 +358,7 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
/* Setup If-Match header */
if (NULL != prev_recovery_data_hash)
{
- val = GNUNET_STRINGS_data_to_string_alloc (&usp.old_recovery_data_hash,
+ val = GNUNET_STRINGS_data_to_string_alloc (prev_recovery_data_hash,
sizeof (struct
GNUNET_HashCode));
GNUNET_asprintf (&hdr,
@@ -402,6 +406,9 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
GNUNET_CRYPTO_eddsa_key_get_public (&anastasis_priv->priv,
&pub.pub);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Account public key created: %s\n",
+ TALER_B2S (&pub));
acc_pub_str = GNUNET_STRINGS_data_to_string_alloc (&pub,
sizeof (pub));
GNUNET_asprintf (&path,
diff --git a/src/lib/anastasis_api_truth_store.c
b/src/lib/anastasis_api_truth_store.c
index 12bc30c..efd2a83 100644
--- a/src/lib/anastasis_api_truth_store.c
+++ b/src/lib/anastasis_api_truth_store.c
@@ -90,6 +90,7 @@ ANASTASIS_truth_store_cancel (struct
GNUNET_CURL_job_cancel (tso->job);
tso->job = NULL;
}
+ GNUNET_free_non_null (tso->pay_uri);
GNUNET_free (tso->url);
GNUNET_free (tso);
}
@@ -117,6 +118,7 @@ handle_truth_store_finished (void *cls,
tso->job = NULL;
udp = NULL;
memset (&ud, 0, sizeof (ud));
+
switch (response_code)
{
case 0:
@@ -209,18 +211,21 @@ handle_header (char *buffer,
char *ndup;
const char *hdr_type;
char *hdr_val;
+ char *sp;
ndup = GNUNET_strndup (buffer,
total);
- hdr_type = strtok (ndup,
- ":");
+ hdr_type = strtok_r (ndup,
+ ":",
+ &sp);
if (NULL == hdr_type)
{
GNUNET_free (ndup);
return total;
}
- hdr_val = strtok (NULL,
- "");
+ hdr_val = strtok_r (NULL,
+ "",
+ &sp);
if (NULL == hdr_val)
{
GNUNET_free (ndup);
@@ -231,8 +236,18 @@ handle_header (char *buffer,
if (0 == strcasecmp (hdr_type,
"Taler"))
{
+ size_t len;
+
/* found payment URI we care about! */
tso->pay_uri = GNUNET_strdup (hdr_val);
+ len = strlen (tso->pay_uri);
+ while ( (len > 0) &&
+ ( ('\n' == tso->pay_uri[len - 1]) ||
+ ('\r' == tso->pay_uri[len - 1]) ) )
+ {
+ len--;
+ tso->pay_uri[len] = '\0';
+ }
}
GNUNET_free (ndup);
return total;
@@ -268,8 +283,10 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
struct ANASTASIS_TruthStoreOperation *tso;
CURL *eh;
struct curl_slist *job_headers;
- struct GNUNET_HashCode old_truth_data_hash;
struct GNUNET_HashCode new_truth_data_hash;
+ char *json_str;
+
+ json_str = json_dumps (truth_data, 0);
/* setup our HTTP headers */
job_headers = NULL;
@@ -278,8 +295,6 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
char *val;
char *hdr;
- if (NULL != prev_truth_data_hash)
- old_truth_data_hash = *prev_truth_data_hash;
GNUNET_CRYPTO_hash (truth_data,
sizeof(truth_data),
&new_truth_data_hash);
@@ -305,7 +320,7 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
/* Setup If-Match header */
if (NULL != prev_truth_data_hash)
{
- val = GNUNET_STRINGS_data_to_string_alloc (&old_truth_data_hash,
+ val = GNUNET_STRINGS_data_to_string_alloc (prev_truth_data_hash,
sizeof (struct
GNUNET_HashCode));
GNUNET_asprintf (&hdr,
@@ -374,11 +389,11 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
- truth_data));
+ json_str));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDSIZE,
- sizeof(truth_data)));
+ (long) strlen (json_str)));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_HEADERFUNCTION,
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
index 62c5a58..ce1aca9 100644
--- a/src/lib/test_anastasis_api.c
+++ b/src/lib/test_anastasis_api.c
@@ -234,6 +234,17 @@ run (void *cls,
TALER_TESTING_cmd_end ()
};
+ json_t *truth_data = json_object ();
+
+ json_object_set_new (truth_data, "keyshare_data", json_string ("Truth
test"));
+ json_object_set_new (truth_data, "method", json_string ("Truth test"));
+ json_object_set_new (truth_data, "nonce", json_integer (1234));
+ json_object_set_new (truth_data, "aes_gcm_tag", json_string ("Truth test"));
+ json_object_set_new (truth_data, "truth_hash", json_string ("Truth test"));
+ json_object_set_new (truth_data, "encrypted_truth", json_string (
+ "Truth test"));
+ json_object_set_new (truth_data, "truth_mime", json_string ("Truth test"));
+
struct TALER_TESTING_Command truth[] = {
// FIXME: Code for truth handling
@@ -242,8 +253,8 @@ run (void *cls,
NULL,
MHD_HTTP_NO_CONTENT,
ANASTASIS_TESTING_TSO_NONE,
- "Test-2",
- strlen ("Test-2")),
+ truth_data,
+ sizeof (truth_data)),
TALER_TESTING_cmd_end ()
};
diff --git a/src/lib/testing_api_cmd_truth_store.c
b/src/lib/testing_api_cmd_truth_store.c
index c7e6b2a..2826e28 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -407,7 +407,7 @@ ANASTASIS_TESTING_cmd_truth_store (const char *label,
unsigned int http_status,
enum
ANASTASIS_TESTING_TruthStoreOption tso,
- const void *truth_data,
+ const json_t *truth_data,
size_t truth_data_size)
{
struct TruthStoreState *tss;
--
To stop receiving notification emails like this one, please contact
address@hidden.