From 42147c2501d06c44c8bfbc052d72fb2e97eaa2c6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 29 Mar 2015 14:17:52 +0200 Subject: switching /withdraw/sign from GET to POST --- src/mint/taler-mint-httpd.c | 37 +++++++++------ src/mint/taler-mint-httpd_deposit.c | 4 +- src/mint/taler-mint-httpd_parsing.c | 52 ++++++++++++-------- src/mint/taler-mint-httpd_parsing.h | 10 ++-- src/mint/taler-mint-httpd_refresh.c | 42 ++++++++-------- src/mint/taler-mint-httpd_withdraw.c | 92 +++++++++++++----------------------- 6 files changed, 114 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/mint/taler-mint-httpd.c b/src/mint/taler-mint-httpd.c index e9bfac730..1315ba204 100644 --- a/src/mint/taler-mint-httpd.c +++ b/src/mint/taler-mint-httpd.c @@ -137,54 +137,63 @@ handle_mhd_request (void *cls, { "/agpl", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, &TMH_MHD_handler_agpl_redirect, MHD_HTTP_FOUND }, + { "/keys", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, &TMH_KS_handler_keys, MHD_HTTP_OK }, { "/keys", NULL, "text/plain", "Only GET is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { "/withdraw/status", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, &TMH_WITHDRAW_handler_withdraw_status, MHD_HTTP_OK }, { "/withdraw/status", NULL, "text/plain", "Only GET is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/withdraw/sign", MHD_HTTP_METHOD_GET, "application/json", + + { "/withdraw/sign", MHD_HTTP_METHOD_POST, "application/json", NULL, 0, &TMH_WITHDRAW_handler_withdraw_sign, MHD_HTTP_OK }, { "/withdraw/sign", NULL, "text/plain", - "Only GET is allowed", 0, + "Only POST is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + + { "/deposit", MHD_HTTP_METHOD_POST, "application/json", + NULL, 0, + &TMH_DEPOSIT_handler_deposit, MHD_HTTP_OK }, + { "/deposit", NULL, "text/plain", + "Only POST is allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { "/refresh/melt", MHD_HTTP_METHOD_POST, "application/json", NULL, 0, &TMH_REFRESH_handler_refresh_melt, MHD_HTTP_OK }, { "/refresh/melt", NULL, "text/plain", "Only POST is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { "/refresh/reveal", MHD_HTTP_METHOD_POST, "application/json", NULL, 0, &TMH_REFRESH_handler_refresh_melt, MHD_HTTP_OK }, { "/refresh/reveal", NULL, "text/plain", "Only POST is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/refresh/link", MHD_HTTP_METHOD_GET, "application/json", - NULL, 0, - &TMH_REFRESH_handler_refresh_link, MHD_HTTP_OK }, - { "/refresh/link", NULL, "text/plain", - "Only GET is allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/refresh/reveal", MHD_HTTP_METHOD_GET, "application/json", + + { "/refresh/reveal", MHD_HTTP_METHOD_POST, "application/json", NULL, 0, &TMH_REFRESH_handler_refresh_reveal, MHD_HTTP_OK }, { "/refresh/reveal", NULL, "text/plain", - "Only GET is allowed", 0, + "Only POST is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/deposit", MHD_HTTP_METHOD_POST, "application/json", + + { "/refresh/link", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, - &TMH_DEPOSIT_handler_deposit, MHD_HTTP_OK }, - { "/deposit", NULL, "text/plain", - "Only POST is allowed", 0, + &TMH_REFRESH_handler_refresh_link, MHD_HTTP_OK }, + { "/refresh/link", NULL, "text/plain", + "Only GET is allowed", 0, &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { NULL, NULL, NULL, NULL, 0, 0 } }; static struct TMH_RequestHandler h404 = diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index 72c4b0d19..18cc18f7b 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -144,8 +144,8 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TMH_KS_StateHandle *ks; struct TMH_PARSE_FieldSpecification spec[] = { - TMH_PARSE_MEMBER_RSA_PUBLIC_KEY ("denom_pub", &deposit.coin.denom_pub), - TMH_PARSE_MEMBER_RSA_SIGNATURE ("ubsig", &deposit.coin.denom_sig), + TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &deposit.coin.denom_pub), + TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("ubsig", &deposit.coin.denom_sig), TMH_PARSE_MEMBER_FIXED ("coin_pub", &deposit.coin.coin_pub), TMH_PARSE_MEMBER_FIXED ("merchant_pub", &deposit.merchant_pub), TMH_PARSE_MEMBER_FIXED ("H_a", &deposit.h_contract), diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index c9e060b9e..f8df1855c 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c @@ -189,7 +189,7 @@ TMH_PARSE_post_json (struct MHD_Connection *connection, GNUNET_free (r); return (MHD_NO == TMH_RESPONSE_reply_internal_error (connection, - "out of memory")) + "out of memory")) ? GNUNET_SYSERR : GNUNET_NO; } /* everything OK, wait for more POST data */ @@ -376,8 +376,8 @@ TMH_PARSE_mhd_request_var_arg_data (struct MHD_Connection *connection, */ int TMH_PARSE_navigate_json (struct MHD_Connection *connection, - const json_t *root, - ...) + const json_t *root, + ...) { va_list argp; int ret; @@ -555,13 +555,14 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY: { - void **where = va_arg (argp, void **); + struct TALER_DenominationPublicKey *where; size_t len; const char *str; int res; void *buf; - // FIXME: avoidable code duplication here... + where = va_arg (argp, + struct TALER_DenominationPublicKey *); str = json_string_value (root); if (NULL == str) { @@ -596,10 +597,10 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, ? GNUNET_NO : GNUNET_SYSERR; break; } - *where = GNUNET_CRYPTO_rsa_public_key_decode (buf, - len); + where->rsa_public_key = GNUNET_CRYPTO_rsa_public_key_decode (buf, + len); GNUNET_free (buf); - if (NULL == *where) + if (NULL == where->rsa_public_key) { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, @@ -618,13 +619,14 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, case TMH_PARSE_JNC_RET_RSA_SIGNATURE: { - void **where = va_arg (argp, void **); + struct TALER_DenominationSignature *where; size_t len; const char *str; int res; void *buf; - // FIXME: avoidable code duplication here... + where = va_arg (argp, + struct TALER_DenominationSignature *); str = json_string_value (root); if (NULL == str) { @@ -659,10 +661,10 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, ? GNUNET_NO : GNUNET_SYSERR; break; } - *where = GNUNET_CRYPTO_rsa_signature_decode (buf, - len); + where->rsa_signature = GNUNET_CRYPTO_rsa_signature_decode (buf, + len); GNUNET_free (buf); - if (NULL == *where) + if (NULL == where->rsa_signature) { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, @@ -874,19 +876,27 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec) } break; case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY: - ptr = *(void **) spec[i].destination; - if (NULL != ptr) { - GNUNET_CRYPTO_rsa_public_key_free (ptr); - *(void**) spec[i].destination = NULL; + struct TALER_DenominationPublicKey pk; + + pk = *(struct TALER_DenominationPublicKey *) spec[i].destination; + if (NULL != pk.rsa_public_key) + { + GNUNET_CRYPTO_rsa_public_key_free (pk.rsa_public_key); + pk.rsa_public_key = NULL; + } } break; case TMH_PARSE_JNC_RET_RSA_SIGNATURE: - ptr = *(void **) spec[i].destination; - if (NULL != ptr) { - GNUNET_CRYPTO_rsa_signature_free (ptr); - *(void**) spec[i].destination = NULL; + struct TALER_DenominationSignature sig; + + sig = *(struct TALER_DenominationSignature *) spec[i].destination; + if (NULL != sig.rsa_signature) + { + GNUNET_CRYPTO_rsa_signature_free (sig.rsa_signature); + sig.rsa_signature = NULL; + } } break; case TMH_PARSE_JNC_RET_AMOUNT: diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index 6e10ac2a1..feac6087d 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014 GNUnet e.V. + Copyright (C) 2014, 2015 GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -271,17 +271,17 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec); * Generate line in parser specification for RSA public key. * * @param field name of the field - * @param ptrpk address of `struct GNUNET_CRYPTO_rsa_PublicKey *` initialize + * @param ptrpk address of `struct TALER_DenominationPublicKey` initialize */ -#define TMH_PARSE_MEMBER_RSA_PUBLIC_KEY(field,ptrpk) { field, ptrpk, 0, 0, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, 0 } +#define TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY(field,ptrpk) { field, ptrpk, 0, 0, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, 0 } /** * Generate line in parser specification for RSA public key. * * @param field name of the field - * @param ptrsig address of `struct GNUNET_CRYPTO_rsa_Signature *` initialize + * @param ptrsig address of `struct TALER_DenominationSignature *` initialize */ -#define TMH_PARSE_MEMBER_RSA_SIGNATURE(field,ptrsig) { field, ptrsig, 0, 0, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 } +#define TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE(field,ptrsig) { field, ptrsig, 0, 0, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 } /** * Generate line in parser specification for an amount. diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index c99c5c2dc..151035c04 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -176,8 +176,8 @@ get_coin_public_info (struct MHD_Connection *connection, struct TALER_Amount amount; struct TMH_PARSE_FieldSpecification spec[] = { TMH_PARSE_MEMBER_FIXED ("coin_pub", &r_melt_detail->coin_info.coin_pub), - TMH_PARSE_MEMBER_RSA_SIGNATURE ("denom_sig", &sig.rsa_signature), - TMH_PARSE_MEMBER_RSA_PUBLIC_KEY ("denom_pub", &pk.rsa_public_key), + TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("denom_sig", &sig.rsa_signature), + TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &pk.rsa_public_key), TMH_PARSE_MEMBER_FIXED ("confirm_sig", &melt_sig), TMH_PARSE_MEMBER_AMOUNT ("value_with_fee", &amount), TMH_PARSE_MEMBER_END @@ -396,10 +396,10 @@ handle_refresh_melt_json (struct MHD_Connection *connection, size_t buf_size; res = TMH_PARSE_navigate_json (connection, - new_denoms, - TMH_PARSE_JNC_INDEX, (int) i, - TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, - &denom_pubs[i].rsa_public_key); + new_denoms, + TMH_PARSE_JNC_INDEX, (int) i, + TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, + &denom_pubs[i].rsa_public_key); if (GNUNET_OK != res) { for (j=0;j