merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit a4c5cda0a40ef1987d93b7aacaa7caa993f8b838
parent 4ebac01e89badb29d361b49310cdd1cc6397b563
Author: Christian Blättler <blatc2@bfh.ch>
Date:   Wed, 20 Mar 2024 07:53:49 +0100

first smoke tests

Diffstat:
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 152+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/backenddb/pg_lookup_token_family_key.c | 14+++++++++-----
2 files changed, 87 insertions(+), 79 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1434,6 +1434,8 @@ serialize_order (struct OrderContext *oc) } oc->serialize_order.contract = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_int64 ("version", + oc->parse_order.version), GNUNET_JSON_pack_string ("summary", oc->parse_order.summary), GNUNET_JSON_pack_allow_null ( @@ -1480,7 +1482,7 @@ serialize_order (struct OrderContext *oc) GNUNET_JSON_pack_array_incref ("exchanges", oc->set_exchanges.exchanges), TALER_JSON_pack_amount ("max_fee", - &oc->parse_order.max_fee), + &oc->set_max_fee.max_fee), TALER_JSON_pack_amount ("amount", &oc->parse_order.brutto), GNUNET_JSON_pack_allow_null ( @@ -1748,7 +1750,7 @@ parse_order (struct OrderContext *oc) ret); return; } - if (NULL == version || 0 == strcmp("v0", version)) + if (NULL == version || 0 == strcmp("0", version)) { oc->parse_order.version = TALER_MCV_V0; @@ -1774,9 +1776,32 @@ parse_order (struct OrderContext *oc) return; } } - else if (0 != strcmp("v1", version)) + else if (0 == strcmp("1", version)) { oc->parse_order.version = TALER_MCV_V1; + + if (! json_is_array(oc->parse_order.choices)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "order.choices is not a valid array"); + return; + } + + if (oc->parse_order.token_types != NULL && + ! json_is_object(oc->parse_order.token_types)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "order.token_types is not a valid object"); + return; + } } else { @@ -1785,17 +1810,7 @@ parse_order (struct OrderContext *oc) reply_with_error (oc, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_VERSION_MALFORMED, - "invalid version specified in order, supported are null, 'v0' or 'v1'"); - return; - } - if (NULL == oc->parse_order.choices && TALER_MCV_V0 != oc->parse_order.version) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_UNEXPECTED_REQUEST_ERROR, - "choices array must not be null for v1 contracts"); + "invalid version specified in order, supported are null, '0' or '1'"); return; } if (! TMH_test_exchange_configured_for_currency ( @@ -2101,73 +2116,60 @@ parse_token_types (struct OrderContext *oc) const char *key; json_t *value; - GNUNET_array_grow (oc->parse_token_types.authorities, - oc->parse_token_types.authorities_len, - json_object_size(oc->parse_order.token_types)); - json_object_foreach ((json_t*) oc->parse_order.token_types, key, value) { struct TALER_MerchantContractTokenAuthority authority; - const struct json_t *pub_key; - - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_object_const ("key", &pub_key), - GNUNET_JSON_spec_bool ("critical", &authority.critical), - }; + const json_t *jpublic_key = NULL; - if (GNUNET_OK != - GNUNET_JSON_parse (value, - spec, - NULL, - NULL)) { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types"); - return; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_object_const ("key", &jpublic_key), + GNUNET_JSON_spec_bool ("critical", &authority.critical), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (value, + spec, + NULL, + NULL)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "token_types failed to parse"); + return; + } } - const char *cipher = NULL; - - struct GNUNET_JSON_Specification kspec[] = { - GNUNET_JSON_spec_string ("cipher", &cipher), - GNUNET_JSON_spec_rsa_public_key("public_key", &authority.key.public_key.details.rsa_public_key), - }; - if (GNUNET_OK != - GNUNET_JSON_parse (pub_key, - kspec, - NULL, - NULL)) { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (kspec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types.key"); - return; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_rsa_public_key ("rsa_pub", &authority.key.public_key.details.rsa_public_key), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (jpublic_key, + spec, + NULL, + NULL)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + reply_with_error (oc, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "key object of token type is invalid"); + return; + } } - if (0 == strcmp("rsa", cipher)) - { - authority.key.public_key.cipher = GNUNET_CRYPTO_BSA_RSA; - } - else - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (kspec); - reply_with_error (oc, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token_types.key.cipher"); - return; - } + authority.key.public_key.cipher = GNUNET_CRYPTO_BSA_RSA; GNUNET_CRYPTO_rsa_public_key_hash ( authority.key.public_key.details.rsa_public_key, @@ -2209,17 +2211,16 @@ parse_token_types (struct OrderContext *oc) /* case listed to make compilers happy */ GNUNET_assert (0); } - json_decref (oc->merge_inventory.products); reply_with_error (oc, http_status, ec, - "token family public key unknown"); + "token type public key unknown"); return; } + // TODO: Copy relevant fields from key_details to authority strcpy((char *) authority.label, key); strcpy((char *) authority.summary, key_details.token_family.description); - // TODO: Copy summary_i18n switch (key_details.token_family.kind) { case TALER_MERCHANTDB_TFK_Subscription: @@ -2264,13 +2265,14 @@ parse_choices (struct OrderContext *oc) &jinputs), GNUNET_JSON_spec_array_const ("outputs", &joutputs), + GNUNET_JSON_spec_end () }; enum GNUNET_GenericReturnValue ret; ret = GNUNET_JSON_parse (json_array_get (oc->parse_order.choices, i), - spec, - &error_name, - &error_line); + spec, + &error_name, + &error_line); if (GNUNET_OK != ret) { GNUNET_JSON_parse_free (spec); @@ -2314,6 +2316,7 @@ parse_choices (struct OrderContext *oc) GNUNET_JSON_spec_uint32 ("number", &input.details.token.number), &no_number), + GNUNET_JSON_spec_end() }; const char *ename; @@ -2425,6 +2428,7 @@ parse_choices (struct OrderContext *oc) GNUNET_JSON_spec_uint32 ("number", &output.details.token.number), &no_number), + GNUNET_JSON_spec_end() }; const char *ename; diff --git a/src/backenddb/pg_lookup_token_family_key.c b/src/backenddb/pg_lookup_token_family_key.c @@ -58,9 +58,9 @@ TMH_PG_lookup_token_family_key (void *cls, char *cipher; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_pub", - &details->pub_h), // TODO: Figure out how to parse keys + // GNUNET_PQ_result_spec_auto_from_type ("h_pub", + // &details->pub_h), // GNUNET_PQ_result_spec_auto_from_type ("pub", // &details->pub), // GNUNET_PQ_result_spec_auto_from_type ("priv", @@ -71,6 +71,10 @@ TMH_PG_lookup_token_family_key (void *cls, &details->token_family.slug), GNUNET_PQ_result_spec_string ("name", &details->token_family.name), + GNUNET_PQ_result_spec_timestamp ("merchant_token_family_keys.valid_after", + &details->valid_after), + GNUNET_PQ_result_spec_timestamp ("merchant_token_family_keys.valid_before", + &details->valid_before), GNUNET_PQ_result_spec_string ("description", &details->token_family.description), TALER_PQ_result_spec_json ("description_i18n", @@ -98,8 +102,8 @@ TMH_PG_lookup_token_family_key (void *cls, ",pub" ",priv" ",cipher" - ",valid_after" - ",valid_before" + ",merchant_token_family_keys.valid_after" + ",merchant_token_family_keys.valid_before" ",slug" ",name" ",description" @@ -116,7 +120,7 @@ TMH_PG_lookup_token_family_key (void *cls, " JOIN merchant_instances" " USING (merchant_serial)" " WHERE merchant_instances.merchant_id=$1" - " AND merchant_token_families.slug=$2"); + " AND h_pub=$2"); enum GNUNET_DB_QueryStatus qs; qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "lookup_token_family_key",