diff options
Diffstat (limited to 'src/mint/taler-mint-httpd_refresh.c')
-rw-r--r-- | src/mint/taler-mint-httpd_refresh.c | 99 |
1 files changed, 59 insertions, 40 deletions
diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 69ba87c29..40737ae31 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c | |||
@@ -34,7 +34,6 @@ | |||
34 | #include "mint.h" | 34 | #include "mint.h" |
35 | #include "mint_db.h" | 35 | #include "mint_db.h" |
36 | #include "taler_signatures.h" | 36 | #include "taler_signatures.h" |
37 | #include "taler_rsa.h" | ||
38 | #include "taler_json_lib.h" | 37 | #include "taler_json_lib.h" |
39 | #include "taler-mint-httpd_parsing.h" | 38 | #include "taler-mint-httpd_parsing.h" |
40 | #include "taler-mint-httpd_keys.h" | 39 | #include "taler-mint-httpd_keys.h" |
@@ -94,7 +93,7 @@ check_confirm_signature (struct MHD_Connection *connection, | |||
94 | * @param connection the connection to send error responses to | 93 | * @param connection the connection to send error responses to |
95 | * @param root the JSON object to extract the coin info from | 94 | * @param root the JSON object to extract the coin info from |
96 | * @return #GNUNET_YES if coin public info in JSON was valid | 95 | * @return #GNUNET_YES if coin public info in JSON was valid |
97 | * #GNUNET_NO otherwise | 96 | * #GNUNET_NO JSON was invalid, response was generated |
98 | * #GNUNET_SYSERR on internal error | 97 | * #GNUNET_SYSERR on internal error |
99 | */ | 98 | */ |
100 | static int | 99 | static int |
@@ -103,33 +102,38 @@ request_json_require_coin_public_info (struct MHD_Connection *connection, | |||
103 | struct TALER_CoinPublicInfo *r_public_info) | 102 | struct TALER_CoinPublicInfo *r_public_info) |
104 | { | 103 | { |
105 | int ret; | 104 | int ret; |
106 | 105 | struct GNUNET_CRYPTO_rsa_Signature *sig; | |
107 | GNUNET_assert (NULL != root); | 106 | struct GNUNET_CRYPTO_rsa_PublicKey *pk; |
108 | 107 | struct GNUNET_MINT_ParseFieldSpec spec[] = | |
109 | ret = GNUNET_MINT_parse_navigate_json (connection, root, | 108 | { |
110 | JNAV_FIELD, "coin_pub", | 109 | TALER_MINT_PARSE_FIXED("coin_pub", &r_public_info->coin_pub), |
111 | JNAV_RET_DATA, | 110 | TALER_MINT_PARSE_VARIABLE("denom_sig"), |
112 | &r_public_info->coin_pub, | 111 | TALER_MINT_PARSE_VARIABLE("denom_pub"), |
113 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 112 | TALER_MINT_PARSE_END |
114 | if (GNUNET_OK != ret) | 113 | }; |
115 | return ret; | 114 | |
116 | 115 | ret = TALER_MINT_parse_json_data (connection, | |
117 | ret = GNUNET_MINT_parse_navigate_json (connection, root, | 116 | root, |
118 | JNAV_FIELD, "denom_sig", | 117 | spec); |
119 | JNAV_RET_DATA, | ||
120 | &r_public_info->denom_sig, | ||
121 | sizeof (struct TALER_RSA_Signature)); | ||
122 | if (GNUNET_OK != ret) | ||
123 | return ret; | ||
124 | |||
125 | ret = GNUNET_MINT_parse_navigate_json (connection, root, | ||
126 | JNAV_FIELD, "denom_pub", | ||
127 | JNAV_RET_DATA, | ||
128 | &r_public_info->denom_pub, | ||
129 | sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)); | ||
130 | if (GNUNET_OK != ret) | 118 | if (GNUNET_OK != ret) |
131 | return ret; | 119 | return ret; |
132 | 120 | sig = GNUNET_CRYPTO_rsa_signature_decode (spec[1].destination, | |
121 | spec[1].destination_size_out); | ||
122 | pk = GNUNET_CRYPTO_rsa_public_key_decode (spec[2].destination, | ||
123 | spec[2].destination_size_out); | ||
124 | TALER_MINT_release_parsed_data (spec); | ||
125 | if ( (NULL == pk) || | ||
126 | (NULL == sig) ) | ||
127 | { | ||
128 | if (NULL != sig) | ||
129 | GNUNET_CRYPTO_rsa_signature_free (sig); | ||
130 | if (NULL != pk) | ||
131 | GNUNET_CRYPTO_rsa_public_key_free (pk); | ||
132 | // FIXME: send error reply... | ||
133 | return GNUNET_NO; | ||
134 | } | ||
135 | r_public_info->denom_sig = sig; | ||
136 | r_public_info->denom_pub = pk; | ||
133 | return GNUNET_OK; | 137 | return GNUNET_OK; |
134 | } | 138 | } |
135 | 139 | ||
@@ -247,7 +251,7 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
247 | json_t *new_denoms; | 251 | json_t *new_denoms; |
248 | unsigned int num_new_denoms; | 252 | unsigned int num_new_denoms; |
249 | unsigned int i; | 253 | unsigned int i; |
250 | struct TALER_RSA_PublicKeyBinaryEncoded *denom_pubs; | 254 | struct GNUNET_CRYPTO_rsa_PublicKey *denom_pubs; |
251 | json_t *melt_coins; | 255 | json_t *melt_coins; |
252 | struct TALER_CoinPublicInfo *coin_public_infos; | 256 | struct TALER_CoinPublicInfo *coin_public_infos; |
253 | unsigned int coin_count; | 257 | unsigned int coin_count; |
@@ -256,6 +260,8 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
256 | struct MintKeyState *key_state; | 260 | struct MintKeyState *key_state; |
257 | struct RefreshMeltSignatureBody body; | 261 | struct RefreshMeltSignatureBody body; |
258 | json_t *melt_sig_json; | 262 | json_t *melt_sig_json; |
263 | char *buf; | ||
264 | size_t buf_size; | ||
259 | 265 | ||
260 | res = TALER_MINT_parse_post_json (connection, | 266 | res = TALER_MINT_parse_post_json (connection, |
261 | connection_cls, | 267 | connection_cls, |
@@ -291,23 +297,31 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
291 | return res; | 297 | return res; |
292 | num_new_denoms = json_array_size (new_denoms); | 298 | num_new_denoms = json_array_size (new_denoms); |
293 | denom_pubs = GNUNET_malloc (num_new_denoms * | 299 | denom_pubs = GNUNET_malloc (num_new_denoms * |
294 | sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)); | 300 | sizeof (struct GNUNET_CRYPTO_rsa_PublicKey *)); |
295 | 301 | ||
296 | for (i=0;i<num_new_denoms;i++) | 302 | for (i=0;i<num_new_denoms;i++) |
297 | { | 303 | { |
298 | res = GNUNET_MINT_parse_navigate_json (connection, root, | 304 | res = GNUNET_MINT_parse_navigate_json (connection, root, |
299 | JNAV_FIELD, "new_denoms", | 305 | JNAV_FIELD, "new_denoms", |
300 | JNAV_INDEX, (int) i, | 306 | JNAV_INDEX, (int) i, |
301 | JNAV_RET_DATA, | 307 | JNAV_RET_DATA_VAR, |
302 | &denom_pubs[i], | 308 | &buf, |
303 | sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)); | 309 | &buf_size); |
304 | |||
305 | if (GNUNET_OK != res) | 310 | if (GNUNET_OK != res) |
306 | { | 311 | { |
307 | GNUNET_free (denom_pubs); | 312 | GNUNET_free (denom_pubs); |
308 | /* FIXME: proper cleanup! */ | 313 | /* FIXME: proper cleanup! */ |
309 | return res; | 314 | return res; |
310 | } | 315 | } |
316 | denom_pubs[i] = GNUNET_CRYPTO_rsa_public_key_decode (buf, buf_size); | ||
317 | GNUNET_free (buf); | ||
318 | if (NULL == denom_pubs[i]) | ||
319 | { | ||
320 | GNUNET_free (denom_pubs); | ||
321 | /* FIXME: proper cleanup! */ | ||
322 | /* FIXME: generate error reply */ | ||
323 | return GNUNET_SYSERR; | ||
324 | } | ||
311 | } | 325 | } |
312 | 326 | ||
313 | res = GNUNET_MINT_parse_navigate_json (connection, root, | 327 | res = GNUNET_MINT_parse_navigate_json (connection, root, |
@@ -377,9 +391,14 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
377 | /* check that signature from the session public key is ok */ | 391 | /* check that signature from the session public key is ok */ |
378 | hash_context = GNUNET_CRYPTO_hash_context_start (); | 392 | hash_context = GNUNET_CRYPTO_hash_context_start (); |
379 | for (i = 0; i < num_new_denoms; i++) | 393 | for (i = 0; i < num_new_denoms; i++) |
394 | { | ||
395 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (denom_pubs[i], | ||
396 | &buf); | ||
380 | GNUNET_CRYPTO_hash_context_read (hash_context, | 397 | GNUNET_CRYPTO_hash_context_read (hash_context, |
381 | &denom_pubs[i], | 398 | buf, |
382 | sizeof (struct TALER_RSA_PublicKeyBinaryEncoded)); | 399 | buf_size); |
400 | GNUNET_free (buf); | ||
401 | } | ||
383 | for (i = 0; i < coin_count; i++) | 402 | for (i = 0; i < coin_count; i++) |
384 | GNUNET_CRYPTO_hash_context_read (hash_context, | 403 | GNUNET_CRYPTO_hash_context_read (hash_context, |
385 | &coin_public_infos[i].coin_pub, | 404 | &coin_public_infos[i].coin_pub, |
@@ -526,9 +545,9 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, | |||
526 | JNAV_FIELD, "coin_evs", | 545 | JNAV_FIELD, "coin_evs", |
527 | JNAV_INDEX, (int) i, | 546 | JNAV_INDEX, (int) i, |
528 | JNAV_INDEX, (int) j, | 547 | JNAV_INDEX, (int) j, |
529 | JNAV_RET_DATA, | 548 | JNAV_RET_DATA_VAR, |
530 | commit_coin[i][j].coin_ev, | 549 | &commit_coin[i][j].coin_ev, |
531 | sizeof (struct TALER_RSA_BlindedSignaturePurpose)); | 550 | &commit_coin[i][j].coin_ev_size); |
532 | 551 | ||
533 | if (GNUNET_OK != res) | 552 | if (GNUNET_OK != res) |
534 | { | 553 | { |
@@ -539,8 +558,8 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, | |||
539 | } | 558 | } |
540 | 559 | ||
541 | GNUNET_CRYPTO_hash_context_read (hash_context, | 560 | GNUNET_CRYPTO_hash_context_read (hash_context, |
542 | &commit_coin[i][j].coin_ev, | 561 | commit_coin[i][j].coin_ev, |
543 | sizeof (struct TALER_RSA_BlindedSignaturePurpose)); | 562 | commit_coin[i][j].coin_ev_size); |
544 | 563 | ||
545 | res = GNUNET_MINT_parse_navigate_json (connection, root, | 564 | res = GNUNET_MINT_parse_navigate_json (connection, root, |
546 | JNAV_FIELD, "link_encs", | 565 | JNAV_FIELD, "link_encs", |