diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-06-13 17:33:43 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-06-13 17:33:43 +0200 |
commit | d72b878a0e33aa1f312547c56c75fcd6f7cd6cc1 (patch) | |
tree | 5aa24b382695d88f1c2cd5133121a1df4643d13f /src | |
parent | 7d63433cedc03f561920708cd92ba1e5377dcbf5 (diff) |
allow for token envelopes being null
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.c | 32 |
1 files changed, 27 insertions, 5 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 08e4b6d8..5af827e7 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -2394,6 +2394,7 @@ static enum GNUNET_GenericReturnValue sign_token_envelopes (struct PayContext *pc, struct TALER_MerchantContractTokenFamilyKey *key, struct TALER_TokenIssuePrivateKeyP *priv, + bool critical, unsigned int index, unsigned int expected_num) { @@ -2403,20 +2404,32 @@ sign_token_envelopes (struct PayContext *pc, { unsigned int pos = index + j; - /* TODO: Handle missing envelopes for non-critical output tokens. */ if (pos > pc->token_envelopes_cnt || pos > pc->output_tokens_len) { + GNUNET_assert (0); /* this should not happen */ + return GNUNET_NO; + } + + struct TokenEnvelope *env = &pc->token_envelopes[pos]; + + if (NULL == env) + { + if (!critical) + { + continue; + } + + /* critical token families require a token envelope. */ GNUNET_break (0); pay_end (pc, TALER_MHD_reply_with_error (pc->connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, - "Token envelope array is missing " - "required token envelope")); + "Token envelope for critical " + "token family missing")); return GNUNET_NO; } - struct TokenEnvelope *env = &pc->token_envelopes[index + j]; - struct SignedOutputToken *output = &pc->output_tokens[index + j]; + struct SignedOutputToken *output = &pc->output_tokens[pos]; TALER_token_issue_sign (priv, &env->blinded_token, @@ -2622,6 +2635,9 @@ phase_validate_tokens (struct PayContext *pc) if (GNUNET_OK != sign_token_envelopes (pc, &key, &details.priv, + /* TODO: Use critical field stored in database here instead. */ + details.token_family.kind == + TALER_MERCHANTDB_TFK_Subscription, i, output.details.token.count)) { @@ -3435,6 +3451,12 @@ phase_parse_pay (struct PayContext *pc) 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", |