From 93a98f8091329d44fe63c092da5f4eaf3bcb983d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 20 Jan 2015 15:17:41 +0100 Subject: starting to refactor refresh code, moving response generation logic to response generation file --- src/mint/taler-mint-httpd_keys.c | 24 ++++++++++ src/mint/taler-mint-httpd_keys.h | 13 ++++++ src/mint/taler-mint-httpd_refresh.c | 82 +++++------------------------------ src/mint/taler-mint-httpd_responses.c | 34 +++++++++++++++ src/mint/taler-mint-httpd_responses.h | 18 ++++++++ 5 files changed, 100 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/mint/taler-mint-httpd_keys.c b/src/mint/taler-mint-httpd_keys.c index 8db32cd83..01679718e 100644 --- a/src/mint/taler-mint-httpd_keys.c +++ b/src/mint/taler-mint-httpd_keys.c @@ -512,4 +512,28 @@ read_again: } +/** + * Sign the message in @a purpose with the mint's signing + * key. + * + * @param purpose the message to sign + * @param[OUT] sig signature over purpose using current signing key + */ +void +TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, + struct GNUNET_CRYPTO_EddsaSignature *sig) + +{ + struct MintKeyState *key_state; + + key_state = TALER_MINT_key_state_acquire (); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (&key_state->current_sign_key_issue.signkey_priv, + purpose, + sig)); + + TALER_MINT_key_state_release (key_state); +} + + /* end of taler-mint-httpd_keys.c */ diff --git a/src/mint/taler-mint-httpd_keys.h b/src/mint/taler-mint-httpd_keys.h index c156cff66..cef0ac950 100644 --- a/src/mint/taler-mint-httpd_keys.h +++ b/src/mint/taler-mint-httpd_keys.h @@ -152,4 +152,17 @@ TALER_MINT_handler_keys (struct RequestHandler *rh, const char *upload_data, size_t *upload_data_size); + +/** + * Sign the message in @a purpose with the mint's signing + * key. + * + * @param purpose the message to sign + * @param[OUT] sig signature over purpose using current signing key + */ +void +TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, + struct GNUNET_CRYPTO_EddsaSignature *sig); + + #endif diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 883da8a85..8f4f13105 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -41,38 +41,6 @@ #include "taler-mint-httpd_responses.h" -/** - * Sign the message in @a purpose with the mint's signing - * key and encode the signature as a JSON object. - * - * @param purpose the message to sign - * @return signature as JSON object - */ -static json_t * -sign_as_json (struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) -{ - json_t *sig_json; - struct GNUNET_CRYPTO_EddsaSignature sig; - struct MintKeyState *key_state; - - key_state = TALER_MINT_key_state_acquire (); - - sig_json = json_object (); - - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (&key_state->current_sign_key_issue.signkey_priv, - purpose, - &sig)); - - TALER_MINT_key_state_release (key_state); - - json_object_set (sig_json, "sig", TALER_JSON_from_data (&sig, sizeof (struct GNUNET_CRYPTO_EddsaSignature))); - json_object_set (sig_json, "purpose", json_integer (ntohl (purpose->purpose))); - json_object_set (sig_json, "size", json_integer (ntohl (purpose->size))); - - return sig_json; -} - - /** * FIXME: document! */ @@ -184,8 +152,7 @@ refresh_accept_denoms (struct MHD_Connection *connection, /** - * Get an amount in the mint's currency - * that is zero. + * Get an amount in the mint's currency that is zero. * * @return zero amount in the mint's currency */ @@ -479,12 +446,15 @@ helper_refresh_send_melt_response (struct MHD_Connection *connection, { 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); - sig_json = sign_as_json (&body.purpose); + 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); } @@ -502,9 +472,9 @@ helper_refresh_send_melt_response (struct MHD_Connection *connection, * @param root the JSON object with the signature * @param the public key that the signature was created with * @param purpose the signed message - * @return GNUNET_YES if the signature was valid - * GNUNET_NO if the signature was invalid - * GNUNET_SYSERR on internal error + * @return #GNUNET_YES if the signature was valid + * #GNUNET_NO if the signature was invalid + * #GNUNET_SYSERR on internal error */ static int request_json_check_signature (struct MHD_Connection *connection, @@ -774,35 +744,6 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, } -/** - * Send a response to a "/refresh/commit" request. - * - * @param connection the connection to send the response to - * @param db_conn the mint database - * @param refresh_session the refresh session - * @return a MHD status code - */ -static int -refresh_send_commit_response (struct MHD_Connection *connection, - PGconn *db_conn, - struct RefreshSession *refresh_session) -{ - struct RefreshCommitResponseSignatureBody body; - json_t *sig_json; - - body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody)); - body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE); - body.noreveal_index = htons (refresh_session->noreveal_index); - sig_json = sign_as_json (&body.purpose); - GNUNET_assert (NULL != sig_json); - return TALER_MINT_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:i, s:o}", - "noreveal_index", (int) refresh_session->noreveal_index, - "signature", sig_json); -} - - /** * Handle a "/refresh/commit" request * @@ -868,9 +809,8 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending cached commit response\n"); - res = refresh_send_commit_response (connection, - db_conn, - &refresh_session); + res = TALER_MINT_reply_refresh_commit_success (connection, + &refresh_session); GNUNET_break (res != GNUNET_SYSERR); return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; } @@ -1072,7 +1012,7 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, return MHD_NO; } - return refresh_send_commit_response (connection, db_conn, &refresh_session); + return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session); } diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 78e239b7c..7aedec1d3 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -290,5 +290,39 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection, } +/** + * Send a response to a "/refresh/commit" request. + * + * FIXME: maybe not the ideal argument type for @a refresh_session here. + * + * @param connection the connection to send the response to + * @param refresh_session the refresh session + * @return a MHD status code + */ +int +TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection, + struct RefreshSession *refresh_session) +{ + struct RefreshCommitResponseSignatureBody body; + struct GNUNET_CRYPTO_EddsaSignature sig; + json_t *sig_json; + + body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody)); + body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE); + body.noreveal_index = htons (refresh_session->noreveal_index); + TALER_MINT_keys_sign (&body.purpose, + &sig); + sig_json = TALER_JSON_from_sig (&body.purpose, &sig); + GNUNET_assert (NULL != sig_json); + return TALER_MINT_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:i, s:o}", + "noreveal_index", (int) refresh_session->noreveal_index, + "signature", sig_json); +} + + + + /* end of taler-mint-httpd_responses.c */ diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index ce7557e1d..ca6b68d50 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h @@ -159,4 +159,22 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection, const struct CollectableBlindcoin *collectable); +/** + * Send a response to a "/refresh/commit" request. + * + * FIXME: maybe not the ideal argument type for @a refresh_session here. + * + * @param connection the connection to send the response to + * @param refresh_session the refresh session + * @return a MHD status code + */ +int +TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection, + struct RefreshSession *refresh_session); + + + + + + #endif -- cgit v1.2.3