summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-21 19:18:31 +0200
committerChristian Grothoff <christian@grothoff.org>2015-06-21 19:18:31 +0200
commit5caa52aa4cf7eb4e59cef34195f61d088a28a622 (patch)
treecaacee4443a52e4b23fd5e5f5fbb8d94701d31e4 /src
parentc5641e9141ed8fccf13a2a11cb859e93e8270974 (diff)
downloadexchange-5caa52aa4cf7eb4e59cef34195f61d088a28a622.tar.gz
exchange-5caa52aa4cf7eb4e59cef34195f61d088a28a622.tar.bz2
exchange-5caa52aa4cf7eb4e59cef34195f61d088a28a622.zip
implementing /deposit JSON generation
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_json_lib.h12
-rw-r--r--src/mint-lib/mint_api_deposit.c41
-rw-r--r--src/mint/taler-mint-httpd_deposit.c11
-rw-r--r--src/util/json.c27
4 files changed, 79 insertions, 12 deletions
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index 7c260ea8..5a13b9bc 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -153,6 +153,18 @@ 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
*
* @param type the type of the wire format
diff --git a/src/mint-lib/mint_api_deposit.c b/src/mint-lib/mint_api_deposit.c
index 90a98e45..806631e7 100644
--- a/src/mint-lib/mint_api_deposit.c
+++ b/src/mint-lib/mint_api_deposit.c
@@ -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,
diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c
index 2e9facdf..53187dcb 100644
--- a/src/mint/taler-mint-httpd_deposit.c
+++ b/src/mint/taler-mint-httpd_deposit.c
@@ -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,
diff --git a/src/util/json.c b/src/util/json.c
index 17eb0f3f..1c7cb752 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -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 */