diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 165 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 17 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 17 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 4 |
4 files changed, 108 insertions, 95 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index d24f10a9..8a32b2ba 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -39,19 +39,20 @@ /** - * Merchant's private key + * Our wire format details in JSON format (with salt). */ -struct GNUNET_CRYPTO_EddsaPrivateKey *privkey; +struct json_t *j_wire; /** - * Our wireformat + * Hash of our wire format details as given in #j_wire. */ -struct MERCHANT_WIREFORMAT_Sepa *wire; +struct GNUNET_HashCode h_wire; + /** - * Salt used to hash the wire object + * Merchant's private key */ -long long salt; +struct GNUNET_CRYPTO_EddsaPrivateKey *privkey; /** * Our hostname @@ -131,35 +132,6 @@ static struct MHD_Daemon *mhd; /** - * Take the global wire details and return a JSON containing them, - * compliantly with the Taler's API. - * - * @param wire the merchant's wire details - * @param salt the nounce for hashing the wire details with - * @param edate when the beneficiary wants this transfer to take place - * @return JSON representation of the wire details, NULL upon errors - */ -json_t * -MERCHANT_get_wire_json (const struct MERCHANT_WIREFORMAT_Sepa *wire, - uint64_t salt) - -{ - json_t *root; - json_t *j_salt; - - j_salt = json_integer (salt); - if (NULL == (root = json_pack ("{s:s, s:s, s:s, s:s, s:I}", - "type", "SEPA", - "IBAN", wire->iban, - "name", wire->name, - "bic", wire->bic, - "r", json_integer_value (j_salt)))) - return NULL; - return root; -} - - -/** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback @@ -619,52 +591,95 @@ parse_auditors (const struct GNUNET_CONFIGURATION_Handle *cfg, /** * Parse the SEPA information from the configuration. If any of the - * required fields is missing return NULL. + * required fields is missing return an error. * * @param cfg the configuration - * @return Sepa details as a structure; NULL upon error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -static struct MERCHANT_WIREFORMAT_Sepa * +static int parse_wireformat_sepa (const struct GNUNET_CONFIGURATION_Handle *cfg) { - struct MERCHANT_WIREFORMAT_Sepa *wf; - - wf = GNUNET_new (struct MERCHANT_WIREFORMAT_Sepa); - EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, - "wire-sepa", - "IBAN", - &wf->iban)); - EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, - "wire-sepa", - "NAME", - &wf->name)); - EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, - "wire-sepa", - "BIC", - &wf->bic)); - return wf; + unsigned long long salt; + char *iban; + char *name; + char *bic; - EXITIF_exit: - GNUNET_free_non_null (wf->iban); - GNUNET_free_non_null (wf->name); - GNUNET_free_non_null (wf->bic); - GNUNET_free (wf); - return NULL; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg, + "wire-sepa", + "SALT", + &salt)) + { + salt = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, + UINT64_MAX); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "No SALT option given in `wire-sepa`, using %llu\n", + (unsigned long long) salt); + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "wire-sepa", + "IBAN", + &iban)) + return GNUNET_SYSERR; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "wire-sepa", + "NAME", + &name)) + { + GNUNET_free (iban); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "wire-sepa", + "BIC", + &bic)) + { + GNUNET_free (iban); + GNUNET_free (name); + GNUNET_free (bic); + } + j_wire = json_pack ("{s:s, s:s, s:s, s:s, s:o}", + "type", "SEPA", + "IBAN", iban, + "name", name, + "bic", bic, + "r", json_integer (salt)); + GNUNET_free (iban); + GNUNET_free (name); + GNUNET_free (bic); + if (NULL == j_wire) + return GNUNET_SYSERR; + return GNUNET_OK; } /** - * Destroy and free resouces occupied by the wireformat structure + * Verify that #j_wire contains a well-formed wire format, and + * update #h_wire to match it (if successful). * - * @param wf the wireformat structure + * @param allowed which wire format is allowed/expected? + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -static void -destroy_wireformat_sepa (struct MERCHANT_WIREFORMAT_Sepa *wf) +static int +validate_and_hash_wireformat (const char *allowed) { - GNUNET_free_non_null (wf->iban); - GNUNET_free_non_null (wf->name); - GNUNET_free_non_null (wf->bic); - GNUNET_free (wf); + const char *allowed_arr[] = { + allowed, + NULL + }; + + if (GNUNET_YES != + TALER_json_validate_wireformat (allowed_arr, + j_wire)) + return GNUNET_SYSERR; + if (GNUNET_SYSERR == + TALER_hash_json (j_wire, + &h_wire)) + return MHD_NO; + return GNUNET_OK; } @@ -747,9 +762,11 @@ run (void *cls, (nauditors = parse_auditors (config, &auditors))); - EXITIF (NULL == - (wire = - parse_wireformat_sepa (config))); + /* FIXME: for now, we just support SEPA here: */ + EXITIF (GNUNET_OK != + parse_wireformat_sepa (config)); + EXITIF (GNUNET_OK != + validate_and_hash_wireformat ("SEPA")); EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (config, "merchant", @@ -784,8 +801,6 @@ run (void *cls, "EDATE", &edate_delay)); - salt = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT64_MAX); for (cnt = 0; cnt < nmints; cnt++) { @@ -841,8 +856,8 @@ main (int argc, char *const *argv) if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, - "taler-merchant-http", - "Serve merchant's HTTP interface", + "taler-merchant-httpd", + "Taler merchant's HTTP backend interface", options, &run, NULL)) return 3; return (GNUNET_OK == result) ? 0 : 1; diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index d2fe3921..c71108c0 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -183,11 +183,21 @@ struct TM_HandlerContext }; -extern struct MERCHANT_Auditor *auditors; -extern unsigned int nauditors; -extern struct MERCHANT_WIREFORMAT_Sepa *wire; +/** + * Our wire format details in JSON format (with salt). + */ +extern json_t *j_wire; +/** + * Hash of our wire format details as given in #j_wire. + */ +extern struct GNUNET_HashCode h_wire; + + + +extern struct MERCHANT_Auditor *auditors; +extern unsigned int nauditors; extern struct MERCHANT_Mint **mints; @@ -196,7 +206,6 @@ extern struct GNUNET_CRYPTO_EddsaPrivateKey *privkey; extern PGconn *db_conn; -extern long long salt; extern unsigned int nmints; diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c index 88757b53..b5050666 100644 --- a/src/backend/taler-merchant-httpd_contract.c +++ b/src/backend/taler-merchant-httpd_contract.c @@ -61,7 +61,6 @@ MH_handler_contract (struct TMH_RequestHandler *rh, json_t *j_auditors; json_t *auditor; json_t *mint; - json_t *j_wire; const struct TALER_MINT_Keys *keys; int res; int cnt; @@ -114,30 +113,22 @@ MH_handler_contract (struct TMH_RequestHandler *rh, * routine, simply ignored, or ended with an invitation to the wallet * to just retry later */ - if (!json_array_size (trusted_mints)) + if (! json_array_size (trusted_mints)) return MHD_NO; /** * Hard error, no action can be taken by a wallet */ - if (!json_array_size (j_auditors)) + if (! json_array_size (j_auditors)) return MHD_NO; json_object_set_new (root, "mints", trusted_mints); json_object_set_new (root, "auditors", j_auditors); - if (NULL == (j_wire = MERCHANT_get_wire_json (wire, - salt))) - return MHD_NO; - - /* hash wire objcet */ - if (GNUNET_SYSERR == - TALER_hash_json (j_wire, &h_wire)) - return MHD_NO; - json_object_set_new (root, "H_wire", - TALER_json_from_data (&h_wire, sizeof (h_wire))); + TALER_json_from_data (&h_wire, + sizeof (h_wire))); GNUNET_CRYPTO_eddsa_key_get_public (privkey, &pubkey); json_object_set_new (root, diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index 5191d711..23aa178d 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -298,7 +298,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh, json_t *coins; char *chosen_mint; json_t *coin_aggregate; - json_t *wire_details; unsigned int mint_index; /*a cell in the global array*/ unsigned int coins_index; unsigned int coins_cnt; @@ -478,7 +477,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh, "merchant_pub", TALER_json_from_data (&pubkey, sizeof (pubkey))); - wire_details = MERCHANT_get_wire_json (wire, salt); /* since memory is zero'd out by GNUNET_malloc, any 'ackd' field will be (implicitly) set to false */ dc = GNUNET_malloc (coins_cnt * sizeof (struct MERCHANT_DepositConfirmation)); @@ -546,7 +544,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, dh = TALER_MINT_deposit (mints[mint_index]->conn, &percoin_amount, edate, - wire_details, + j_wire, &h_contract, &coin_pub, &ub_sig, |