diff options
Diffstat (limited to 'src/exchange')
-rw-r--r-- | src/exchange/taler-exchange-httpd_db.c | 128 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_responses.c | 95 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_responses.h | 12 |
3 files changed, 83 insertions, 152 deletions
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c index c58fe02da..f1c69b7a9 100644 --- a/src/exchange/taler-exchange-httpd_db.c +++ b/src/exchange/taler-exchange-httpd_db.c @@ -991,7 +991,6 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection, struct TALER_EXCHANGEDB_RefreshSession refresh_session; struct TALER_EXCHANGEDB_Session *session; int res; - unsigned int i; if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls))) { @@ -1064,34 +1063,26 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection, return TMH_RESPONSE_reply_internal_db_error (connection); } - for (i = 0; i < TALER_CNC_KAPPA; i++) + if (GNUNET_OK != + TMH_plugin->insert_refresh_commit_coins (TMH_plugin->cls, + session, + session_hash, + num_new_denoms, + commit_coin[refresh_session.noreveal_index])) { - if (GNUNET_OK != - TMH_plugin->insert_refresh_commit_coins (TMH_plugin->cls, - session, - session_hash, - i, - num_new_denoms, - commit_coin[i])) - { - TMH_plugin->rollback (TMH_plugin->cls, - session); - return TMH_RESPONSE_reply_internal_db_error (connection); - } + TMH_plugin->rollback (TMH_plugin->cls, + session); + return TMH_RESPONSE_reply_internal_db_error (connection); } - for (i = 0; i < TALER_CNC_KAPPA; i++) + if (GNUNET_OK != + TMH_plugin->insert_refresh_transfer_public_key (TMH_plugin->cls, + session, + session_hash, + &transfer_pubs[refresh_session.noreveal_index])) { - if (GNUNET_OK != - TMH_plugin->insert_refresh_transfer_public_key (TMH_plugin->cls, - session, - session_hash, - i, - &transfer_pubs[i])) - { - TMH_plugin->rollback (TMH_plugin->cls, - session); - return TMH_RESPONSE_reply_internal_db_error (connection); - } + TMH_plugin->rollback (TMH_plugin->cls, + session); + return TMH_RESPONSE_reply_internal_db_error (connection); } COMMIT_TRANSACTION (session, connection); @@ -1102,48 +1093,6 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection, /** - * Send an error response with the details of the original melt - * commitment and the location of the mismatch. - * - * @param connection the MHD connection to handle - * @param session database connection to use - * @param session_hash hash of session to query - * @param rm details about the original melt - * @return #GNUNET_NO if we generated the error message - * #GNUNET_SYSERR if we could not even generate an error message - */ -static int -send_melt_commitment_error (struct MHD_Connection *connection, - struct TALER_EXCHANGEDB_Session *session, - const struct GNUNET_HashCode *session_hash, - const struct TALER_EXCHANGEDB_RefreshMelt *rm) -{ - struct TALER_EXCHANGEDB_MeltCommitment *mc; - int ret; - - mc = TMH_plugin->get_melt_commitment (TMH_plugin->cls, - session, - session_hash); - if (NULL == mc) - { - GNUNET_break (0); - return (MHD_YES == - TMH_RESPONSE_reply_internal_error (connection, - "Melt commitment assembly")) - ? GNUNET_NO : GNUNET_SYSERR; - } - ret = (MHD_YES == - TMH_RESPONSE_reply_refresh_reveal_missmatch (connection, - rm, - mc)) - ? GNUNET_NO : GNUNET_SYSERR; - TMH_plugin->free_melt_commitment (TMH_plugin->cls, - mc); - return ret; -} - - -/** * Check if the given @a transfer_privs correspond to an honest * commitment for the given session. * Checks that the transfer private keys match their commitments. @@ -1368,6 +1317,8 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, unsigned int off; struct GNUNET_HashContext *hash_context; struct GNUNET_HashCode sh_check; + int ret; + struct TALER_TransferPublicKeyP gamma_tp; if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls))) { @@ -1382,7 +1333,8 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, if (GNUNET_NO == res) return TMH_RESPONSE_reply_arg_invalid (connection, "session_hash"); - if (GNUNET_SYSERR == res) + if ( (GNUNET_SYSERR == res) || + (refresh_session.noreveal_index >= TALER_CNC_KAPPA) ) return TMH_RESPONSE_reply_internal_db_error (connection); denom_pubs = GNUNET_new_array (refresh_session.num_newcoins, struct TALER_DenominationPublicKey); @@ -1406,18 +1358,15 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, off = 0; for (i=0;i<TALER_CNC_KAPPA;i++) { - struct TALER_TransferPublicKeyP tp; - if (i == refresh_session.noreveal_index) { off = 1; - /* obtain tp from db */ + /* obtain gamma_tp from db */ if (GNUNET_OK != TMH_plugin->get_refresh_transfer_public_key (TMH_plugin->cls, session, session_hash, - i, - &tp)) + &gamma_tp)) { GNUNET_break (0); GNUNET_free (denom_pubs); @@ -1427,16 +1376,21 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, return (MHD_YES == TMH_RESPONSE_reply_internal_db_error (connection)) ? GNUNET_NO : GNUNET_SYSERR; } + GNUNET_CRYPTO_hash_context_read (hash_context, + &gamma_tp, + sizeof (struct TALER_TransferPublicKeyP)); } else { /* compute tp from private key */ + struct TALER_TransferPublicKeyP tp; + GNUNET_CRYPTO_ecdhe_key_get_public (&transfer_privs[i - off].ecdhe_priv, &tp.ecdhe_pub); + GNUNET_CRYPTO_hash_context_read (hash_context, + &tp, + sizeof (struct TALER_TransferPublicKeyP)); } - GNUNET_CRYPTO_hash_context_read (hash_context, - &tp, - sizeof (struct TALER_TransferPublicKeyP)); } /* next, add all of the hashes from the denomination keys to the @@ -1501,7 +1455,6 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, TMH_plugin->get_refresh_commit_coins (TMH_plugin->cls, session, session_hash, - i, refresh_session.num_newcoins, commit_coins)) { @@ -1534,7 +1487,10 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, { GNUNET_break_op (0); for (j=0;j<refresh_session.num_newcoins;j++) + { GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key); + GNUNET_free (commit_coins[j].coin_ev); + } GNUNET_free (commit_coins); GNUNET_free (denom_pubs); GNUNET_CRYPTO_rsa_signature_free (refresh_session.melt.coin.denom_sig.rsa_signature); @@ -1552,16 +1508,24 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection, sizeof (struct GNUNET_HashCode))) { GNUNET_break_op (0); + ret = (MHD_YES == + TMH_RESPONSE_reply_refresh_reveal_missmatch (connection, + &refresh_session, + commit_coins, + denom_pubs, + &gamma_tp)) + ? GNUNET_NO : GNUNET_SYSERR; for (j=0;j<refresh_session.num_newcoins;j++) + { + GNUNET_free (commit_coins[j].coin_ev); GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key); + } + GNUNET_free (commit_coins); GNUNET_free (denom_pubs); GNUNET_CRYPTO_rsa_signature_free (refresh_session.melt.coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_public_key_free (refresh_session.melt.coin.denom_pub.rsa_public_key); - return send_melt_commitment_error (connection, - session, - session_hash, - &refresh_session.melt); + return ret; } /* Client request OK, start transaction */ diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index 799bc0c0f..5be8d1773 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -972,92 +972,55 @@ TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection, * revealed value(s) do not match the original commitment. * * @param connection the connection to send the response to - * @param rm details about the original melt - * @param mc all information about the original commitment + * @param session info about session + * @param commit_coins array of @a num_newcoins committed envelopes at offset @a gamma + * @param denom_pubs array of @a num_newcoins denomination keys for the new coins + * @param gamma_tp transfer public key at offset @a gamma * @return a MHD result code */ int TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, - const struct TALER_EXCHANGEDB_RefreshMelt *rm, - const struct TALER_EXCHANGEDB_MeltCommitment *mc) + const struct TALER_EXCHANGEDB_RefreshSession *session, + const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins, + const struct TALER_DenominationPublicKey *denom_pubs, + const struct TALER_TransferPublicKeyP *gamma_tp) { json_t *info_new; - json_t *info_commit; - json_t *info_links; + json_t *info_commit_k; unsigned int i; - unsigned int k; - json_t *rm_json; - - rm_json = json_object (); - json_object_set_new (rm_json, - "coin_sig", - GNUNET_JSON_from_data_auto (&rm->coin_sig)); - json_object_set_new (rm_json, - "coin_pub", - GNUNET_JSON_from_data_auto (&rm->coin.coin_pub)); - json_object_set_new (rm_json, - "melt_amount_with_fee", - TALER_JSON_from_amount (&rm->amount_with_fee)); - json_object_set_new (rm_json, - "melt_fee", - TALER_JSON_from_amount (&rm->melt_fee)); info_new = json_array (); - for (i=0;i<mc->num_newcoins;i++) + info_commit_k = json_array (); + for (i=0;i<session->num_newcoins;i++) { - const struct TALER_DenominationPublicKey *pk; + const struct TALER_EXCHANGEDB_RefreshCommitCoin *cc; + json_t *cc_json; - pk = &mc->denom_pubs[i]; GNUNET_assert (0 == json_array_append_new (info_new, - GNUNET_JSON_from_rsa_public_key (pk->rsa_public_key))); + GNUNET_JSON_from_rsa_public_key (denom_pubs[i].rsa_public_key))); - } - info_commit = json_array (); - info_links = json_array (); - for (k=0;k<TALER_CNC_KAPPA;k++) - { - json_t *info_commit_k; - json_t *info_link_k; - const struct TALER_TransferPublicKeyP *transfer_pub; - - info_commit_k = json_array (); - for (i=0;i<mc->num_newcoins;i++) - { - const struct TALER_EXCHANGEDB_RefreshCommitCoin *cc; - json_t *cc_json; - - cc = &mc->commit_coins[k][i]; - cc_json = json_object (); - json_object_set_new (cc_json, - "coin_ev", - GNUNET_JSON_from_data (cc->coin_ev, - cc->coin_ev_size)); - GNUNET_assert (0 == - json_array_append_new (info_commit_k, - cc_json)); - } - GNUNET_assert (0 == - json_array_append_new (info_commit, - info_commit_k)); - - info_link_k = json_object (); - transfer_pub = &mc->transfer_pubs[k]; - json_object_set_new (info_link_k, - "transfer_pub", - GNUNET_JSON_from_data_auto (transfer_pub)); + cc = &commit_coins[i]; + cc_json = json_pack ("{s:o}", + "coin_ev", + GNUNET_JSON_from_data (cc->coin_ev, + cc->coin_ev_size)); GNUNET_assert (0 == - json_array_append_new (info_links, - info_link_k)); + json_array_append_new (info_commit_k, + cc_json)); } return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_CONFLICT, - "{s:s, s:o, s:o, s:o, s:o}", + "{s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:i}", "error", "commitment violation", - "refresh_melt_info", rm_json, + "coin_sig", GNUNET_JSON_from_data_auto (&session->melt.coin_sig), + "coin_pub", GNUNET_JSON_from_data_auto (&session->melt.coin.coin_pub), + "melt_amount_with_fee", TALER_JSON_from_amount (&session->melt.amount_with_fee), + "melt_fee", TALER_JSON_from_amount (&session->melt.melt_fee), "newcoin_infos", info_new, - "commit_infos", info_commit, - "link_infos", info_links); + "commit_infos", info_commit_k, + "gamma_tp", GNUNET_JSON_from_data_auto (gamma_tp), + "gamma", (int) session->noreveal_index); } diff --git a/src/exchange/taler-exchange-httpd_responses.h b/src/exchange/taler-exchange-httpd_responses.h index 99f021774..82317d89a 100644 --- a/src/exchange/taler-exchange-httpd_responses.h +++ b/src/exchange/taler-exchange-httpd_responses.h @@ -492,14 +492,18 @@ TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection, * revealed value(s) do not match the original commitment. * * @param connection the connection to send the response to - * @param rm details about the original melt - * @param mc all information about the original commitment + * @param session info about session + * @param commit_coins array of @a num_newcoins committed envelopes at offset @a gamma + * @param denom_pubs array of @a num_newcoins denomination keys for the new coins + * @param gamma_tp transfer public key at offset @a gamma * @return a MHD result code */ int TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, - const struct TALER_EXCHANGEDB_RefreshMelt *rm, - const struct TALER_EXCHANGEDB_MeltCommitment *mc); + const struct TALER_EXCHANGEDB_RefreshSession *session, + const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins, + const struct TALER_DenominationPublicKey *denom_pubs, + const struct TALER_TransferPublicKeyP *gamma_tp); /** |