diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-20 15:17:41 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-20 15:17:41 +0100 |
commit | 93a98f8091329d44fe63c092da5f4eaf3bcb983d (patch) | |
tree | 8bb70e9d3bc4513a484bc136d3a53d9d5a8b8c56 | |
parent | ed51946442e5e22a7dea68f14ff2bf563503c755 (diff) | |
download | exchange-93a98f8091329d44fe63c092da5f4eaf3bcb983d.tar.gz exchange-93a98f8091329d44fe63c092da5f4eaf3bcb983d.zip |
starting to refactor refresh code, moving response generation logic to response generation file
-rw-r--r-- | src/mint/taler-mint-httpd_keys.c | 24 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_keys.h | 13 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_refresh.c | 82 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 34 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.h | 18 |
5 files changed, 100 insertions, 71 deletions
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: | |||
512 | } | 512 | } |
513 | 513 | ||
514 | 514 | ||
515 | /** | ||
516 | * Sign the message in @a purpose with the mint's signing | ||
517 | * key. | ||
518 | * | ||
519 | * @param purpose the message to sign | ||
520 | * @param[OUT] sig signature over purpose using current signing key | ||
521 | */ | ||
522 | void | ||
523 | TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
524 | struct GNUNET_CRYPTO_EddsaSignature *sig) | ||
525 | |||
526 | { | ||
527 | struct MintKeyState *key_state; | ||
528 | |||
529 | key_state = TALER_MINT_key_state_acquire (); | ||
530 | GNUNET_assert (GNUNET_OK == | ||
531 | GNUNET_CRYPTO_eddsa_sign (&key_state->current_sign_key_issue.signkey_priv, | ||
532 | purpose, | ||
533 | sig)); | ||
534 | |||
535 | TALER_MINT_key_state_release (key_state); | ||
536 | } | ||
537 | |||
538 | |||
515 | /* end of taler-mint-httpd_keys.c */ | 539 | /* 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, | |||
152 | const char *upload_data, | 152 | const char *upload_data, |
153 | size_t *upload_data_size); | 153 | size_t *upload_data_size); |
154 | 154 | ||
155 | |||
156 | /** | ||
157 | * Sign the message in @a purpose with the mint's signing | ||
158 | * key. | ||
159 | * | ||
160 | * @param purpose the message to sign | ||
161 | * @param[OUT] sig signature over purpose using current signing key | ||
162 | */ | ||
163 | void | ||
164 | TALER_MINT_keys_sign (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
165 | struct GNUNET_CRYPTO_EddsaSignature *sig); | ||
166 | |||
167 | |||
155 | #endif | 168 | #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 | |||
@@ -42,38 +42,6 @@ | |||
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Sign the message in @a purpose with the mint's signing | ||
46 | * key and encode the signature as a JSON object. | ||
47 | * | ||
48 | * @param purpose the message to sign | ||
49 | * @return signature as JSON object | ||
50 | */ | ||
51 | static json_t * | ||
52 | sign_as_json (struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) | ||
53 | { | ||
54 | json_t *sig_json; | ||
55 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
56 | struct MintKeyState *key_state; | ||
57 | |||
58 | key_state = TALER_MINT_key_state_acquire (); | ||
59 | |||
60 | sig_json = json_object (); | ||
61 | |||
62 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (&key_state->current_sign_key_issue.signkey_priv, | ||
63 | purpose, | ||
64 | &sig)); | ||
65 | |||
66 | TALER_MINT_key_state_release (key_state); | ||
67 | |||
68 | json_object_set (sig_json, "sig", TALER_JSON_from_data (&sig, sizeof (struct GNUNET_CRYPTO_EddsaSignature))); | ||
69 | json_object_set (sig_json, "purpose", json_integer (ntohl (purpose->purpose))); | ||
70 | json_object_set (sig_json, "size", json_integer (ntohl (purpose->size))); | ||
71 | |||
72 | return sig_json; | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * FIXME: document! | 45 | * FIXME: document! |
78 | */ | 46 | */ |
79 | static int | 47 | static int |
@@ -184,8 +152,7 @@ refresh_accept_denoms (struct MHD_Connection *connection, | |||
184 | 152 | ||
185 | 153 | ||
186 | /** | 154 | /** |
187 | * Get an amount in the mint's currency | 155 | * Get an amount in the mint's currency that is zero. |
188 | * that is zero. | ||
189 | * | 156 | * |
190 | * @return zero amount in the mint's currency | 157 | * @return zero amount in the mint's currency |
191 | */ | 158 | */ |
@@ -479,12 +446,15 @@ helper_refresh_send_melt_response (struct MHD_Connection *connection, | |||
479 | 446 | ||
480 | { | 447 | { |
481 | struct RefreshMeltResponseSignatureBody body; | 448 | struct RefreshMeltResponseSignatureBody body; |
449 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
482 | json_t *sig_json; | 450 | json_t *sig_json; |
483 | 451 | ||
484 | body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody)); | 452 | body.purpose.size = htonl (sizeof (struct RefreshMeltResponseSignatureBody)); |
485 | body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE); | 453 | body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_RESPONSE); |
486 | GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash); | 454 | GNUNET_CRYPTO_hash_context_finish (hash_context, &body.melt_response_hash); |
487 | sig_json = sign_as_json (&body.purpose); | 455 | TALER_MINT_keys_sign (&body.purpose, |
456 | &sig); | ||
457 | sig_json = TALER_JSON_from_sig (&body.purpose, &sig); | ||
488 | GNUNET_assert (NULL != sig_json); | 458 | GNUNET_assert (NULL != sig_json); |
489 | json_object_set (root, "signature", sig_json); | 459 | json_object_set (root, "signature", sig_json); |
490 | } | 460 | } |
@@ -502,9 +472,9 @@ helper_refresh_send_melt_response (struct MHD_Connection *connection, | |||
502 | * @param root the JSON object with the signature | 472 | * @param root the JSON object with the signature |
503 | * @param the public key that the signature was created with | 473 | * @param the public key that the signature was created with |
504 | * @param purpose the signed message | 474 | * @param purpose the signed message |
505 | * @return GNUNET_YES if the signature was valid | 475 | * @return #GNUNET_YES if the signature was valid |
506 | * GNUNET_NO if the signature was invalid | 476 | * #GNUNET_NO if the signature was invalid |
507 | * GNUNET_SYSERR on internal error | 477 | * #GNUNET_SYSERR on internal error |
508 | */ | 478 | */ |
509 | static int | 479 | static int |
510 | request_json_check_signature (struct MHD_Connection *connection, | 480 | request_json_check_signature (struct MHD_Connection *connection, |
@@ -775,35 +745,6 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
775 | 745 | ||
776 | 746 | ||
777 | /** | 747 | /** |
778 | * Send a response to a "/refresh/commit" request. | ||
779 | * | ||
780 | * @param connection the connection to send the response to | ||
781 | * @param db_conn the mint database | ||
782 | * @param refresh_session the refresh session | ||
783 | * @return a MHD status code | ||
784 | */ | ||
785 | static int | ||
786 | refresh_send_commit_response (struct MHD_Connection *connection, | ||
787 | PGconn *db_conn, | ||
788 | struct RefreshSession *refresh_session) | ||
789 | { | ||
790 | struct RefreshCommitResponseSignatureBody body; | ||
791 | json_t *sig_json; | ||
792 | |||
793 | body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody)); | ||
794 | body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE); | ||
795 | body.noreveal_index = htons (refresh_session->noreveal_index); | ||
796 | sig_json = sign_as_json (&body.purpose); | ||
797 | GNUNET_assert (NULL != sig_json); | ||
798 | return TALER_MINT_reply_json_pack (connection, | ||
799 | MHD_HTTP_OK, | ||
800 | "{s:i, s:o}", | ||
801 | "noreveal_index", (int) refresh_session->noreveal_index, | ||
802 | "signature", sig_json); | ||
803 | } | ||
804 | |||
805 | |||
806 | /** | ||
807 | * Handle a "/refresh/commit" request | 748 | * Handle a "/refresh/commit" request |
808 | * | 749 | * |
809 | * @param rh context of the handler | 750 | * @param rh context of the handler |
@@ -868,9 +809,8 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, | |||
868 | { | 809 | { |
869 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 810 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
870 | "sending cached commit response\n"); | 811 | "sending cached commit response\n"); |
871 | res = refresh_send_commit_response (connection, | 812 | res = TALER_MINT_reply_refresh_commit_success (connection, |
872 | db_conn, | 813 | &refresh_session); |
873 | &refresh_session); | ||
874 | GNUNET_break (res != GNUNET_SYSERR); | 814 | GNUNET_break (res != GNUNET_SYSERR); |
875 | return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; | 815 | return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; |
876 | } | 816 | } |
@@ -1072,7 +1012,7 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, | |||
1072 | return MHD_NO; | 1012 | return MHD_NO; |
1073 | } | 1013 | } |
1074 | 1014 | ||
1075 | return refresh_send_commit_response (connection, db_conn, &refresh_session); | 1015 | return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session); |
1076 | } | 1016 | } |
1077 | 1017 | ||
1078 | 1018 | ||
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, | |||
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | /** | ||
294 | * Send a response to a "/refresh/commit" request. | ||
295 | * | ||
296 | * FIXME: maybe not the ideal argument type for @a refresh_session here. | ||
297 | * | ||
298 | * @param connection the connection to send the response to | ||
299 | * @param refresh_session the refresh session | ||
300 | * @return a MHD status code | ||
301 | */ | ||
302 | int | ||
303 | TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection, | ||
304 | struct RefreshSession *refresh_session) | ||
305 | { | ||
306 | struct RefreshCommitResponseSignatureBody body; | ||
307 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
308 | json_t *sig_json; | ||
309 | |||
310 | body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody)); | ||
311 | body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE); | ||
312 | body.noreveal_index = htons (refresh_session->noreveal_index); | ||
313 | TALER_MINT_keys_sign (&body.purpose, | ||
314 | &sig); | ||
315 | sig_json = TALER_JSON_from_sig (&body.purpose, &sig); | ||
316 | GNUNET_assert (NULL != sig_json); | ||
317 | return TALER_MINT_reply_json_pack (connection, | ||
318 | MHD_HTTP_OK, | ||
319 | "{s:i, s:o}", | ||
320 | "noreveal_index", (int) refresh_session->noreveal_index, | ||
321 | "signature", sig_json); | ||
322 | } | ||
323 | |||
324 | |||
325 | |||
326 | |||
293 | 327 | ||
294 | /* end of taler-mint-httpd_responses.c */ | 328 | /* 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, | |||
159 | const struct CollectableBlindcoin *collectable); | 159 | const struct CollectableBlindcoin *collectable); |
160 | 160 | ||
161 | 161 | ||
162 | /** | ||
163 | * Send a response to a "/refresh/commit" request. | ||
164 | * | ||
165 | * FIXME: maybe not the ideal argument type for @a refresh_session here. | ||
166 | * | ||
167 | * @param connection the connection to send the response to | ||
168 | * @param refresh_session the refresh session | ||
169 | * @return a MHD status code | ||
170 | */ | ||
171 | int | ||
172 | TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection, | ||
173 | struct RefreshSession *refresh_session); | ||
174 | |||
175 | |||
176 | |||
177 | |||
178 | |||
179 | |||
162 | #endif | 180 | #endif |