aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-27 23:06:23 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-27 23:06:23 +0100
commitea3fac606311d1c14362d387960a4913182b629e (patch)
treec6e85271898e14ebed421b83439ee116f00ef39e
parent5647ed2be5cc69d25e393fc3a511bb0959566367 (diff)
downloadexchange-ea3fac606311d1c14362d387960a4913182b629e.tar.gz
exchange-ea3fac606311d1c14362d387960a4913182b629e.zip
starting to clean up /deposit logic
-rw-r--r--src/mint/mint.h68
-rw-r--r--src/mint/mint_db.c49
-rw-r--r--src/mint/mint_db.h4
-rw-r--r--src/mint/taler-mint-httpd_db.c12
-rw-r--r--src/mint/taler-mint-httpd_deposit.c145
-rw-r--r--src/mint/taler-mint-httpd_deposit.h8
-rw-r--r--src/mint/taler-mint-httpd_keys.c2
-rw-r--r--src/mint/taler-mint-httpd_keys.h2
-rw-r--r--src/mint/taler-mint-httpd_parsing.h8
9 files changed, 184 insertions, 114 deletions
diff --git a/src/mint/mint.h b/src/mint/mint.h
index 046b9c17e..05e966e1c 100644
--- a/src/mint/mint.h
+++ b/src/mint/mint.h
@@ -28,6 +28,7 @@
28#include <gnunet/gnunet_util_lib.h> 28#include <gnunet/gnunet_util_lib.h>
29#include <gnunet/gnunet_common.h> 29#include <gnunet/gnunet_common.h>
30#include <libpq-fe.h> 30#include <libpq-fe.h>
31#include <jansson.h>
31#include "taler_util.h" 32#include "taler_util.h"
32#include "taler_signatures.h" 33#include "taler_signatures.h"
33 34
@@ -71,13 +72,15 @@ struct TALER_CoinPublicInfo
71 */ 72 */
72 struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub; 73 struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub;
73 74
74 /* 75 /**
75 * The public key signifying the coin's denomination. 76 * Public key representing the denomination of the coin
77 * that is being deposited.
76 */ 78 */
77 struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub; 79 struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
78 80
79 /** 81 /**
80 * Signature over coin_pub by denom_pub. 82 * (Unblinded) signature over @e coin_pub with @e denom_pub,
83 * which demonstrates that the coin is valid.
81 */ 84 */
82 struct GNUNET_CRYPTO_rsa_Signature *denom_sig; 85 struct GNUNET_CRYPTO_rsa_Signature *denom_sig;
83}; 86};
@@ -236,33 +239,62 @@ struct KnownCoin
236 */ 239 */
237struct Deposit 240struct Deposit
238{ 241{
239 /* FIXME: should be TALER_CoinPublicInfo */ 242 /**
240 struct GNUNET_CRYPTO_EddsaPublicKey coin_pub; 243 * Information about the coin that is being deposited.
244 */
245 struct TALER_CoinPublicInfo coin;
241 246
242 struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub; 247 /**
248 * EdDSA signature affirming that the customer intends
249 * this coin to be deposited at the merchant identified
250 * by @e h_wire in relation to the contract identified
251 * by @e h_contract.
252 */
253 struct GNUNET_CRYPTO_EddsaSignature csig;
243 254
244 struct GNUNET_CRYPTO_rsa_Signature *coin_sig; 255 /**
256 * Public key of the merchant. Enables later identification
257 * of the merchant in case of a need to rollback transactions.
258 */
259 struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub;
245 260
246 struct GNUNET_CRYPTO_rsa_Signature *ubsig; // ??? 261 /**
262 * Hash over the contract between merchant and customer
263 * (remains unknown to the Mint).
264 */
265 struct GNUNET_HashCode h_contract;
247 266
248 /** 267 /**
249 * Type of the deposit (also purpose of the signature). Either 268 * Hash of the (canonical) representation of @e wire, used
250 * #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT. 269 * to check the signature on the request. Generated by
270 * the mint from the detailed wire data provided by the
271 * merchant.
251 */ 272 */
252 // struct TALER_RSA_SignaturePurpose purpose; // FIXME: bad type! 273 struct GNUNET_HashCode h_wire;
253 274
275 /**
276 * Detailed wire information for executing the transaction.
277 */
278 const json_t *wire;
279
280 /**
281 * Merchant-generated transaction ID to detect duplicate
282 * transactions.
283 */
254 uint64_t transaction_id; 284 uint64_t transaction_id;
255 285
286 /**
287 * Fraction of the coin's remaining value to be deposited.
288 * The coin is identified by @e coin_pub.
289 */
256 struct TALER_AmountNBO amount; 290 struct TALER_AmountNBO amount;
257 291
258 struct GNUNET_CRYPTO_EddsaPublicKey merchant_pub; 292 /**
259 293 * Type of the deposit (also purpose of the signature). Either
260 struct GNUNET_HashCode h_contract; 294 * #TALER_SIGNATURE_DEPOSIT or #TALER_SIGNATURE_INCREMENTAL_DEPOSIT.
261 295 */
262 struct GNUNET_HashCode h_wire; 296 uint32_t purpose; // FIXME: bad type, use ENUM!
263 297
264 /* TODO: uint16_t wire_size */
265 char wire[]; /* string encoded wire JSON object */
266 298
267}; 299};
268 300
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c
index f6fff7e5c..4c836bf92 100644
--- a/src/mint/mint_db.c
+++ b/src/mint/mint_db.c
@@ -1840,17 +1840,21 @@ TALER_MINT_DB_insert_deposit (PGconn *db_conn,
1840 const struct Deposit *deposit) 1840 const struct Deposit *deposit)
1841{ 1841{
1842 struct TALER_DB_QueryParam params[]= { 1842 struct TALER_DB_QueryParam params[]= {
1843 TALER_DB_QUERY_PARAM_PTR (&deposit->coin_pub), 1843 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.coin_pub),
1844 TALER_DB_QUERY_PARAM_PTR (&deposit->denom_pub), 1844 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.denom_pub), // FIXME!
1845 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.denom_sig), // FIXME!
1845 TALER_DB_QUERY_PARAM_PTR (&deposit->transaction_id), 1846 TALER_DB_QUERY_PARAM_PTR (&deposit->transaction_id),
1847 TALER_DB_QUERY_PARAM_PTR (&deposit->purpose), // FIXME: enum Ok here?
1846 TALER_DB_QUERY_PARAM_PTR (&deposit->amount.value), 1848 TALER_DB_QUERY_PARAM_PTR (&deposit->amount.value),
1847 TALER_DB_QUERY_PARAM_PTR (&deposit->amount.fraction), 1849 TALER_DB_QUERY_PARAM_PTR (&deposit->amount.fraction),
1848 TALER_DB_QUERY_PARAM_PTR_SIZED (deposit->amount.currency, strlen (deposit->amount.currency)), 1850 TALER_DB_QUERY_PARAM_PTR_SIZED (deposit->amount.currency,
1851 strlen (deposit->amount.currency)),
1849 TALER_DB_QUERY_PARAM_PTR (&deposit->merchant_pub), 1852 TALER_DB_QUERY_PARAM_PTR (&deposit->merchant_pub),
1850 TALER_DB_QUERY_PARAM_PTR (&deposit->h_contract), 1853 TALER_DB_QUERY_PARAM_PTR (&deposit->h_contract),
1851 TALER_DB_QUERY_PARAM_PTR (&deposit->h_wire), 1854 TALER_DB_QUERY_PARAM_PTR (&deposit->h_wire),
1852 TALER_DB_QUERY_PARAM_PTR (&deposit->coin_sig), 1855 TALER_DB_QUERY_PARAM_PTR (&deposit->csig),
1853 TALER_DB_QUERY_PARAM_PTR_SIZED (deposit->wire, strlen(deposit->wire)), 1856 TALER_DB_QUERY_PARAM_PTR_SIZED (deposit->wire,
1857 strlen ("FIXME")), // FIXME! json!
1854 TALER_DB_QUERY_PARAM_END 1858 TALER_DB_QUERY_PARAM_END
1855 }; 1859 };
1856 PGresult *result; 1860 PGresult *result;
@@ -1869,18 +1873,19 @@ TALER_MINT_DB_insert_deposit (PGconn *db_conn,
1869 1873
1870int 1874int
1871TALER_MINT_DB_get_deposit (PGconn *db_conn, 1875TALER_MINT_DB_get_deposit (PGconn *db_conn,
1872 const struct GNUNET_CRYPTO_EddsaPublicKey *coin_pub, 1876 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub,
1873 struct Deposit **r_deposit) 1877 struct Deposit *deposit)
1874{ 1878{
1875 struct TALER_DB_QueryParam params[] = { 1879 struct TALER_DB_QueryParam params[] = {
1876 TALER_DB_QUERY_PARAM_PTR (coin_pub), 1880 TALER_DB_QUERY_PARAM_PTR (coin_pub),
1877 TALER_DB_QUERY_PARAM_END 1881 TALER_DB_QUERY_PARAM_END
1878 }; 1882 };
1879 PGresult *result; 1883 PGresult *result;
1880 struct Deposit *deposit;
1881 1884
1882 deposit = NULL; 1885 memset (deposit, 0, sizeof (struct Deposit));
1883 result = TALER_DB_exec_prepared (db_conn, "get_deposit", params); 1886 result = TALER_DB_exec_prepared (db_conn,
1887 "get_deposit",
1888 params);
1884 if (PGRES_TUPLES_OK != PQresultStatus (result)) 1889 if (PGRES_TUPLES_OK != PQresultStatus (result))
1885 { 1890 {
1886 break_db_err (result); 1891 break_db_err (result);
@@ -1900,19 +1905,21 @@ TALER_MINT_DB_get_deposit (PGconn *db_conn,
1900 } 1905 }
1901 1906
1902 { 1907 {
1903 deposit = GNUNET_malloc (sizeof (struct Deposit)); /* Without wire data */ 1908 char *denom_sig_buf;
1904 char *sig_buf; 1909 size_t denom_sig_buf_size;
1905 size_t sig_buf_size;
1906 char *dk_buf; 1910 char *dk_buf;
1907 size_t dk_buf_size; 1911 size_t dk_buf_size;
1912
1908 struct TALER_DB_ResultSpec rs[] = { 1913 struct TALER_DB_ResultSpec rs[] = {
1909 TALER_DB_RESULT_SPEC ("coin_pub", &deposit->coin_pub), 1914 TALER_DB_RESULT_SPEC ("coin_pub", &deposit->coin.coin_pub),
1910 TALER_DB_RESULT_SPEC_VAR ("denom_pub", &dk_buf, &dk_buf_size), 1915 TALER_DB_RESULT_SPEC_VAR ("denom_pub", &dk_buf, &dk_buf_size),
1911 TALER_DB_RESULT_SPEC_VAR ("coin_sig", &sig_buf, &sig_buf_size), 1916 TALER_DB_RESULT_SPEC_VAR ("denom_sig", &denom_sig_buf, &denom_sig_buf_size),
1912 TALER_DB_RESULT_SPEC ("transaction_id", &deposit->transaction_id), 1917 TALER_DB_RESULT_SPEC ("transaction_id", &deposit->transaction_id),
1913 TALER_DB_RESULT_SPEC ("merchant_pub", &deposit->merchant_pub), 1918 TALER_DB_RESULT_SPEC ("merchant_pub", &deposit->merchant_pub),
1914 TALER_DB_RESULT_SPEC ("h_contract", &deposit->h_contract), 1919 TALER_DB_RESULT_SPEC ("h_contract", &deposit->h_contract),
1915 TALER_DB_RESULT_SPEC ("h_wire", &deposit->h_wire), 1920 TALER_DB_RESULT_SPEC ("h_wire", &deposit->h_wire),
1921 TALER_DB_RESULT_SPEC ("purpose", &deposit->purpose),
1922 // FIXME: many fields missing...
1916 TALER_DB_RESULT_SPEC_END 1923 TALER_DB_RESULT_SPEC_END
1917 }; 1924 };
1918 EXITIF (GNUNET_OK != 1925 EXITIF (GNUNET_OK !=
@@ -1923,15 +1930,15 @@ TALER_MINT_DB_get_deposit (PGconn *db_conn,
1923 "amount_fraction", 1930 "amount_fraction",
1924 "amount_currency", 1931 "amount_currency",
1925 &deposit->amount)); 1932 &deposit->amount));
1926 deposit->coin_sig = GNUNET_CRYPTO_rsa_signature_decode (sig_buf, 1933 deposit->coin.denom_sig
1927 sig_buf_size); 1934 = GNUNET_CRYPTO_rsa_signature_decode (denom_sig_buf,
1928 deposit->denom_pub = GNUNET_CRYPTO_rsa_public_key_decode (dk_buf, 1935 denom_sig_buf_size);
1929 dk_buf_size); 1936 deposit->coin.denom_pub
1930 // deposit->purpose = htonl (TALER_SIGNATURE_DEPOSIT); // FIXME: struct Deposit not nice 1937 = GNUNET_CRYPTO_rsa_public_key_decode (dk_buf,
1938 dk_buf_size);
1931 } 1939 }
1932 1940
1933 PQclear (result); 1941 PQclear (result);
1934 *r_deposit = deposit;
1935 return GNUNET_OK; 1942 return GNUNET_OK;
1936 1943
1937EXITIF_exit: 1944EXITIF_exit:
diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h
index e0c2e2e0a..3a62f1835 100644
--- a/src/mint/mint_db.h
+++ b/src/mint/mint_db.h
@@ -258,8 +258,8 @@ TALER_MINT_DB_insert_deposit (PGconn *db_conn,
258 258
259int 259int
260TALER_MINT_DB_get_deposit (PGconn *db_conn, 260TALER_MINT_DB_get_deposit (PGconn *db_conn,
261 const struct GNUNET_CRYPTO_EddsaPublicKey *coin_pub, 261 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub,
262 struct Deposit **r_deposit); 262 struct Deposit *r_deposit);
263 263
264 264
265int 265int
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index baf5d12aa..fcc6d915f 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -54,7 +54,7 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
54 const struct Deposit *deposit) 54 const struct Deposit *deposit)
55{ 55{
56 PGconn *db_conn; 56 PGconn *db_conn;
57 struct Deposit *existing_deposit; 57 struct Deposit existing_deposit;
58 int res; 58 int res;
59 59
60 if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) 60 if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
@@ -63,13 +63,15 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
63 return TALER_MINT_reply_internal_db_error (connection); 63 return TALER_MINT_reply_internal_db_error (connection);
64 } 64 }
65 res = TALER_MINT_DB_get_deposit (db_conn, 65 res = TALER_MINT_DB_get_deposit (db_conn,
66 &deposit->coin_pub, 66 &deposit->coin.coin_pub,
67 &existing_deposit); 67 &existing_deposit);
68 if (GNUNET_YES == res) 68 if (GNUNET_YES == res)
69 { 69 {
70 // FIXME: memory leak 70 // FIXME: memory leak
71 // FIXME: memcmp will not actually work here 71 // FIXME: memcmp will not actually work here
72 if (0 == memcmp (existing_deposit, deposit, sizeof (struct Deposit))) 72 if (0 == memcmp (&existing_deposit,
73 deposit,
74 sizeof (struct Deposit)))
73 return TALER_MINT_reply_deposit_success (connection, deposit); 75 return TALER_MINT_reply_deposit_success (connection, deposit);
74 // FIXME: in the future, check if there's enough credits 76 // FIXME: in the future, check if there's enough credits
75 // left on the coin. For now: refuse 77 // left on the coin. For now: refuse
@@ -93,7 +95,9 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
93 int res; 95 int res;
94 struct TALER_CoinPublicInfo coin_info; 96 struct TALER_CoinPublicInfo coin_info;
95 97
96 res = TALER_MINT_DB_get_known_coin (db_conn, &coin_info.coin_pub, &known_coin); 98 res = TALER_MINT_DB_get_known_coin (db_conn,
99 &coin_info.coin_pub,
100 &known_coin);
97 if (GNUNET_YES == res) 101 if (GNUNET_YES == res)
98 { 102 {
99 // coin must have been refreshed 103 // coin must have been refreshed
diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c
index 4a3713c5b..ed0eca8bb 100644
--- a/src/mint/taler-mint-httpd_deposit.c
+++ b/src/mint/taler-mint-httpd_deposit.c
@@ -59,19 +59,26 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
59 const struct Deposit *deposit) 59 const struct Deposit *deposit)
60{ 60{
61 struct MintKeyState *key_state; 61 struct MintKeyState *key_state;
62 struct TALER_CoinPublicInfo coin_info;
63 62
64 memcpy (&coin_info.coin_pub, 63 /* FIXME: verify coin signature! */
65 &deposit->coin_pub, 64 /*
66 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 65 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_DEPOSIT,
67 coin_info.denom_pub = deposit->denom_pub; 66 &deposit->purpose,
68 coin_info.denom_sig = deposit->ubsig; 67 &deposit->coin_sig,
68 &deposit->coin_pub))
69 {
70 resp = json_pack ("{s:s}", "error", "Signature verfication failed");
71 return TALER_MINT_reply_arg_invalid (connection,
72 "csig");
73 }
74 */
69 75
70 key_state = TALER_MINT_key_state_acquire (); 76 key_state = TALER_MINT_key_state_acquire ();
71 if (GNUNET_YES != 77 if (GNUNET_YES !=
72 TALER_MINT_test_coin_valid (key_state, 78 TALER_MINT_test_coin_valid (key_state,
73 &coin_info)) 79 &deposit->coin))
74 { 80 {
81 LOG_WARNING ("Invalid coin passed for /deposit\n");
75 TALER_MINT_key_state_release (key_state); 82 TALER_MINT_key_state_release (key_state);
76 return TALER_MINT_reply_json_pack (connection, 83 return TALER_MINT_reply_json_pack (connection,
77 MHD_HTTP_NOT_FOUND, 84 MHD_HTTP_NOT_FOUND,
@@ -80,19 +87,6 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
80 } 87 }
81 TALER_MINT_key_state_release (key_state); 88 TALER_MINT_key_state_release (key_state);
82 89
83 /* FIXME: verify coin signature! */
84 /*
85 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_DEPOSIT,
86 &deposit->purpose,
87 &deposit->coin_sig,
88 &deposit->coin_pub))
89 {
90 resp = json_pack ("{s:s}", "error", "Signature verfication failed");
91 resp_code = MHD_HTTP_NOT_FOUND;
92 goto EXITIF_exit;
93 }
94 */
95
96 return TALER_MINT_db_execute_deposit (connection, 90 return TALER_MINT_db_execute_deposit (connection,
97 deposit); 91 deposit);
98} 92}
@@ -101,12 +95,12 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
101/** 95/**
102 * Handle a "/deposit" request. This function parses the 96 * Handle a "/deposit" request. This function parses the
103 * JSON information and then calls #verify_and_execute_deposit() 97 * JSON information and then calls #verify_and_execute_deposit()
104 * to verify the data and execute the deposit. 98 * to verify the signatures and execute the deposit.
105 * 99 *
106 * @param connection the MHD connection to handle 100 * @param connection the MHD connection to handle
107 * @param root root of the posted JSON 101 * @param root root of the posted JSON
108 * @param purpose is this a #TALER_SIGNATURE_DEPOSIT or 102 * @param purpose is this a #TALER_SIGNATURE_DEPOSIT or
109 * #TALER_SIGNATURE_INCREMENTAL_DEPOSIT 103 * #TALER_SIGNATURE_INCREMENTAL_DEPOSIT // FIXME: bad type, use enum!
110 * @param wire json describing the wire details (?) 104 * @param wire json describing the wire details (?)
111 * @return MHD result code 105 * @return MHD result code
112 */ 106 */
@@ -116,61 +110,88 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
116 uint32_t purpose, 110 uint32_t purpose,
117 const json_t *wire) 111 const json_t *wire)
118{ 112{
119 struct Deposit *deposit; 113 int res;
114 struct Deposit deposit;
120 char *wire_enc; 115 char *wire_enc;
121 size_t len; 116 size_t len;
122 int res; 117 struct GNUNET_MINT_ParseFieldSpec spec[] = {
118 TALER_MINT_PARSE_VARIABLE ("denom_pub"),
119 TALER_MINT_PARSE_VARIABLE ("ubsig"),
120 TALER_MINT_PARSE_FIXED ("coin_pub", &deposit.coin.coin_pub),
121 TALER_MINT_PARSE_FIXED ("merchant_pub", &deposit.merchant_pub),
122 TALER_MINT_PARSE_FIXED ("H_a", &deposit.h_contract),
123 TALER_MINT_PARSE_FIXED ("H_wire", &deposit.h_wire),
124 TALER_MINT_PARSE_FIXED ("csig", &deposit.csig),
125 TALER_MINT_PARSE_FIXED ("transaction_id", &deposit.transaction_id),
126 TALER_MINT_PARSE_END
127 };
123 128
124 // FIXME: `struct Deposit` is clearly ill-defined, we should 129 memset (&deposit, 0, sizeof (deposit));
125 // not have to do this... 130 res = TALER_MINT_parse_json_data (connection,
131 root,
132 spec);
133 if (GNUNET_SYSERR == res)
134 return MHD_NO; /* hard failure */
135 if (GNUNET_NO == res)
136 return MHD_YES; /* failure */
137 deposit.coin.denom_pub
138 = GNUNET_CRYPTO_rsa_public_key_decode (spec[0].destination,
139 spec[0].destination_size_out);
140 if (NULL == deposit.coin.denom_pub)
141 {
142 LOG_WARNING ("Failed to parse denomination key for /deposit request\n");
143 TALER_MINT_release_parsed_data (spec);
144 return TALER_MINT_reply_arg_invalid (connection,
145 "denom_pub");
146 }
147 deposit.coin.denom_sig
148 = GNUNET_CRYPTO_rsa_signature_decode (spec[1].destination,
149 spec[1].destination_size_out);
150 if (NULL == deposit.coin.denom_sig)
151 {
152 LOG_WARNING ("Failed to parse unblinded signature for /deposit request\n");
153 GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub);
154 TALER_MINT_release_parsed_data (spec);
155 return TALER_MINT_reply_arg_invalid (connection,
156 "denom_pub");
157 }
126 if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS))) 158 if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS)))
127 { 159 {
128 GNUNET_break_op (0); 160 GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub);
129 return TALER_MINT_reply_json_pack (connection, 161 GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig);
130 MHD_HTTP_BAD_REQUEST, 162 LOG_WARNING ("Failed to parse JSON wire format specification for /deposit request\n");
131 "{s:s}", 163 TALER_MINT_release_parsed_data (spec);
132 "error", "Bad format"); 164 return TALER_MINT_reply_arg_invalid (connection,
133 165 "wire");
134 } 166 }
135 len = strlen (wire_enc) + 1; 167 len = strlen (wire_enc) + 1;
168 GNUNET_CRYPTO_hash (wire_enc,
169 len,
170 &deposit.h_wire);
136 GNUNET_free (wire_enc); 171 GNUNET_free (wire_enc);
137 172
138 deposit = GNUNET_malloc (sizeof (struct Deposit) + len); 173 deposit.wire = wire;
139 { 174 deposit.purpose = purpose;
140 struct GNUNET_MINT_ParseFieldSpec spec[] = 175
141 { 176 // FIXME: deposit.amount not initialized!
142 TALER_MINT_PARSE_FIXED ("coin_pub", &deposit->coin_pub), 177
143 TALER_MINT_PARSE_FIXED ("denom_pub", &deposit->denom_pub), 178 res = verify_and_execute_deposit (connection,
144 TALER_MINT_PARSE_FIXED ("ubsig", &deposit->ubsig), 179 &deposit);
145 TALER_MINT_PARSE_FIXED ("merchant_pub", &deposit->merchant_pub), 180 GNUNET_CRYPTO_rsa_public_key_free (deposit.coin.denom_pub);
146 TALER_MINT_PARSE_FIXED ("H_a", &deposit->h_contract), 181 GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig);
147 TALER_MINT_PARSE_FIXED ("H_wire", &deposit->h_wire), 182 TALER_MINT_release_parsed_data (spec);
148 TALER_MINT_PARSE_FIXED ("csig", &deposit->coin_sig),
149 TALER_MINT_PARSE_FIXED ("transaction_id", &deposit->transaction_id),
150 TALER_MINT_PARSE_END
151 };
152 res = TALER_MINT_parse_json_data (connection,
153 wire, /* FIXME: wire or root here? */
154 spec);
155 if (GNUNET_SYSERR == res)
156 return MHD_NO; /* hard failure */
157 if (GNUNET_NO == res)
158 return MHD_YES; /* failure */
159
160 // deposit->purpose = htonl (purpose); // FIXME...
161 res = verify_and_execute_deposit (connection,
162 deposit);
163 TALER_MINT_release_parsed_data (spec);
164 }
165 GNUNET_free (deposit);
166 return res; 183 return res;
167} 184}
168 185
169 186
170/** 187/**
171 * Handle a "/deposit" request. Parses the JSON in the post and, if 188 * Handle a "/deposit" request. Parses the JSON in the post to find
189 * the "type" (either DIRECT_DEPOSIT or INCREMENTAL_DEPOSIT), and, if
172 * successful, passes the JSON data to 190 * successful, passes the JSON data to
173 * #parse_and_handle_deposit_request(). 191 * #parse_and_handle_deposit_request() to further check the details
192 * of the operation specified in the "wire" field of the JSON data.
193 * If everything checks out, this will ultimately lead to the
194 * "/deposit" being executed, or rejected.
174 * 195 *
175 * @param rh context of the handler 196 * @param rh context of the handler
176 * @param connection the MHD connection to handle 197 * @param connection the MHD connection to handle
diff --git a/src/mint/taler-mint-httpd_deposit.h b/src/mint/taler-mint-httpd_deposit.h
index dd7b8c133..c6d628050 100644
--- a/src/mint/taler-mint-httpd_deposit.h
+++ b/src/mint/taler-mint-httpd_deposit.h
@@ -29,7 +29,13 @@
29 29
30 30
31/** 31/**
32 * Handle a "/deposit" request 32 * Handle a "/deposit" request. Parses the JSON in the post to find
33 * the "type" (either DIRECT_DEPOSIT or INCREMENTAL_DEPOSIT), and, if
34 * successful, passes the JSON data to
35 * #parse_and_handle_deposit_request() to further check the details
36 * of the operation specified in the "wire" field of the JSON data.
37 * If everything checks out, this will ultimately lead to the
38 * "/deposit" being executed, or rejected.
33 * 39 *
34 * @param rh context of the handler 40 * @param rh context of the handler
35 * @param connection the MHD connection to handle 41 * @param connection the MHD connection to handle
diff --git a/src/mint/taler-mint-httpd_keys.c b/src/mint/taler-mint-httpd_keys.c
index 28924baef..359357da9 100644
--- a/src/mint/taler-mint-httpd_keys.c
+++ b/src/mint/taler-mint-httpd_keys.c
@@ -379,7 +379,7 @@ TALER_MINT_get_denom_key (const struct MintKeyState *key_state,
379 */ 379 */
380int 380int
381TALER_MINT_test_coin_valid (const struct MintKeyState *key_state, 381TALER_MINT_test_coin_valid (const struct MintKeyState *key_state,
382 struct TALER_CoinPublicInfo *coin_public_info) 382 const struct TALER_CoinPublicInfo *coin_public_info)
383{ 383{
384 struct TALER_MINT_DenomKeyIssuePriv *dki; 384 struct TALER_MINT_DenomKeyIssuePriv *dki;
385 struct GNUNET_HashCode c_hash; 385 struct GNUNET_HashCode c_hash;
diff --git a/src/mint/taler-mint-httpd_keys.h b/src/mint/taler-mint-httpd_keys.h
index 4672c1359..4182c25ea 100644
--- a/src/mint/taler-mint-httpd_keys.h
+++ b/src/mint/taler-mint-httpd_keys.h
@@ -123,7 +123,7 @@ TALER_MINT_get_denom_key (const struct MintKeyState *key_state,
123 */ 123 */
124int 124int
125TALER_MINT_test_coin_valid (const struct MintKeyState *key_state, 125TALER_MINT_test_coin_valid (const struct MintKeyState *key_state,
126 struct TALER_CoinPublicInfo *coin_public_info); 126 const struct TALER_CoinPublicInfo *coin_public_info);
127 127
128 128
129/** 129/**
diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h
index c8e946077..9c4d8aafe 100644
--- a/src/mint/taler-mint-httpd_parsing.h
+++ b/src/mint/taler-mint-httpd_parsing.h
@@ -40,14 +40,14 @@
40 * @param upload_data the POST data 40 * @param upload_data the POST data
41 * @param upload_data_size number of bytes in @a upload_data 41 * @param upload_data_size number of bytes in @a upload_data
42 * @param json the JSON object for a completed request 42 * @param json the JSON object for a completed request
43 * @returns 43 * @return
44 * GNUNET_YES if json object was parsed or at least 44 * #GNUNET_YES if json object was parsed or at least
45 * may be parsed in the future (call again); 45 * may be parsed in the future (call again);
46 * `*json` will be NULL if we need to be called again, 46 * `*json` will be NULL if we need to be called again,
47 * and non-NULL if we are done. 47 * and non-NULL if we are done.
48 * GNUNET_NO is request incomplete or invalid 48 * #GNUNET_NO is request incomplete or invalid
49 * (error message was generated) 49 * (error message was generated)
50 * GNUNET_SYSERR on internal error 50 * #GNUNET_SYSERR on internal error
51 * (we could not even queue an error message, 51 * (we could not even queue an error message,
52 * close HTTP session with MHD_NO) 52 * close HTTP session with MHD_NO)
53 */ 53 */