implementing /deposit JSON generation

This commit is contained in:
Christian Grothoff 2015-06-21 19:18:31 +02:00
parent c5641e9141
commit 5caa52aa4c
4 changed files with 79 additions and 12 deletions

View File

@ -152,6 +152,18 @@ struct GNUNET_CRYPTO_rsa_Signature *
TALER_json_to_rsa_signature (json_t *json);
/**
* Hash a JSON for binary signing.
*
* @param[in] json some JSON value to hash
* @param[out] hc resulting hash code
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
TALER_hash_json (json_t *json,
struct GNUNET_HashCode *hc);
/**
* Check if the given wire format JSON object is correctly formatted
*

View File

@ -129,6 +129,7 @@ handle_deposit_finished (void *cls,
}
if (NULL != json)
{
GNUNET_break (0); // FIXME: obtain response code from eh!
response_code = 42;
}
switch (response_code)
@ -243,6 +244,7 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint,
struct TALER_MINT_Context *ctx;
json_t *deposit_obj;
CURL *eh;
struct GNUNET_HashCode h_wire;
if (GNUNET_YES !=
MAH_handle_is_ready (mint))
@ -250,11 +252,42 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint,
GNUNET_break (0);
return NULL;
}
/* initialize h_wire */
if (GNUNET_OK !=
TALER_hash_json (wire_details,
&h_wire))
{
GNUNET_break (0);
return NULL;
}
GNUNET_break (0); /* FIXME: verify all sigs! */
/* FIXME: actually build JSON request */
deposit_obj = json_pack ("{s:s}",
"hello", "world");
deposit_obj = json_pack ("{s:o, s:o," /* f/wire */
" s:s, s:s," /* H_wire, H_contract */
" s:s, s:s," /* coin_pub, denom_pub */
" s:s, s:s," /* ub_sig, timestamp */
" s:I, s:s," /* transaction id, merchant_pub */
" s:s, s:s}", /* refund_deadline, coin_sig */
"f", TALER_json_from_amount (amount),
"wire", wire_details,
"H_wire", TALER_json_from_data (&h_wire,
sizeof (h_wire)),
"H_contract", TALER_json_from_data (&h_contract,
sizeof (h_contract)),
"coin_pub", TALER_json_from_data (coin_pub,
sizeof (*coin_pub)),
"denom_pub", TALER_json_from_rsa_public_key (denom_pub->rsa_public_key),
"ub_sig", TALER_json_from_rsa_signature (denom_sig->rsa_signature),
"timestamp", TALER_json_from_abs (timestamp),
"transaction_id", (json_int_t) transaction_id,
"merchant_pub", TALER_json_from_data (merchant_pub,
sizeof (*merchant_pub)),
"refund_deadline", TALER_json_from_abs (refund_deadline),
"coin_sig", TALER_json_from_data (coin_sig,
sizeof (*coin_sig))
);
dh = GNUNET_new (struct TALER_MINT_DepositHandle);
dh->mint = mint;
@ -262,10 +295,10 @@ TALER_MINT_deposit (struct TALER_MINT_Handle *mint,
dh->cb_cls = cb_cls;
dh->url = MAH_path_to_url (mint, "/deposit");
eh = curl_easy_init ();
/* FIXME: strdup() json_enc? Free deposit_obj! */
GNUNET_assert (NULL != (dh->json_enc =
json_dumps (deposit_obj,
JSON_COMPACT)));
json_decref (deposit_obj);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,

View File

@ -136,8 +136,6 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
{
int res;
struct TALER_MINTDB_Deposit deposit;
char *wire_enc;
size_t len;
struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
struct TMH_KS_StateHandle *ks;
struct TMH_PARSE_FieldSpecification spec[] = {
@ -170,18 +168,15 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
return TMH_RESPONSE_reply_arg_unknown (connection,
"wire");
}
if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS)))
if (GNUNET_OK !=
TALER_hash_json (wire,
&deposit.h_wire))
{
TALER_LOG_WARNING ("Failed to parse JSON wire format specification for /deposit request\n");
TMH_PARSE_release_data (spec);
return TMH_RESPONSE_reply_arg_invalid (connection,
"wire");
}
len = strlen (wire_enc) + 1;
GNUNET_CRYPTO_hash (wire_enc,
len,
&deposit.h_wire);
GNUNET_free (wire_enc);
ks = TMH_KS_acquire ();
dki = TMH_KS_denomination_key_lookup (ks,
&deposit.coin.denom_pub,

View File

@ -402,4 +402,31 @@ TALER_json_to_data (json_t *json,
return GNUNET_SYSERR;
}
/**
* Hash a JSON for binary signing.
*
* @param[in] json some JSON value
* @param[out] hc resulting hash code
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
TALER_hash_json (json_t *json,
struct GNUNET_HashCode *hc)
{
char *wire_enc;
size_t len;
if (NULL == (wire_enc = json_dumps (json,
JSON_COMPACT | JSON_SORT_KEYS)))
return GNUNET_SYSERR;
len = strlen (wire_enc) + 1;
GNUNET_CRYPTO_hash (wire_enc,
len,
hc);
GNUNET_free (wire_enc);
return GNUNET_OK;
}
/* End of util/json.c */