[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: Worked on test. Not working...
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: Worked on test. Not working... |
Date: |
Fri, 29 Nov 2019 14:07:29 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 8329cb6 Worked on test. Not working...
8329cb6 is described below
commit 8329cb6add4e2a167f3edcd423b1fdc52a0be590
Author: Dennis Neufeld <address@hidden>
AuthorDate: Fri Nov 29 13:06:56 2019 +0000
Worked on test. Not working...
---
src/backend/anastasis-httpd.h | 2 +-
src/backend/anastasis-httpd_policy_upload.c | 194 ++++++------
src/include/anastasis_database_plugin.h | 79 ++---
src/lib/anastasis_api_policy.c | 457 ----------------------------
src/lib/testing_api_cmd_policy.c | 214 -------------
src/stasis/plugin_anastasis_postgres.c | 243 +++++++++------
src/stasis/test_anastasis_db.c | 112 +++++--
7 files changed, 364 insertions(+), 937 deletions(-)
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index a7aa696..87ba238 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -139,7 +139,7 @@ extern unsigned long long AH_upload_limit_mb;
/**
* Annual fee for the backup account.
- *
+ *
* FIXME: the amount to pay is fixed to this value. Better variable value?
*/
extern struct TALER_Amount AH_annual_fee;
diff --git a/src/backend/anastasis-httpd_policy_upload.c
b/src/backend/anastasis-httpd_policy_upload.c
index 69b333e..a9a0f25 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -218,12 +218,14 @@ make_payment_request (const char *payment_identifier)
* FIXME: Is this reasonable?
*/
unsigned int
-amount_to_post_counter (const struct TALER_Amount *amount) {
+amount_to_post_counter (const struct TALER_Amount *amount)
+{
/* FIXME: reasonable conversion from Taler Amount to post counter */
- if (0 == strcmp (amount->currency, "CHF") || 0 == strcmp (amount->currency,
"EUR"))
+ if ((0 == strcmp (amount->currency, "CHF"))|| (0 == strcmp (amount->currency,
+ "EUR")))
{
- //FIXME: check if long long value is in int range
- return (int)amount->value * 10;
+ // FIXME: check if long long value is in int range
+ return (int) amount->value * 10;
}
return 0;
}
@@ -258,7 +260,7 @@ proposal_cb (void *cls,
puc_tail,
puc);
MHD_resume_connection (puc->con);
- post_counter = amount_to_post_counter ( &AH_annual_fee);
+ post_counter = amount_to_post_counter (&AH_annual_fee);
qs = db->record_payment (db->cls,
&puc->account,
post_counter,
@@ -267,7 +269,7 @@ proposal_cb (void *cls,
{
GNUNET_break (0);
puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CREATE_DB_ERROR,
- "Failed to persist payment request in
sync database");
+ "Failed to persist payment request in
sync database");
puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
return;
}
@@ -325,7 +327,7 @@ check_payment_cb (void *cls,
return; /* continue as planned */
GNUNET_break (0);
puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CONFIRM_DB_ERROR,
- "Failed to persist payment confirmation
in sync database");
+ "Failed to persist payment confirmation
in sync database");
puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
return; /* continue as planned */
}
@@ -337,7 +339,7 @@ check_payment_cb (void *cls,
return;
}
puc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_TIMEOUT,
- "Timeout awaiting promised payment");
+ "Timeout awaiting promised payment");
puc->response_code = MHD_HTTP_REQUEST_TIMEOUT;
}
@@ -711,7 +713,7 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
}
}
/* check if the client insists on paying */
- {
+ {
const char *order_req;
order_req = MHD_lookup_connection_value (connection,
@@ -720,99 +722,79 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
if (NULL != order_req)
return begin_payment (puc,
GNUNET_YES);
- }
- /* ready to begin! */
- return MHD_YES;
- }
- /* handle upload */
- if (0 != recovery_data_size)
- {
- /* check MHD invariant */
- GNUNET_assert (puc->upload_off + *recovery_data_size <=
puc->upload_size);
- memcpy (&puc->upload[puc->upload_off],
- recovery_data,
- *recovery_data_size);
- puc->upload_off += *recovery_data_size;
- GNUNET_CRYPTO_hash_context_read (puc->hash_ctx,
- recovery_data,
- *recovery_data_size);
- *recovery_data_size = 0;
- return MHD_YES;
}
- if (NULL != puc->resp)
- {
- /* We generated a response asynchronously, queue that */
- return MHD_queue_response (connection,
- puc->response_code,
- puc->resp);
- }
-
- /* finished with upload, check hash */
- {
- struct GNUNET_HashCode our_hash;
+ /* ready to begin! */
+ return MHD_YES;
+ }
+ /* handle upload */
+ if (0 != recovery_data_size)
+ {
+ /* check MHD invariant */
+ GNUNET_assert (puc->upload_off + *recovery_data_size <= puc->upload_size);
+ memcpy (&puc->upload[puc->upload_off],
+ recovery_data,
+ *recovery_data_size);
+ puc->upload_off += *recovery_data_size;
+ GNUNET_CRYPTO_hash_context_read (puc->hash_ctx,
+ recovery_data,
+ *recovery_data_size);
+ *recovery_data_size = 0;
+ return MHD_YES;
+ }
+ if (NULL != puc->resp)
+ {
+ /* We generated a response asynchronously, queue that */
+ return MHD_queue_response (connection,
+ puc->response_code,
+ puc->resp);
+ }
- GNUNET_CRYPTO_hash_context_finish (puc->hash_ctx,
- &our_hash);
- puc->hash_ctx = NULL;
- if (0 != GNUNET_memcmp (&our_hash,
- &puc->new_policy_upload_hash))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_SYNC_INVALID_UPLOAD,
- "Data uploaded does not match Etag
promise");
- }
- }
+ /* finished with upload, check hash */
+ {
+ struct GNUNET_HashCode our_hash;
- /* store backup to database */
+ GNUNET_CRYPTO_hash_context_finish (puc->hash_ctx,
+ &our_hash);
+ puc->hash_ctx = NULL;
+ if (0 != GNUNET_memcmp (&our_hash,
+ &puc->new_policy_upload_hash))
{
- enum ANASTASIS_DB_QueryStatus qs;
- void *paymentIdentifier;
- GNUNET_STRINGS_base64_decode (puc->payment_identifier,
- strlen (puc->payment_identifier),
- &paymentIdentifier);
- // FIXME: version has to be delivered by header
- uint32_t version;
-
- qs = db->store_recovery_document (db->cls,
- &accountPubP,
- &puc->account_sig,
- &puc->old_policy_upload_hash,
- &puc->new_policy_upload_hash,
- recovery_data,
- sizeof (recovery_data),
- paymentIdentifier,
- &version);
-
- if (qs < 0)
- return handle_database_error (puc,
- qs);
- if (0 == qs)
- {
- /* database says nothing actually changed, 304 (could
- theoretically happen if another equivalent upload succeeded
- since we last checked!) */
- struct MHD_Response *resp;
- int ret;
-
- resp = MHD_create_response_from_buffer (0,
- NULL,
- MHD_RESPMEM_PERSISTENT);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
-
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
- "*"));
- ret = MHD_queue_response (connection,
- MHD_HTTP_NOT_MODIFIED,
- resp);
- MHD_destroy_response (resp);
- return ret;
- }
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_SYNC_INVALID_UPLOAD,
+ "Data uploaded does not match Etag
promise");
}
+ }
- /* generate main (204) standard success reply */
+ /* store backup to database */
+ {
+ enum ANASTASIS_DB_QueryStatus qs;
+ void *paymentIdentifier;
+ GNUNET_STRINGS_base64_decode (puc->payment_identifier,
+ strlen (puc->payment_identifier),
+ &paymentIdentifier);
+ // FIXME: version has to be delivered by header
+ uint32_t version;
+
+ qs = db->store_recovery_document (db->cls,
+ &accountPubP,
+ &puc->account_sig,
+ &puc->old_policy_upload_hash,
+ &puc->new_policy_upload_hash,
+ recovery_data,
+ sizeof (recovery_data),
+ paymentIdentifier,
+ &version);
+
+ if (qs < 0)
+ return handle_database_error (puc,
+ qs);
+ if (0 == qs)
{
+ /* database says nothing actually changed, 304 (could
+ theoretically happen if another equivalent upload succeeded
+ since we last checked!) */
struct MHD_Response *resp;
int ret;
@@ -824,9 +806,29 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
"*"));
ret = MHD_queue_response (connection,
- MHD_HTTP_NO_CONTENT,
+ MHD_HTTP_NOT_MODIFIED,
resp);
MHD_destroy_response (resp);
return ret;
}
+ }
+
+ /* generate main (204) standard success reply */
+ {
+ struct MHD_Response *resp;
+ int ret;
+
+ resp = MHD_create_response_from_buffer (0,
+ NULL,
+ MHD_RESPMEM_PERSISTENT);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
+ "*"));
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_NO_CONTENT,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
+ }
}
\ No newline at end of file
diff --git a/src/include/anastasis_database_plugin.h
b/src/include/anastasis_database_plugin.h
index 967c03d..b537387 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -142,21 +142,21 @@ struct ANASTASIS_DatabasePlugin
* @return transaction status, 0 if upload could not be finished because @a
payment_secret
* did not have enough upload left; HARD error if @a payment_secret
is unknown, ...
*/
-enum ANASTASIS_DB_QueryStatus
-(*store_recovery_document)(void *cls,
- const struct
- ANASTASIS_AccountPubP *anastasis_pub,
- const struct
- ANASTASIS_AccountSignatureP *account_sig,
- const struct
- GNUNET_HashCode *old_data_hash,
- const struct
- GNUNET_HashCode *data_hash,
- const void *data,
- size_t data_size,
- const struct
- ANASTASIS_PaymentSecretP *payment_secret,
- uint32_t *version);
+ enum ANASTASIS_DB_QueryStatus
+ (*store_recovery_document)(void *cls,
+ const struct
+ ANASTASIS_AccountPubP *anastasis_pub,
+ const struct
+ ANASTASIS_AccountSignatureP *account_sig,
+ const struct
+ GNUNET_HashCode *old_data_hash,
+ const struct
+ GNUNET_HashCode *data_hash,
+ const void *data,
+ size_t data_size,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_secret,
+ uint32_t *version);
/**
* Fetch recovery document for user.
@@ -197,19 +197,19 @@ enum ANASTASIS_DB_QueryStatus
* @param version[OUT] set to the version number of the policy being returned
* @return transaction status
*/
-enum ANASTASIS_DB_QueryStatus
-(*get_latest_recovery_document)(void *cls,
- const struct
- ANASTASIS_AccountPubP *anastasis_pub,
- struct
- ANASTASIS_AccountSignatureP *account_sig,
- struct
- GNUNET_HashCode *prev_hash,
- struct
- GNUNET_HashCode *recovery_data_hash,
- size_t *data_size,
- void **data,
- uint32_t *version);
+ enum ANASTASIS_DB_QueryStatus
+ (*get_latest_recovery_document)(void *cls,
+ const struct
+ ANASTASIS_AccountPubP *anastasis_pub,
+ struct
+ ANASTASIS_AccountSignatureP *account_sig,
+ struct
+ GNUNET_HashCode *prev_hash,
+ struct
+ GNUNET_HashCode *recovery_data_hash,
+ size_t *data_size,
+ void **data,
+ uint32_t *version);
/**
* Upload Truth, which contains the Truth and the KeyShare.
@@ -290,28 +290,29 @@ enum ANASTASIS_DB_QueryStatus
* @param lifetime for how long is the account now paid (increment)
* @return transaction status
*/
-enum ANASTASIS_DB_QueryStatus
-(*increment_lifetime)(void *cls,
- const struct ANASTASIS_AccountPubP *anastasis_pub,
- const struct ANASTASIS_PaymentSecretP
*payment_identifier,
- struct GNUNET_TIME_Relative lifetime);
+ enum ANASTASIS_DB_QueryStatus
+ (*increment_lifetime)(void *cls,
+ const struct ANASTASIS_AccountPubP *anastasis_pub,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_identifier,
+ struct GNUNET_TIME_Relative lifetime);
/**
* Store payment. Used to begin a payment, not indicative
* that the payment actually was made. (That is done
* when we increment the account's lifetime.)
- *
+ *
* @param cls closure
* @param anastasis_pub anastasis's public key
* @param post_counter how many uploads does @a amount pay for
* @param payment_secret payment secret which the user must provide with every
upload
* @return transaction status
*/
-enum ANASTASIS_DB_QueryStatus
-(*record_payment)(void *cls,
- const struct ANASTASIS_AccountPubP *anastasis_pub,
- unsigned int post_counter,
- const struct ANASTASIS_PaymentSecretP *payment_secret);
+ enum ANASTASIS_DB_QueryStatus
+ (*record_payment)(void *cls,
+ const struct ANASTASIS_AccountPubP *anastasis_pub,
+ uint32_t post_counter,
+ const struct ANASTASIS_PaymentSecretP *payment_secret);
};
#endif
diff --git a/src/lib/anastasis_api_policy.c b/src/lib/anastasis_api_policy.c
deleted file mode 100644
index 1236929..0000000
--- a/src/lib/anastasis_api_policy.c
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- This file is part of ANASTASIS
- Copyright (C) 2014-2017 GNUnet e.V. and INRIA
-
- ANASTASIS is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1,
- or (at your option) any later version.
-
- ANASTASIS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with ANASTASIS; see the file COPYING.LGPL. If not,
- see <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file lib/anastasis_api_policy.c
- * @brief Implementation of the /policy GET and POST
- * @author Christian Grothoff
- * @author Dennis Neufeld
- * @author Dominik Meister
- */
-#include "platform.h"
-#include <curl/curl.h>
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include <taler/taler_json_lib.h>
-#include <taler/taler_curl_lib.h>
-#include <taler/taler_util.h>
-#include "anastasis_service.h"
-
-
-/**
- * @brief A Contract Operation Handle
- */
-struct ANASTASIS_PolicyLookupOperation
-{
-
- /**
- * The url for this request, including parameters.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- ANASTASIS_PolicyLookupCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reference to the execution context.
- */
- struct GNUNET_CURL_Context *ctx;
-};
-
-
-struct ANASTASIS_PolicyStoreOperation
-{
- /**
- * Complete URL where the backend offers /policy
- */
- char *url;
-
- /**
- * Minor context that holds body and headers.
- */
- struct TEAH_PostContext post_ctx;
-
- /**
- * The CURL context to connect to the backend
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * The callback to pass the backend response to
- */
- ANASTASIS_PolicyStoreCallback cb;
-
- /**
- * Clasure to pass to the callback
- */
- void *cb_cls;
-
- /**
- * Handle for the request
- */
- struct GNUNET_CURL_Job *job;
-};
-
-
-
-/**
- * Cancel a pending /policy GET request
- *
- * @param handle from the operation to cancel
- */
-void
-ANASTASIS_policy_lookup_cancel (struct
- ANASTASIS_PolicyLookupOperation *plo)
-{
- if (NULL != plo->job)
- {
- GNUNET_CURL_job_cancel (plo->job);
- plo->job = NULL;
- }
- GNUNET_free (plo->url);
- GNUNET_free (plo);
-}
-
-
-/**
- * Process GET /policy response
- */
-static void
-handle_policy_lookup_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct ANASTASIS_PolicyLookupOperation *plo = cls;
- char *error;
- enum ANASTASIS_ErrorCode code;
- const json_t *json = response;
-
- plo->job = NULL;
- switch (response_code)
- {
- case 0:
- /* Hard error */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Backend didn't even return from GET /policy\n");
- return;
-
- case MHD_HTTP_OK:
- case MHD_HTTP_NOT_FOUND:
- plo->cb (plo->cb_cls,
- response_code,
- ANASTASIS_EC_NONE,
- json);
- break;
- default:
- /**
- * The backend gave response, but it's error, log it.
- * NOTE that json must be a ANASTASIS-specific error object (FIXME,
- * need a link to error objects at docs)
- */
- if (-1 == json_unpack ((json_t *) json,
- "{s:s, s:I, s:s}",
- "error", &error,
- "code", &code))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed GET /policy, error: %s, code: %d\n",
- error,
- code);
- break;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed /policy lookup, backend did not give"
- " a valid error object, HTTP code was %lu\n",
- response_code);
- }
-
- ANASTASIS_policy_lookup_cancel (plo);
-}
-
-
-/**
- * Does a GET /policy.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param anastasis_pub public key of the user's account
- * @param cb callback which will work the response gotten from the backend
- * @param cb_cls closure to pass to the callback
- * @return handle for this operation, NULL upon errors
- */
-struct ANASTASIS_PolicyLookupOperation *
-ANASTASIS_policy_lookup (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct ANASTASIS_AccountPubP *anastasis_pub,
- ANASTASIS_PolicyLookupCallback cb,
- void *cb_cls)
-{
- struct ANASTASIS_PolicyLookupOperation *plo;
- CURL *eh;
- char *acc_pub_str;
- char *path;
-
- plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
- plo->ctx = ctx;
- plo->cb = cb;
- plo->cb_cls = cb_cls;
- acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
- GNUNET_asprintf (&path,
- "policy/%s",
- acc_pub_str);
- GNUNET_free (acc_pub_str);
- plo->url = TALER_url_join (backend_url,
- path,
- NULL);
- GNUNET_free (path);
- eh = curl_easy_init ();
- if (CURLE_OK != curl_easy_setopt (eh,
- CURLOPT_URL,
- plo->url))
- {
- GNUNET_break (0);
- return NULL;
- }
-
- if (NULL == (plo->job = GNUNET_CURL_job_add (ctx,
- eh,
- GNUNET_NO,
- handle_policy_lookup_finished,
- plo)))
- {
- GNUNET_break (0);
- return NULL;
-
- }
-
- return plo;
-}
-
-
-/**
- * Does a GET /policy for a specific version.
- *
- * @param ctx execution context
- * @param backend_url base URL of the merchant backend
- * @param anastasis_pub public key of the user's account
- * @param cb callback which will work the response gotten from the backend
- * @param cb_cls closure to pass to the callback
- * @param version version of the policy to be requested
- * @return handle for this operation, NULL upon errors
- */
-struct ANASTASIS_PolicyLookupOperation *
-ANASTASIS_policy_lookup_version (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct
- ANASTASIS_AccountPubP *anastasis_pub,
- ANASTASIS_PolicyLookupCallback cb,
- void *cb_cls,
- uint32_t *version)
-{
- struct ANASTASIS_PolicyLookupOperation *plo;
- CURL *eh;
- char *acc_pub_str;
- char *path;
-
- plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
- plo->ctx = ctx;
- plo->cb = cb;
- plo->cb_cls = cb_cls;
- acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
- GNUNET_asprintf (&path,
- "policy/%s",
- acc_pub_str);
- GNUNET_free (acc_pub_str);
- plo->url = TALER_url_join (backend_url,
- path,
- "version",
- version,
- NULL);
- GNUNET_free (path);
- eh = curl_easy_init ();
- if (CURLE_OK != curl_easy_setopt (eh,
- CURLOPT_URL,
- plo->url))
- {
- GNUNET_break (0);
- return NULL;
- }
-
- if (NULL == (plo->job = GNUNET_CURL_job_add (ctx,
- eh,
- GNUNET_NO,
- handle_policy_lookup_finished,
- plo)))
- {
- GNUNET_break (0);
- return NULL;
-
- }
-
- return plo;
-}
-
-
-/**
- * Callback to process POST /policy response
- *
- * @param cls the `struct ANASTASIS_PolicyStoreOperation`
- * @param response_code HTTP response code, 0 on error
- * @param json response body, NULL if not JSON
- */
-static void
-handle_policy_store_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct ANASTASIS_PolicyStoreOperation *pso = cls;
- char *error;
- char *hint;
- enum ANASTASIS_ErrorCode code;
- const json_t *json = response;
-
- pso->job = NULL;
- switch (response_code)
- {
- case 0:
- /* Hard error */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Backend didn't even return from POST /policy\n");
- return;
-
- /* Good to hand everything to the callback, as all
- * the logic is actually there. */
- case MHD_HTTP_OK:
- case MHD_HTTP_BAD_REQUEST:
- case MHD_HTTP_NOT_FOUND:
- pso->cb (pso->cb_cls,
- response_code,
- ANASTASIS_EC_NONE,
- json);
- break;
- default:
- /**
- * The backend gave response, but it's error, log it.
- * NOTE that json must be a Anastasis-specific error object (FIXME,
- * need a link to error objects at docs)
- */
- if (-1 == json_unpack
- ((json_t *) json,
- "{s:s, s:I, s:s}",
- "error", &error,
- "code", &code,
- "hint", &hint))
-
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "/policy failed (HTTP code: %lu), backend did "
- "not give a valid error object\n", response_code);
- break;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "/policy, error: %s, code: %d, hint: %s\n",
- error,
- code,
- hint);
- }
- ANASTASIS_policy_store_cancel (pso);
-}
-
-
-/**
- * Cancel a POST /policy request.
- *
- * @param pso the policy store operation to cancel
- */
-void
-ANASTASIS_policy_store_cancel (struct
- ANASTASIS_PolicyStoreOperation *pso)
-{
- if (NULL != pso->job)
- {
- GNUNET_CURL_job_cancel (pso->job);
- pso->job = NULL;
- }
- TALER_curl_easy_post_finished (&pso->post_ctx);
- GNUNET_free (pso->url);
- GNUNET_free (pso);
-}
-
-
-/**
- * Store policies, does a POST /policy/$AccountPub
- *
- * @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 refund amount to which increase the refund
- * @param cb callback processing the response from /policy
- * @param cb_cls closure for cb
- */
-struct ANASTASIS_PolicyStoreOperation *
-ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const struct
- ANASTASIS_AccountPubP *anastasis_pub,
- const void *policy_data,
- size_t policy_data_size,
- const struct
- ANASTASIS_PaymentSecretP *paymentSecretP,
- ANASTASIS_PolicyStoreCallback cb,
- void *cb_cls)
-{
- struct ANASTASIS_PolicyStoreOperation *pso;
- CURL *eh;
- char *acc_pub_str;
- char *path;
-
- GNUNET_assert (NULL != policy_data);
- pso = GNUNET_new (struct ANASTASIS_PolicyStoreOperation);
- pso->ctx = ctx;
- pso->cb = cb;
- pso->cb_cls = cb_cls;
- acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
- GNUNET_asprintf (&path,
- "policy/%s",
- acc_pub_str);
- GNUNET_free (acc_pub_str);
- pso->url = TALER_url_join (backend_url,
- "policy",
- anastasis_pub);
- GNUNET_free (path);
- eh = curl_easy_init ();
- GNUNET_assert
- (NULL != (pso->post_ctx.headers = curl_slist_append
- (pso->post_ctx.headers,
- "Content-Type:
anastasis/encrypted-policy")));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_POSTFIELDS,
- policy_data));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_POSTFIELDSIZE,
- policy_data_size));
- GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
- CURLOPT_URL,
- pso->url));
- pso->job = GNUNET_CURL_job_add2
- (ctx,
- eh,
- pso->post_ctx.headers,
- &handle_policy_store_finished,
- pso);
-
- return pso;
-}
diff --git a/src/lib/testing_api_cmd_policy.c b/src/lib/testing_api_cmd_policy.c
deleted file mode 100644
index 8efc599..0000000
--- a/src/lib/testing_api_cmd_policy.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- This file is part of ANASTASIS
- Copyright (C) 2014-2019 Taler Systems SA
-
- ANASTASIS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- ANASTASIS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with ANASTASIS; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file lib/testing_api_cmd_policy.c
- * @brief command to execute the anastasis backend service.
- * @author Marcello Stanisci
- */
-
-#include "platform.h"
-#include "anastasis_service.h"
-#include "anastasis_testing_lib.h"
-#include <taler/taler_util.h>
-#include <taler/taler_testing_lib.h>
-
-/**
- * State for a "policy store" CMD.
- */
-struct PolicyStoreState
-{
-
- /**
- * The policy data.
- */
- const void *policy_data;
-
- /**
- * Expected status code.
- */
- unsigned int http_status;
-
- /**
- * Eddsa Publickey.
- */
- const struct ANASTASIS_AccountPubP *anastasis_pub;
-
- /**
- * The /policy POST operation handle.
- */
- struct ANASTASIS_PolicyStoreOperation *pso;
-
- /**
- * The nonce.
- */
- struct GNUNET_CRYPTO_EddsaPublicKey nonce;
-
- /**
- * URL of the anastasis backend.
- */
- const char *anastasis_url;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Payment identifier.
- */
- const struct ANASTASIS_PaymentSecretP *payment_id;
-};
-
-
-/**
- * State for a "policy lookup" CMD.
- */
-struct PolicyLookupState
-{
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Eddsa Publickey.
- */
- const struct ANASTASIS_AccountPubP anastasis_pub;
-
- /**
- * URL of the anastasis backend.
- */
- const char *anastasis_url;
-
- /**
- * Expected status code.
- */
- unsigned int http_status;
-
- /**
- * The /policy GET operation handle.
- */
- struct ANASTASIS_PolicyLookupOperation *plo;
-};
-
-
-/**
- * Run a "policy store" CMD.
- *
- * @param cls closure.
- * @param cmd command currently being run.
- * @param is interpreter state.
- */
-static void
-policy_store_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct PolicyStoreState *pss = cls;
-
- pss->is = is;
-
-
- GNUNET_CRYPTO_random_block
- (GNUNET_CRYPTO_QUALITY_WEAK,
- &pss->nonce,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
-
- pss->pso = ANASTASIS_policy_store (is->ctx,
- pss->anastasis_url,
- pss->anastasis_pub,
- pss->policy_data,
- sizeof (pss->policy_data),
- pss->payment_id,
- NULL,
- // &policy_store_cb,
- pss);
- GNUNET_assert (NULL != pss->pso);
-}
-
-
-/**
- * Free the state of a "policy sore" CMD, and possibly
- * cancel it if it did not complete.
- *
- * @param cls closure.
- * @param cmd command being freed.
- */
-static void
-policy_store_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct PolicyStoreState *pss = cls;
-
- if (NULL != pss->pso)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command '%s' did not complete (policy post)\n",
- cmd->label);
- ANASTASIS_policy_store_cancel (pss->pso);
- pss->pso = NULL;
- }
-
- // GNUNET_free_non_null ((void *) pss->order_id);
- GNUNET_free (pss);
-}
-
-
-/**
- * Make the "policy store" command.
- *
- * @param label command label
- * @param anastasis_url base URL of the anastasis serving
- * the policy store request.
- * @param http_status expected HTTP status.
- * @param pub account identifier
- * @param payment_id payment identifier
- * @param policy_data recovery data to post
- *
- * @return the command
- */
-struct TALER_TESTING_Command
-ANASTASIS_TESTING_cmd_policy_store (const char *label,
- const char *anastasis_url,
- unsigned int http_status,
- const struct
- ANASTASIS_AccountPubP *pub,
- const struct
- ANASTASIS_PaymentSecretP *payment_id,
- const void *policy_data)
-{
- struct PolicyStoreState *pss;
-
- pss = GNUNET_new (struct PolicyStoreState);
- pss->anastasis_pub = pub;
- pss->policy_data = policy_data;
- pss->payment_id = payment_id;
- pss->http_status = http_status;
- pss->anastasis_url = anastasis_url;
-
- struct TALER_TESTING_Command cmd = {
- .cls = pss,
- .label = label,
- .run = &policy_store_run,
- .cleanup = &policy_store_cleanup
- };
-
- return cmd;
-}
\ No newline at end of file
diff --git a/src/stasis/plugin_anastasis_postgres.c
b/src/stasis/plugin_anastasis_postgres.c
index 383fe81..f23484f 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -216,7 +216,7 @@ commit_transaction (void *cls)
* Lookup pending payments by account.
*
* @param cls closure
- * @param account_pub account to look for pending payment under
+ * @param anastasis_pub account to look for pending payment under
*/
static enum ANASTASIS_DB_QueryStatus
postgres_lookup_pending_payment_by_account (void *cls,
@@ -298,11 +298,11 @@ postgres_store_recovery_document (void *cls,
const struct
ANASTASIS_AccountSignatureP *account_sig,
const struct
- GNUNET_HashCode *old_data_hash,
+ GNUNET_HashCode *old_recovery_data_hash,
const struct
- GNUNET_HashCode *data_hash,
- const void *data,
- size_t data_size,
+ GNUNET_HashCode *recovery_data_hash,
+ const void *recovery_data,
+ size_t recovery_data_size,
const struct
ANASTASIS_PaymentSecretP *payment_secret,
uint32_t *version)
@@ -313,31 +313,59 @@ postgres_store_recovery_document (void *cls,
struct GNUNET_HashCode dh;
check_connection (pg);
- if (GNUNET_OK != begin_transaction (pg,
- "store_recovery_document"))
+ postgres_preflight (pg);
+ /* get the version for the recoverydocument */
{
- GNUNET_break (0);
- return ANASTASIS_DB_STATUS_HARD_ERROR;
- }
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("version", version),
+ GNUNET_PQ_result_spec_end
+ };
- /* Check if user has paid */
- qs = postgres_lookup_pending_payment_by_account (pg,
- anastasis_pub);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+
"latest_recovery_version_select",
+ params,
+ rs);
+ }
+ switch (qs)
+ {
+ case ANASTASIS_DB_STATUS_HARD_ERROR:
+ rollback (pg);
+ return qs;
+ case ANASTASIS_DB_STATUS_SOFT_ERROR:
+ // FIXME: or: retry internally?
+ rollback (pg);
+ return qs;
+ case ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS:
+ *version = 1;
+ break;
+ case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
+ (*version)++;
+ break;
+ default:
+ // FIXME: Some Action
+ rollback (pg);
+ return qs;
+ }
- // check if existing recoverydocument conflicts
+ /* First, check if account exists */
{
+ struct GNUNET_TIME_Absolute ed;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
- &dh),
+ GNUNET_PQ_result_spec_auto_from_type ("paid_until",
+ &ed),
GNUNET_PQ_result_spec_end
};
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-
"recoverydocument_select_hash",
+ "user_select",
params,
rs);
}
@@ -349,9 +377,7 @@ postgres_store_recovery_document (void *cls,
GNUNET_break (0);
return ANASTASIS_DB_STATUS_SOFT_ERROR;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* Well, trying to update where there is no original
- is a hard erorr, even though an odd one */
- return ANASTASIS_DB_STATUS_HARD_ERROR;
+ return ANASTASIS_DB_STATUS_PAYMENT_REQUIRED;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
/* handle interesting case below */
break;
@@ -360,19 +386,6 @@ postgres_store_recovery_document (void *cls,
return ANASTASIS_DB_STATUS_HARD_ERROR;
}
- /* had an existing recoverydocument, is it identical? */
- if (0 == GNUNET_memcmp (&dh,
- data_hash))
- /* recoverydocument identical to what was provided, no change */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- if (0 == GNUNET_memcmp (&dh,
- old_data_hash))
- /* all constraints seem satisified, original error must
- have been a hard error */
- return GNUNET_DB_STATUS_HARD_ERROR;
- /* previous backup does not match old_backup_hash */
- return ANASTASIS_DB_STATUS_OLD_RECOVERY_UPLOAD_MISSMATCH;
-
// lookup if the user has enough uploads left and decrement
{
struct GNUNET_PQ_QueryParam params[] = {
@@ -452,88 +465,88 @@ postgres_store_recovery_document (void *cls,
return qs;
}
- /* get the version for the recoverydocument */
+ /* check if existing recovery_data conflicts */
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint32 ("version", version),
+ GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
+ &dh),
GNUNET_PQ_result_spec_end
};
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-
"latest_recovery_version_select",
+
"recoverydocument_select_hash",
params,
rs);
}
switch (qs)
{
- case ANASTASIS_DB_STATUS_HARD_ERROR:
- rollback (pg);
- return qs;
- case ANASTASIS_DB_STATUS_SOFT_ERROR:
- // FIXME: or: retry internally?
- rollback (pg);
- return qs;
- case ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS:
- *version = 1;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_SOFT_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* original error must have been a hard error, oddly enough */
+ //return ANASTASIS_DB_STATUS_HARD_ERROR;
break;
- case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
- (*version)++;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* handle interesting case below */
break;
default:
- // FIXME: Some Action
- rollback (pg);
- return qs;
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
}
-
+ /* had an existing recovery_data, is it identical? */
+ if (0 == GNUNET_memcmp (&dh,
+ recovery_data_hash))
+ /* previous conflicting recovery_data exists */
+ return ANASTASIS_DB_STATUS_OLD_RECOVERY_UPLOAD_MISSMATCH;
+
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_uint32 (version),
- GNUNET_PQ_query_param_fixed_size (data, data_size),
+ GNUNET_PQ_query_param_auto_from_type (account_sig),
+ GNUNET_PQ_query_param_auto_from_type (old_recovery_data_hash),
+ GNUNET_PQ_query_param_auto_from_type (recovery_data_hash),
+ GNUNET_PQ_query_param_fixed_size (recovery_data,
+ recovery_data_size),
GNUNET_PQ_query_param_end
};
+
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
"recovery_document_insert",
params);
}
-
switch (qs)
{
- case ANASTASIS_DB_STATUS_HARD_ERROR:
- rollback (pg);
- return qs;
- case ANASTASIS_DB_STATUS_SOFT_ERROR:
- // FIXME: or: retry internally?
- rollback (pg);
- return qs;
- case ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_break (0);
- rollback (pg);
- return ANASTASIS_DB_STATUS_HARD_ERROR;
- case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
+ return ANASTASIS_DB_STATUS_SOFT_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ /* handle interesting case below */
break;
default:
- // FIXME: Some Action
- rollback (pg);
- return qs;
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
}
-
- qs = commit_transaction (pg);
- if (qs < 0)
- return qs;
- return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
-
+ return qs;
}
/**
* Increment account lifetime.
*
* @param cls closure
- * @param account_pub which account received a payment
+ * @param anastasis_pub which account received a payment
* @param payment_identifier proof of payment, must be unique and match
pending payment
* @param lifetime for how long is the account now paid (increment)
* @return transaction status
@@ -541,7 +554,8 @@ postgres_store_recovery_document (void *cls,
static enum ANASTASIS_DB_QueryStatus
postgres_increment_lifetime (void *cls,
const struct ANASTASIS_AccountPubP *anastasis_pub,
- const struct ANASTASIS_PaymentSecretP
*payment_identifier,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_identifier,
struct GNUNET_TIME_Relative lifetime)
{
struct PostgresClosure *pg = cls;
@@ -584,7 +598,7 @@ postgres_increment_lifetime (void *cls,
return ANASTASIS_DB_STATUS_SOFT_ERROR;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
{
- //user does not exist, create new one
+ // user does not exist, create new one
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_absolute_time (&expiration),
@@ -599,7 +613,7 @@ postgres_increment_lifetime (void *cls,
break;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
{
- //user exists, update paid_until
+ // user exists, update paid_until
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_absolute_time (&expiration),
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
@@ -658,7 +672,7 @@ postgres_increment_lifetime (void *cls,
* Store payment. Used to begin a payment, not indicative
* that the payment actually was made. (That is done
* when we increment the account's lifetime.)
- *
+ *
* @param cls closure
* @param anastasis_pub anastasis's public key
* @param post_counter how many uploads does @a amount pay for
@@ -668,7 +682,7 @@ postgres_increment_lifetime (void *cls,
static enum ANASTASIS_DB_QueryStatus
postgres_record_payment (void *cls,
const struct ANASTASIS_AccountPubP *anastasis_pub,
- unsigned int post_counter,
+ uint32_t post_counter,
const struct ANASTASIS_PaymentSecretP *payment_secret)
{
struct PostgresClosure *pg = cls;
@@ -915,30 +929,47 @@ postgres_get_latest_recovery_document (void *cls,
uint32_t *version)
{
struct PostgresClosure *pg = cls;
+ enum ANASTASIS_DB_QueryStatus qs;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_variable_size ("recovery_data",
- data,
- data_size),
+ GNUNET_PQ_result_spec_uint32 ("version",
+ version),
GNUNET_PQ_result_spec_auto_from_type ("account_sig",
account_sig),
GNUNET_PQ_result_spec_auto_from_type ("prev_hash",
prev_hash),
GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
recovery_data_hash),
- GNUNET_PQ_result_spec_uint32 ("version",
- version),
+ GNUNET_PQ_result_spec_variable_size ("recovery_data",
+ data,
+ data_size),
GNUNET_PQ_result_spec_end
};
check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ postgres_preflight (pg);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"latest_recoverydocument_select",
params,
rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_SOFT_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+ default:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ }
}
@@ -971,29 +1002,45 @@ postgres_get_recovery_document (void *cls,
{
struct PostgresClosure *pg = cls;
+ enum ANASTASIS_DB_QueryStatus qs;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
GNUNET_PQ_query_param_uint32 (&version),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_variable_size ("recovery_data",
- data,
- data_size),
GNUNET_PQ_result_spec_auto_from_type ("account_sig",
account_sig),
GNUNET_PQ_result_spec_auto_from_type ("prev_hash",
prev_hash),
GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
recovery_data_hash),
+ GNUNET_PQ_result_spec_variable_size ("recovery_data",
+ data,
+ data_size),
GNUNET_PQ_result_spec_end
};
check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "recoverydocument_select",
- params,
- rs);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "recoverydocument_select",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_SOFT_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+ default:
+ GNUNET_break (0);
+ return ANASTASIS_DB_STATUS_HARD_ERROR;
+ }
}
/**
@@ -1032,10 +1079,10 @@ libanastasis_plugin_db_postgres_init (void *cls)
");"),
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS
anastasis_recoverydocument"
"( user_id BYTEA NOT NULL REFERENCES
anastasis_user(user_id),"
- " version INTEGER NOT NULL,"
- " account_sig BYTEA NOT NULL CHECK
(length(account_sig)=64),"
- " prev_hash BYTEA NOT NULL CHECK
(length(prev_hash)=64),"
- " recovery_data_hash BYTEA NOT NULL CHECK
(length(backup_hash)=64),"
+ " version INT4 NOT NULL,"
+ " account_sig BYTEA NOT NULL
CHECK(LENGTH(account_sig)=64),"
+ " prev_hash BYTEA NOT NULL
CHECK(LENGTH(prev_hash)=64),"
+ " recovery_data_hash BYTEA NOT NULL
CHECK(length(recovery_data_hash)=64),"
" recovery_data BYTEA NOT NULL,"
" PRIMARY KEY (user_id, version)"
");"),
@@ -1070,6 +1117,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
"(user_id"
",post_counter"
",payment_identifier"
+ ",transaction_time"
") VALUES "
"($1, $2, $3, $4);",
4),
@@ -1184,7 +1232,8 @@ libanastasis_plugin_db_postgres_init (void *cls)
plugin->get_latest_recovery_document =
&postgres_get_latest_recovery_document;
plugin->get_recovery_document = &postgres_get_recovery_document;
plugin->lookup_account = &postgres_lookup_account;
- plugin->lookup_pending_payment_by_account =
&postgres_lookup_pending_payment_by_account;
+ plugin->lookup_pending_payment_by_account =
+ &postgres_lookup_pending_payment_by_account;
plugin->increment_lifetime = &postgres_increment_lifetime;
plugin->start = &begin_transaction;
plugin->check_connection = &check_connection;
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index aaf9dea..5958d1e 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -27,6 +27,7 @@
#include "anastasis_database_lib.h"
#include "anastasis_error_codes.h"
#include <uuid/uuid.h>
+#include <gnunet/gnunet_signatures.h>
#define FAILIF(cond) \
@@ -61,20 +62,41 @@ static struct ANASTASIS_PaymentSecretP paymentSecretP;
static struct ANASTASIS_AccountPubP accountPubP;
/**
- * Signature over hash of body affirming desire to upload an recovery document
+ * User private key
*/
-static struct ANASTASIS_AccountSignatureP account_sig;
+static struct ANASTASIS_AccountPrivP accountPrivP;
+
+/**
+ * Signature
+ */
+static struct ANASTASIS_AccountSignatureP accountSig;
+
+/**
+ * Signature
+ */
+struct ANASTASIS_AccountSignatureP res_account_sig;
/**
* Hash of the previous uploaded recovery doucument
* (normally the latest version stored in db before upload)
*/
-static struct GNUNET_HashCode prev_hash;
+struct GNUNET_HashCode prevHash;
/**
* Hash of the recovery document to be uploaded
*/
-static struct GNUNET_HashCode recovery_data_hash;
+struct GNUNET_HashCode recoveryDataHash;
+
+/**
+ * Hash of the previous uploaded recovery doucument
+ * (normally the latest version stored in db before upload)
+ */
+struct GNUNET_HashCode res_prev_hash;
+
+/**
+ * Hash of the current recovery document
+ */
+struct GNUNET_HashCode res_recovery_data_hash;
/**
* Amount which is deposited, set to random value
@@ -129,12 +151,12 @@ static char *res_mime_type;
/**
* Version of a Recoverydocument
*/
-static uint32_t version;
+static uint32_t docVersion;
/**
* Version of the latest Recoverydocument
*/
-static uint32_t res_version;
+static uint32_t *res_version;
/**
@@ -166,21 +188,35 @@ run (void *cls)
return;
}
- uint32_t recversion = 1;
+ static uint32_t recversion = 1;
size_t truthsize;
size_t recoverydatasize;
size_t keysharesize;
- RND_BLK (&accountPubP);
+ const char *str = "AHV123456789";
+ struct GNUNET_CRYPTO_EccSignaturePurpose purp;
+
+ GNUNET_CRYPTO_eddsa_private_key_from_string (str,
+ sizeof (str),
+ &accountPrivP.priv);
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&accountPrivP.priv,
+ &accountPubP.pub);
int rec_val = 100;
recovery_data = &rec_val;
RND_BLK (recovery_data);
- GNUNET_CRYPTO_hash (recovery_data,
- sizeof (recovery_data),
- &recovery_data_hash);
+ GNUNET_CRYPTO_hash (recovery_data,
+ sizeof (recovery_data),
+ &recoveryDataHash);
+
+ purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
+ purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
+ GNUNET_CRYPTO_eddsa_sign (&accountPrivP.priv,
+ &purp,
+ &accountSig.eddsa_sig);
RND_BLK (&paymentSecretP);
-
+
int truth_val = 300;
truth_data = &truth_val;
RND_BLK (truth_data);
@@ -197,18 +233,22 @@ run (void *cls)
struct GNUNET_TIME_Relative rel_time;
rel_time = GNUNET_TIME_UNIT_MONTHS;
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->increment_lifetime (plugin->cls,
+ &accountPubP,
+ &paymentSecretP,
+ rel_time));
+
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->lookup_account (plugin->cls,
+ &accountPubP));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->record_payment (plugin->cls,
- &amount,
&accountPubP,
post_counter,
- rel_time,
&paymentSecretP));
-
- FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->lookup_account (plugin->cls,
- &accountPubP));
-
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_truth (plugin->cls,
&uuid,
@@ -218,25 +258,18 @@ run (void *cls)
key_share,
sizeof (&key_share),
rel_time));
-
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_recovery_document (plugin->cls,
&accountPubP,
- &account_sig,
- &prev_hash,
- &recovery_data_hash,
+ &accountSig,
+ &prevHash,
+ &recoveryDataHash,
&recovery_data,
sizeof (&recovery_data),
&paymentSecretP,
- &version));
-
- FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_latest_recovery_document (plugin->cls,
- &accountPubP,
- &recoverydatasize,
- &res_recovery_data,
- &res_version));
-
+ &docVersion));
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_escrow_challenge (plugin->cls,
&uuid,
@@ -249,13 +282,26 @@ run (void *cls)
&uuid,
&res_key_share,
&keysharesize));
-
+
FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_recovery_document (plugin->cls,
&accountPubP,
+ &res_account_sig,
+ &res_prev_hash,
+ &res_recovery_data_hash,
recversion,
&recoverydatasize,
&res_recovery_data));
+
+ FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_latest_recovery_document (plugin->cls,
+ &accountPubP,
+ &res_account_sig,
+ &res_prev_hash,
+ &res_recovery_data_hash,
+ &recoverydatasize,
+ &res_recovery_data,
+ res_version));
if (-1 == result)
result = 0;
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: Worked on test. Not working...,
gnunet <=