aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-06-13 17:56:22 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-06-13 17:56:22 +0200
commite62fe71de43a1325822e5768cc040609030fccd6 (patch)
tree65afdbf1b6e89f83db94d78c74da0ce63b3a40b8 /src
parentcf4679e7b21cafa878903cf679167a7e90c8ac61 (diff)
move tokens_evs to wallet data and remove h_outputs
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c160
-rw-r--r--src/lib/merchant_api_post_order_pay.c10
2 files changed, 74 insertions, 96 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index 5af827e7..cbfd8fdd 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -3106,24 +3106,24 @@ phase_check_contract (struct PayContext *pc)
static void
phase_parse_wallet_data (struct PayContext *pc)
{
- struct GNUNET_HashCode h_outputs_req;
pc->choice_index = -1;
- // TODO: Ensure that wallet_data must be set for contracts with choices.
if (NULL == pc->wallet_data)
{
pc->phase = PP_CHECK_CONTRACT;
return;
}
+ const json_t *tokens_evs;
+
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_mark_optional(
GNUNET_JSON_spec_int64 ("choice_index",
&pc->choice_index),
NULL),
- GNUNET_JSON_spec_mark_optional(
- GNUNET_JSON_spec_fixed_auto ("h_outputs",
- &h_outputs_req),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const ("tokens_evs",
+ &tokens_evs),
NULL),
GNUNET_JSON_spec_end ()
};
@@ -3143,16 +3143,78 @@ phase_parse_wallet_data (struct PayContext *pc)
return;
}
- if (0 != GNUNET_CRYPTO_hash_cmp(&h_outputs_req, &pc->h_outputs))
+ pc->token_envelopes_cnt = json_array_size (tokens_evs);
+ if (pc->token_envelopes_cnt > MAX_TOKEN_ALLOWED_OUTPUTs)
{
GNUNET_break_op (0);
pay_end (pc,
- TALER_MHD_reply_with_error (pc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "'wallet_data.h_outputs' does not match hash of tokens_evs"));
+ TALER_MHD_reply_with_error (
+ pc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "'tokens_evs' array too long"));
return;
}
+ if (0 < pc->token_envelopes_cnt)
+ {
+ /* Calculate output commitment to be verified later. */
+ TALER_json_hash (tokens_evs,
+ &pc->h_outputs);
+ }
+
+ pc->token_envelopes = GNUNET_new_array (pc->token_envelopes_cnt,
+ struct TokenEnvelope);
+
+ {
+ unsigned int tokens_ev_index;
+ json_t *token_ev;
+
+ json_array_foreach (tokens_evs, tokens_ev_index, token_ev)
+ {
+ if (json_is_null (token_ev))
+ {
+ // Skip null envelopes
+ continue;
+ }
+
+ struct TokenEnvelope *ev = &pc->token_envelopes[tokens_ev_index];
+ struct GNUNET_JSON_Specification ispec[] = {
+ TALER_JSON_spec_token_envelope ("token_ev",
+ &ev->blinded_token),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (pc->connection,
+ token_ev,
+ ispec);
+ if (GNUNET_YES != res)
+ {
+ GNUNET_break_op (0);
+ pay_end (pc,
+ (GNUNET_NO == res)
+ ? MHD_YES
+ : MHD_NO);
+ return;
+ }
+
+ for (unsigned int j = 0; j<tokens_ev_index; j++)
+ {
+ if (0 ==
+ GNUNET_memcmp (ev->blinded_token.blinded_pub,
+ pc->token_envelopes[j].blinded_token.blinded_pub))
+ {
+ GNUNET_break_op (0);
+ pay_end (pc,
+ TALER_MHD_reply_with_error (pc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "duplicate token envelope in list"));
+ return;
+ }
+ }
+ }
+ }
TALER_json_hash (pc->wallet_data,
&pc->h_wallet_data);
@@ -3173,7 +3235,6 @@ phase_parse_pay (struct PayContext *pc)
const char *session_id = NULL;
const json_t *coins;
const json_t *tokens;
- const json_t *tokens_evs;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_array_const ("coins",
&coins),
@@ -3189,10 +3250,6 @@ phase_parse_pay (struct PayContext *pc)
GNUNET_JSON_spec_array_const ("tokens",
&tokens),
NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_array_const ("tokens_evs",
- &tokens_evs),
- NULL),
GNUNET_JSON_spec_end ()
};
@@ -3422,79 +3479,6 @@ phase_parse_pay (struct PayContext *pc)
}
}
- pc->token_envelopes_cnt = json_array_size (tokens_evs);
- if (pc->token_envelopes_cnt > MAX_TOKEN_ALLOWED_OUTPUTs)
- {
- GNUNET_break_op (0);
- pay_end (pc,
- TALER_MHD_reply_with_error (
- pc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "'tokens_evs' array too long"));
- return;
- }
- if (0 < pc->token_envelopes_cnt)
- {
- /* Calculate output commitment to be verified later. */
- TALER_json_hash (tokens_evs,
- &pc->h_outputs);
-
- }
-
- pc->token_envelopes = GNUNET_new_array (pc->token_envelopes_cnt,
- struct TokenEnvelope);
-
- {
- unsigned int tokens_ev_index;
- json_t *token_ev;
-
- json_array_foreach (tokens_evs, tokens_ev_index, token_ev)
- {
- if (json_is_null (token_ev))
- {
- // Skip null envelopes
- continue;
- }
-
- struct TokenEnvelope *ev = &pc->token_envelopes[tokens_ev_index];
- struct GNUNET_JSON_Specification ispec[] = {
- TALER_JSON_spec_token_envelope ("token_ev",
- &ev->blinded_token),
- GNUNET_JSON_spec_end ()
- };
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (pc->connection,
- token_ev,
- ispec);
- if (GNUNET_YES != res)
- {
- GNUNET_break_op (0);
- pay_end (pc,
- (GNUNET_NO == res)
- ? MHD_YES
- : MHD_NO);
- return;
- }
-
- for (unsigned int j = 0; j<tokens_ev_index; j++)
- {
- if (0 ==
- GNUNET_memcmp (ev->blinded_token.blinded_pub,
- pc->token_envelopes[j].blinded_token.blinded_pub))
- {
- GNUNET_break_op (0);
- pay_end (pc,
- TALER_MHD_reply_with_error (pc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "duplicate token envelope in list"));
- return;
- }
- }
- }
- }
pc->phase = PP_PARSE_WALLET_DATA;
}
diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c
index b34240b6..cf06630a 100644
--- a/src/lib/merchant_api_post_order_pay.c
+++ b/src/lib/merchant_api_post_order_pay.c
@@ -497,9 +497,6 @@ TALER_MERCHANT_order_pay_frontend (
GNUNET_JSON_pack_array_steal ("tokens",
j_tokens)),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_array_incref ("tokens_evs",
- j_output_tokens)),
- GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("wallet_data",
(json_t *) wallet_data)),
GNUNET_JSON_pack_allow_null (
@@ -590,7 +587,6 @@ TALER_MERCHANT_order_pay (
{
json_t *j_output_tokens = NULL;
const json_t *wallet_data = NULL;
- struct GNUNET_HashCode h_outputs;
struct GNUNET_HashCode wallet_data_hash;
if (GNUNET_YES !=
@@ -630,8 +626,6 @@ TALER_MERCHANT_order_pay (
return NULL;
}
}
-
- TALER_json_hash (j_output_tokens, &h_outputs);
}
if (0 <= choice_index)
{
@@ -639,8 +633,8 @@ TALER_MERCHANT_order_pay (
GNUNET_JSON_pack_int64 ("choice_index",
choice_index),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_data_auto ("h_outputs",
- &h_outputs)));
+ GNUNET_JSON_pack_array_incref ("tokens_evs",
+ j_output_tokens)));
TALER_json_hash (wallet_data,
&wallet_data_hash);
}