From f70814fbb521e9d7c3a0db81fd483ecc926e9018 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 20 Jan 2015 17:12:51 +0100 Subject: more work on splitting refresh logic --- src/mint/taler-mint-httpd_refresh.c | 88 +++++++++++------------------------ src/mint/taler-mint-httpd_responses.c | 43 +++++++++++++++++ src/mint/taler-mint-httpd_responses.h | 13 +++++- 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, } -/** - * Send a response for "/refresh/melt". - * - * @param connection the connection to send the response to - * @param db_conn the database connection to fetch values from - * @param session_pub the refresh session public key. - * @return a MHD result code - */ -static int -helper_refresh_send_melt_response (struct MHD_Connection *connection, - PGconn *db_conn, - const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub) -{ - struct RefreshSession session; - int res; - json_t *root; - json_t *list; - struct GNUNET_HashContext *hash_context; - - if (GNUNET_OK != - (res = TALER_MINT_DB_get_refresh_session (db_conn, - session_pub, - &session))) - { - // FIXME: send internal error - GNUNET_break (0); - return MHD_NO; - } - - root = json_object (); - list = json_array (); - json_object_set_new (root, "blind_session_pubs", list); - - hash_context = GNUNET_CRYPTO_hash_context_start (); - - { - struct RefreshMeltResponseSignatureBody body; - struct GNUNET_CRYPTO_EddsaSignature sig; - json_t *sig_json; - - body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody)); - body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE); - GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash); - TALER_MINT_keys_sign (&body.purpose, - &sig); - sig_json = TALER_JSON_from_sig (&body.purpose, &sig); - GNUNET_assert (NULL != sig_json); - json_object_set (root, "signature", sig_json); - } - - return TALER_MINT_reply_json (connection, - root, - MHD_HTTP_OK); -} - /** * Verify a signature that is encoded in a JSON object @@ -581,6 +526,7 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, struct TALER_Amount melt_balance; struct GNUNET_HashContext *hash_context; struct GNUNET_HashCode melt_hash; + struct RefreshSession session; res = TALER_MINT_parse_post_json (connection, connection_cls, @@ -620,9 +566,20 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, &refresh_session_pub, NULL); if (GNUNET_YES == res) - return helper_refresh_send_melt_response (connection, - db_conn, - &refresh_session_pub); + { + if (GNUNET_OK != + (res = TALER_MINT_DB_get_refresh_session (db_conn, + &refresh_session_pub, + &session))) + { + // FIXME: send internal error + GNUNET_break (0); + return MHD_NO; + } + return TALER_MINT_reply_refresh_melt_success (connection, + &session, + &refresh_session_pub); + } if (GNUNET_SYSERR == res) { // FIXME: return 'internal error'? @@ -738,9 +695,18 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, GNUNET_break (0); return MHD_NO; } - return helper_refresh_send_melt_response (connection, - db_conn, - &refresh_session_pub); + if (GNUNET_OK != + (res = TALER_MINT_DB_get_refresh_session (db_conn, + &refresh_session_pub, + &session))) + { + // FIXME: send internal error + GNUNET_break (0); + return MHD_NO; + } + return TALER_MINT_reply_refresh_melt_success (connection, + &session, + &refresh_session_pub); } 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 @@ -290,6 +290,49 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection, } +/** + * Send a response for "/refresh/melt". + * + * @param connection the connection to send the response to + * @param db_conn the database connection to fetch values from + * @param session_pub the refresh session public key. + * @return a MHD result code + */ +int +TALER_MINT_reply_refresh_melt_success (struct MHD_Connection *connection, + const struct RefreshSession *session, + const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub) +{ + json_t *root; + json_t *list; + struct GNUNET_HashContext *hash_context; + + root = json_object (); + list = json_array (); + json_object_set_new (root, "blind_session_pubs", list); + hash_context = GNUNET_CRYPTO_hash_context_start (); + + { + struct RefreshMeltResponseSignatureBody body; + struct GNUNET_CRYPTO_EddsaSignature sig; + json_t *sig_json; + + body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody)); + body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE); + GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash); + TALER_MINT_keys_sign (&body.purpose, + &sig); + sig_json = TALER_JSON_from_sig (&body.purpose, &sig); + GNUNET_assert (NULL != sig_json); + json_object_set (root, "signature", sig_json); + } + + return TALER_MINT_reply_json (connection, + root, + MHD_HTTP_OK); +} + + /** * Send a response to a "/refresh/commit" request. * 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, struct RefreshSession *refresh_session); - +/** + * Send a response for "/refresh/melt". + * + * @param connection the connection to send the response to + * @param db_conn the database connection to fetch values from + * @param session_pub the refresh session public key. + * @return a MHD result code + */ +int +TALER_MINT_reply_refresh_melt_success (struct MHD_Connection *connection, + const struct RefreshSession *session, + const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub); -- cgit v1.2.3