aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-20 17:12:51 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-20 17:12:51 +0100
commitf70814fbb521e9d7c3a0db81fd483ecc926e9018 (patch)
tree47c993c0cbdc1708cca177cd01ff218f0fd0ee0e
parent93a98f8091329d44fe63c092da5f4eaf3bcb983d (diff)
downloadexchange-f70814fbb521e9d7c3a0db81fd483ecc926e9018.tar.gz
exchange-f70814fbb521e9d7c3a0db81fd483ecc926e9018.zip
more work on splitting refresh logic
-rw-r--r--src/mint/taler-mint-httpd_refresh.c88
-rw-r--r--src/mint/taler-mint-httpd_responses.c43
-rw-r--r--src/mint/taler-mint-httpd_responses.h13
3 files changed, 82 insertions, 62 deletions
diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c
index 8f4f13105..8b18e9a66 100644
--- a/src/mint/taler-mint-httpd_refresh.c
+++ b/src/mint/taler-mint-httpd_refresh.c
@@ -409,61 +409,6 @@ refresh_accept_melts (struct MHD_Connection *connection,
409} 409}
410 410
411 411
412/**
413 * Send a response for "/refresh/melt".
414 *
415 * @param connection the connection to send the response to
416 * @param db_conn the database connection to fetch values from
417 * @param session_pub the refresh session public key.
418 * @return a MHD result code
419 */
420static int
421helper_refresh_send_melt_response (struct MHD_Connection *connection,
422 PGconn *db_conn,
423 const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub)
424{
425 struct RefreshSession session;
426 int res;
427 json_t *root;
428 json_t *list;
429 struct GNUNET_HashContext *hash_context;
430
431 if (GNUNET_OK !=
432 (res = TALER_MINT_DB_get_refresh_session (db_conn,
433 session_pub,
434 &session)))
435 {
436 // FIXME: send internal error
437 GNUNET_break (0);
438 return MHD_NO;
439 }
440
441 root = json_object ();
442 list = json_array ();
443 json_object_set_new (root, "blind_session_pubs", list);
444
445 hash_context = GNUNET_CRYPTO_hash_context_start ();
446
447 {
448 struct RefreshMeltResponseSignatureBody body;
449 struct GNUNET_CRYPTO_EddsaSignature sig;
450 json_t *sig_json;
451
452 body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody));
453 body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE);
454 GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash);
455 TALER_MINT_keys_sign (&body.purpose,
456 &sig);
457 sig_json = TALER_JSON_from_sig (&body.purpose, &sig);
458 GNUNET_assert (NULL != sig_json);
459 json_object_set (root, "signature", sig_json);
460 }
461
462 return TALER_MINT_reply_json (connection,
463 root,
464 MHD_HTTP_OK);
465}
466
467 412
468/** 413/**
469 * Verify a signature that is encoded in a JSON object 414 * Verify a signature that is encoded in a JSON object
@@ -581,6 +526,7 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh,
581 struct TALER_Amount melt_balance; 526 struct TALER_Amount melt_balance;
582 struct GNUNET_HashContext *hash_context; 527 struct GNUNET_HashContext *hash_context;
583 struct GNUNET_HashCode melt_hash; 528 struct GNUNET_HashCode melt_hash;
529 struct RefreshSession session;
584 530
585 res = TALER_MINT_parse_post_json (connection, 531 res = TALER_MINT_parse_post_json (connection,
586 connection_cls, 532 connection_cls,
@@ -620,9 +566,20 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh,
620 &refresh_session_pub, 566 &refresh_session_pub,
621 NULL); 567 NULL);
622 if (GNUNET_YES == res) 568 if (GNUNET_YES == res)
623 return helper_refresh_send_melt_response (connection, 569 {
624 db_conn, 570 if (GNUNET_OK !=
625 &refresh_session_pub); 571 (res = TALER_MINT_DB_get_refresh_session (db_conn,
572 &refresh_session_pub,
573 &session)))
574 {
575 // FIXME: send internal error
576 GNUNET_break (0);
577 return MHD_NO;
578 }
579 return TALER_MINT_reply_refresh_melt_success (connection,
580 &session,
581 &refresh_session_pub);
582 }
626 if (GNUNET_SYSERR == res) 583 if (GNUNET_SYSERR == res)
627 { 584 {
628 // FIXME: return 'internal error'? 585 // FIXME: return 'internal error'?
@@ -738,9 +695,18 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh,
738 GNUNET_break (0); 695 GNUNET_break (0);
739 return MHD_NO; 696 return MHD_NO;
740 } 697 }
741 return helper_refresh_send_melt_response (connection, 698 if (GNUNET_OK !=
742 db_conn, 699 (res = TALER_MINT_DB_get_refresh_session (db_conn,
743 &refresh_session_pub); 700 &refresh_session_pub,
701 &session)))
702 {
703 // FIXME: send internal error
704 GNUNET_break (0);
705 return MHD_NO;
706 }
707 return TALER_MINT_reply_refresh_melt_success (connection,
708 &session,
709 &refresh_session_pub);
744} 710}
745 711
746 712
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index 7aedec1d3..eca10344a 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -291,6 +291,49 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection,
291 291
292 292
293/** 293/**
294 * Send a response for "/refresh/melt".
295 *
296 * @param connection the connection to send the response to
297 * @param db_conn the database connection to fetch values from
298 * @param session_pub the refresh session public key.
299 * @return a MHD result code
300 */
301int
302TALER_MINT_reply_refresh_melt_success (struct MHD_Connection *connection,
303 const struct RefreshSession *session,
304 const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub)
305{
306 json_t *root;
307 json_t *list;
308 struct GNUNET_HashContext *hash_context;
309
310 root = json_object ();
311 list = json_array ();
312 json_object_set_new (root, "blind_session_pubs", list);
313 hash_context = GNUNET_CRYPTO_hash_context_start ();
314
315 {
316 struct RefreshMeltResponseSignatureBody body;
317 struct GNUNET_CRYPTO_EddsaSignature sig;
318 json_t *sig_json;
319
320 body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody));
321 body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE);
322 GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash);
323 TALER_MINT_keys_sign (&body.purpose,
324 &sig);
325 sig_json = TALER_JSON_from_sig (&body.purpose, &sig);
326 GNUNET_assert (NULL != sig_json);
327 json_object_set (root, "signature", sig_json);
328 }
329
330 return TALER_MINT_reply_json (connection,
331 root,
332 MHD_HTTP_OK);
333}
334
335
336/**
294 * Send a response to a "/refresh/commit" request. 337 * Send a response to a "/refresh/commit" request.
295 * 338 *
296 * FIXME: maybe not the ideal argument type for @a refresh_session here. 339 * FIXME: maybe not the ideal argument type for @a refresh_session here.
diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h
index ca6b68d50..ab771cb31 100644
--- a/src/mint/taler-mint-httpd_responses.h
+++ b/src/mint/taler-mint-httpd_responses.h
@@ -173,7 +173,18 @@ TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection,
173 struct RefreshSession *refresh_session); 173 struct RefreshSession *refresh_session);
174 174
175 175
176 176/**
177 * Send a response for "/refresh/melt".
178 *
179 * @param connection the connection to send the response to
180 * @param db_conn the database connection to fetch values from
181 * @param session_pub the refresh session public key.
182 * @return a MHD result code
183 */
184int
185TALER_MINT_reply_refresh_melt_success (struct MHD_Connection *connection,
186 const struct RefreshSession *session,
187 const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub);
177 188
178 189
179 190