diff options
-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 | ||||
-rw-r--r-- | src/exchangedb/perf_taler_exchangedb_interpreter.c | 4 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_common.c | 36 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 126 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 194 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 62 |
8 files changed, 161 insertions, 496 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); /** diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c index 3b858d1bf..b869ad413 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.c +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c @@ -1620,7 +1620,6 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) state->session, state->cmd[hash_index].exposed.data.session_hash, 1, - 1, refresh_commit); GNUNET_assert (GNUNET_OK == ret); } @@ -1636,7 +1635,6 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) state->session, state->cmd[hash_index].exposed.data.session_hash, 1, - 1, &refresh_commit); } @@ -1656,12 +1654,12 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) unsigned int hash_index; struct TALER_EXCHANGEDB_RefreshCommitCoin commit_coin; + // FIXME: this should go after the public key! hash_index = state->cmd[state->i].details.get_refresh_commit_link.index_hash; ret = state->plugin->get_refresh_commit_coins(state->plugin->cls, state->session, state->cmd[hash_index].exposed.data.session_hash, 1, - 1, &commit_coin); GNUNET_assert (GNUNET_SYSERR != ret); } diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c index bb6801e80..1aa77a481 100644 --- a/src/exchangedb/plugin_exchangedb_common.c +++ b/src/exchangedb/plugin_exchangedb_common.c @@ -132,40 +132,4 @@ common_free_coin_transaction_list (void *cls, } -/** - * Free melt commitment data. - * - * @param cls the @e cls of this struct with the plugin-specific state (unused) - * @param mc data structure to free - */ -static void -common_free_melt_commitment (void *cls, - struct TALER_EXCHANGEDB_MeltCommitment *mc) -{ - unsigned int i; - unsigned int k; - - if (NULL != mc->denom_pubs) - { - for (i=0;i<mc->num_newcoins;i++) - if (NULL != mc->denom_pubs[i].rsa_public_key) - GNUNET_CRYPTO_rsa_public_key_free (mc->denom_pubs[i].rsa_public_key); - GNUNET_free (mc->denom_pubs); - } - for (k=0;k<TALER_CNC_KAPPA;k++) - { - if (NULL != mc->commit_coins[k]) - { - for (i=0;i<mc->num_newcoins;i++) - { - /* NOTE: 'non_null' because this API is used also - internally to clean up the struct on failures! */ - GNUNET_free_non_null (mc->commit_coins[k][i].coin_ev); - } - GNUNET_free (mc->commit_coins[k]); - } - } - GNUNET_free (mc); -} - /* end of plugin_exchangedb_common.c */ diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 0c4f908c3..bd8670eb7 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -386,29 +386,24 @@ postgres_create_tables (void *cls) as well as the actual link data (the transfer public key and the encrypted link secret) */ SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_transfer_public_key " - "(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE" + "(session_hash BYTEA NOT NULL PRIMARY KEY REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE" ",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)" - ",cnc_index INT2 NOT NULL" - ",UNIQUE (session_hash, cnc_index)" ")"); - SQLEXEC_INDEX("CREATE INDEX refresh_transfer_public_key_index " - "ON refresh_transfer_public_key(session_hash, cnc_index)"); /* Table with the commitments for the new coins that are to be created during a melting session. Includes the session, the cut-and-choose index and the index of the new coin, and the envelope of the new coin to be signed, as well as the encrypted information about the private key and the blinding factor for the coin (for verification - in case this cnc_index is chosen to be revealed) */ + in case this newcoin_index is chosen to be revealed) */ SQLEXEC("CREATE TABLE IF NOT EXISTS refresh_commit_coin " "(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE" - ",cnc_index INT2 NOT NULL" ",newcoin_index INT2 NOT NULL" ",coin_ev BYTEA NOT NULL" - ",UNIQUE (session_hash, cnc_index, newcoin_index)" + ",UNIQUE (session_hash, newcoin_index)" ")"); SQLEXEC_INDEX("CREATE INDEX refresh_commit_coin_session_hash_index " - "ON refresh_commit_coin(session_hash, cnc_index, newcoin_index)"); + "ON refresh_commit_coin(session_hash, newcoin_index)"); /* Table with the signatures over coins generated during a refresh @@ -831,9 +826,8 @@ postgres_prepare (PGconn *db_conn) "INSERT INTO refresh_transfer_public_key " "(session_hash" ",transfer_pub" - ",cnc_index" ") VALUES " - "($1, $2, $3);", + "($1, $2);", 3, NULL); /* Used in #postgres_get_refresh_transfer_public_key() to @@ -842,20 +836,19 @@ postgres_prepare (PGconn *db_conn) "SELECT" " transfer_pub" " FROM refresh_transfer_public_key" - " WHERE session_hash=$1 AND cnc_index=$2", - 2, NULL); + " WHERE session_hash=$1", + 1, NULL); /* Used in #postgres_insert_refresh_commit_coins() to store coin commitments. */ PREPARE ("insert_refresh_commit_coin", "INSERT INTO refresh_commit_coin " "(session_hash" - ",cnc_index" ",newcoin_index" ",coin_ev" ") VALUES " - "($1, $2, $3, $4);", - 4, NULL); + "($1, $2, $3);", + 3, NULL); /* Used in #postgres_get_refresh_commit_coins() to retrieve the original coin envelopes, to either be @@ -864,8 +857,8 @@ postgres_prepare (PGconn *db_conn) "SELECT" " coin_ev" " FROM refresh_commit_coin" - " WHERE session_hash=$1 AND cnc_index=$2 AND newcoin_index=$3", - 3, NULL); + " WHERE session_hash=$1 AND newcoin_index=$2", + 2, NULL); /* Store information about a /deposit the exchange is to execute. Used in #postgres_insert_deposit(). */ @@ -1081,8 +1074,7 @@ postgres_prepare (PGconn *db_conn) " JOIN refresh_out rc USING (session_hash)" " WHERE ro.session_hash=$1" " AND ro.newcoin_index=rcc.newcoin_index" - " AND ro.newcoin_index=rc.newcoin_index" - " AND rcc.cnc_index=rs.noreveal_index", + " AND ro.newcoin_index=rc.newcoin_index", 1, NULL); /* Used in #postgres_get_transfer(). Given the public key of a @@ -1096,8 +1088,7 @@ postgres_prepare (PGconn *db_conn) "SELECT transfer_pub,session_hash" " FROM refresh_sessions rs" " JOIN refresh_transfer_public_key rcl USING (session_hash)" - " WHERE rs.old_coin_pub=$1" - " AND rcl.cnc_index=rs.noreveal_index", + " WHERE rs.old_coin_pub=$1", 1, NULL); /* Used in #postgres_lookup_wire_transfer */ @@ -3045,7 +3036,6 @@ postgres_get_refresh_order (void *cls, * @param cls the `struct PostgresClosure` with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index (1st dimension) * @param num_newcoins coin index size of the @a commit_coins array * @param commit_coins array of coin commitments to store * @return #GNUNET_OK on success @@ -3055,7 +3045,6 @@ static int postgres_insert_refresh_commit_coins (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, uint16_t num_newcoins, const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins) { @@ -3069,7 +3058,6 @@ postgres_insert_refresh_commit_coins (void *cls, { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (session_hash), - GNUNET_PQ_query_param_uint16 (&cnc_index), GNUNET_PQ_query_param_uint16 (&coin_off), GNUNET_PQ_query_param_fixed_size (commit_coins[i].coin_ev, commit_coins[i].coin_ev_size), @@ -3128,7 +3116,6 @@ postgres_free_refresh_commit_coins (void *cls, * @param cls the `struct PostgresClosure` with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index set index (1st dimension) * @param num_newcoins size of the @a commit_coins array * @param[out] commit_coins array of coin commitments to return * @return #GNUNET_OK on success @@ -3139,7 +3126,6 @@ static int postgres_get_refresh_commit_coins (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, uint16_t num_newcoins, struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins) { @@ -3150,7 +3136,6 @@ postgres_get_refresh_commit_coins (void *cls, uint16_t newcoin_off = (uint16_t) i; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (session_hash), - GNUNET_PQ_query_param_uint16 (&cnc_index), GNUNET_PQ_query_param_uint16 (&newcoin_off), GNUNET_PQ_query_param_end }; @@ -3205,7 +3190,6 @@ postgres_get_refresh_commit_coins (void *cls, * @param cls the `struct PostgresClosure` with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index (1st dimension) * @param tp transfer public key to store * @return #GNUNET_SYSERR on internal error, #GNUNET_OK on success */ @@ -3213,13 +3197,11 @@ static int postgres_insert_refresh_transfer_public_key (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, const struct TALER_TransferPublicKeyP *tp) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (session_hash), GNUNET_PQ_query_param_auto_from_type (tp), - GNUNET_PQ_query_param_uint16 (&cnc_index), GNUNET_PQ_query_param_end }; @@ -3252,7 +3234,6 @@ postgres_insert_refresh_transfer_public_key (void *cls, * @param cls the `struct PostgresClosure` with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index (1st dimension) * @param[out] tp information to return * @return #GNUNET_SYSERR on internal error, * #GNUNET_NO if commitment was not found @@ -3262,12 +3243,10 @@ static int postgres_get_refresh_transfer_public_key (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, struct TALER_TransferPublicKeyP *tp) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (session_hash), - GNUNET_PQ_query_param_uint16 (&cnc_index), GNUNET_PQ_query_param_end }; PGresult *result; @@ -3306,83 +3285,6 @@ postgres_get_refresh_transfer_public_key (void *cls, /** - * Get all of the information from the given melt commit operation. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param session database connection to use - * @param session_hash hash to identify refresh session - * @return NULL if the @a session_hash does not correspond to any known melt - * operation - */ -static struct TALER_EXCHANGEDB_MeltCommitment * -postgres_get_melt_commitment (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct GNUNET_HashCode *session_hash) -{ - struct TALER_EXCHANGEDB_RefreshSession rs; - struct TALER_EXCHANGEDB_MeltCommitment *mc; - uint16_t cnc_index; - - if (GNUNET_OK != - postgres_get_refresh_session (cls, - session, - session_hash, - &rs)) - return NULL; - /* we don't care about most of 'rs' */ - GNUNET_CRYPTO_rsa_public_key_free (rs.melt.coin.denom_pub.rsa_public_key); - GNUNET_CRYPTO_rsa_signature_free (rs.melt.coin.denom_sig.rsa_signature); - mc = GNUNET_new (struct TALER_EXCHANGEDB_MeltCommitment); - mc->num_newcoins = rs.num_newcoins; - mc->denom_pubs = GNUNET_new_array (mc->num_newcoins, - struct TALER_DenominationPublicKey); - if (GNUNET_OK != - postgres_get_refresh_order (cls, - session, - session_hash, - mc->num_newcoins, - mc->denom_pubs)) - { - GNUNET_break (0); - goto cleanup; - } - for (cnc_index=0;cnc_index<TALER_CNC_KAPPA;cnc_index++) - { - mc->commit_coins[cnc_index] - = GNUNET_new_array (mc->num_newcoins, - struct TALER_EXCHANGEDB_RefreshCommitCoin); - if (GNUNET_OK != - postgres_get_refresh_commit_coins (cls, - session, - session_hash, - cnc_index, - mc->num_newcoins, - mc->commit_coins[cnc_index])) - { - GNUNET_break (0); - goto cleanup; - } - if (GNUNET_OK != - postgres_get_refresh_transfer_public_key (cls, - session, - session_hash, - cnc_index, - &mc->transfer_pubs[cnc_index])) - { - GNUNET_break (0); - goto cleanup; - } - } - return mc; - - cleanup: - common_free_melt_commitment (cls, mc); - GNUNET_break (0); - return NULL; -} - - -/** * Insert signature of a new coin generated during refresh into * the database indexed by the refresh session and the index * of the coin. This data is later used should an old coin @@ -4410,8 +4312,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->free_refresh_commit_coins = &postgres_free_refresh_commit_coins; plugin->insert_refresh_transfer_public_key = &postgres_insert_refresh_transfer_public_key; plugin->get_refresh_transfer_public_key = &postgres_get_refresh_transfer_public_key; - plugin->get_melt_commitment = &postgres_get_melt_commitment; - plugin->free_melt_commitment = &common_free_melt_commitment; plugin->insert_refresh_out = &postgres_insert_refresh_out; plugin->get_link_data_list = &postgres_get_link_data_list; plugin->free_link_data_list = &common_free_link_data_list; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index a053c87f4..828659ba3 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -298,28 +298,6 @@ static struct TALER_Amount amount_with_fee; /** - * Compare two coin commitments. - * - * @param rc1 first commitment - * @param rc2 second commitment - * @return 0 if they are equal - */ -static int -commit_coin_cmp (struct TALER_EXCHANGEDB_RefreshCommitCoin *rc1, - struct TALER_EXCHANGEDB_RefreshCommitCoin *rc2) -{ - FAILIF (rc1->coin_ev_size != rc2->coin_ev_size); - FAILIF (0 != memcmp (rc1->coin_ev, - rc2->coin_ev, - rc2->coin_ev_size)); - return 0; - drop: - GNUNET_break (0); - return 1; -} - - -/** * Number of newly minted coins to use in the test. */ #define MELT_NEW_COINS 5 @@ -330,7 +308,7 @@ commit_coin_cmp (struct TALER_EXCHANGEDB_RefreshCommitCoin *rc1, #define MELT_NOREVEAL_INDEX 1 -static struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins[TALER_CNC_KAPPA]; +static struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins; /** * Test APIs related to the "insert_refresh_commit_coins" function. @@ -349,61 +327,54 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_RefreshCommitCoin *a_ccoin; struct TALER_EXCHANGEDB_RefreshCommitCoin *b_ccoin; unsigned int cnt; - uint16_t cnc_index; int ret; #define COIN_ENC_MAX_SIZE 512 ret = GNUNET_SYSERR; ret_commit_coins = NULL; - for (cnc_index=0;cnc_index < TALER_CNC_KAPPA; cnc_index++) + commit_coins + = GNUNET_new_array (MELT_NEW_COINS, + struct TALER_EXCHANGEDB_RefreshCommitCoin); + for (cnt=0; cnt < MELT_NEW_COINS; cnt++) { - commit_coins[cnc_index] - = GNUNET_new_array (MELT_NEW_COINS, - struct TALER_EXCHANGEDB_RefreshCommitCoin); - for (cnt=0; cnt < MELT_NEW_COINS; cnt++) - { - struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin; - - ccoin = &commit_coins[cnc_index][cnt]; - ccoin->coin_ev_size = GNUNET_CRYPTO_random_u64 - (GNUNET_CRYPTO_QUALITY_WEAK, COIN_ENC_MAX_SIZE); - ccoin->coin_ev = GNUNET_malloc (ccoin->coin_ev_size); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - ccoin->coin_ev, - ccoin->coin_ev_size); - } - FAILIF (GNUNET_OK != - plugin->insert_refresh_commit_coins (plugin->cls, - session, - session_hash, - cnc_index, - MELT_NEW_COINS, - commit_coins[cnc_index])); - ret_commit_coins = GNUNET_new_array (MELT_NEW_COINS, - struct TALER_EXCHANGEDB_RefreshCommitCoin); - FAILIF (GNUNET_OK != - plugin->get_refresh_commit_coins (plugin->cls, - session, - session_hash, - cnc_index, - MELT_NEW_COINS, - ret_commit_coins)); - /* compare the refresh commit coin arrays */ - for (cnt = 0; cnt < MELT_NEW_COINS; cnt++) - { - a_ccoin = &commit_coins[cnc_index][cnt]; - b_ccoin = &ret_commit_coins[cnt]; - FAILIF (a_ccoin->coin_ev_size != b_ccoin->coin_ev_size); - FAILIF (0 != memcmp (a_ccoin->coin_ev, - a_ccoin->coin_ev, - a_ccoin->coin_ev_size)); - GNUNET_free (ret_commit_coins[cnt].coin_ev); - } - GNUNET_free (ret_commit_coins); - ret_commit_coins = NULL; + struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin; + + ccoin = &commit_coins[cnt]; + ccoin->coin_ev_size = GNUNET_CRYPTO_random_u64 + (GNUNET_CRYPTO_QUALITY_WEAK, COIN_ENC_MAX_SIZE); + ccoin->coin_ev = GNUNET_malloc (ccoin->coin_ev_size); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + ccoin->coin_ev, + ccoin->coin_ev_size); + } + FAILIF (GNUNET_OK != + plugin->insert_refresh_commit_coins (plugin->cls, + session, + session_hash, + MELT_NEW_COINS, + commit_coins)); + ret_commit_coins = GNUNET_new_array (MELT_NEW_COINS, + struct TALER_EXCHANGEDB_RefreshCommitCoin); + FAILIF (GNUNET_OK != + plugin->get_refresh_commit_coins (plugin->cls, + session, + session_hash, + MELT_NEW_COINS, + ret_commit_coins)); + /* compare the refresh commit coin arrays */ + for (cnt = 0; cnt < MELT_NEW_COINS; cnt++) + { + a_ccoin = &commit_coins[cnt]; + b_ccoin = &ret_commit_coins[cnt]; + FAILIF (a_ccoin->coin_ev_size != b_ccoin->coin_ev_size); + FAILIF (0 != memcmp (a_ccoin->coin_ev, + a_ccoin->coin_ev, + a_ccoin->coin_ev_size)); + GNUNET_free (ret_commit_coins[cnt].coin_ev); } + GNUNET_free (ret_commit_coins); + ret_commit_coins = NULL; ret = GNUNET_OK; - drop: if (NULL != ret_commit_coins) { @@ -433,37 +404,31 @@ test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash) { int ret; - unsigned int i; struct TALER_TransferPublicKeyP tp; + unsigned int i; ret = GNUNET_SYSERR; FAILIF (GNUNET_NO != plugin->get_refresh_transfer_public_key (plugin->cls, session, session_hash, - MELT_NOREVEAL_INDEX, &tp)); for (i=0;i<TALER_CNC_KAPPA;i++) - { RND_BLK (&rctp[i]); - FAILIF (GNUNET_OK != - plugin->insert_refresh_transfer_public_key (plugin->cls, - session, - session_hash, - i, - &rctp[i])); - - FAILIF (GNUNET_OK != - plugin->get_refresh_transfer_public_key (plugin->cls, - session, - session_hash, - i, - &tp)); - FAILIF (0 != - memcmp (&rctp[i], - &tp, - sizeof (struct TALER_TransferPublicKeyP))); - } + FAILIF (GNUNET_OK != + plugin->insert_refresh_transfer_public_key (plugin->cls, + session, + session_hash, + &rctp[MELT_NOREVEAL_INDEX])); + FAILIF (GNUNET_OK != + plugin->get_refresh_transfer_public_key (plugin->cls, + session, + session_hash, + &tp)); + FAILIF (0 != + memcmp (&rctp[MELT_NOREVEAL_INDEX], + &tp, + sizeof (struct TALER_TransferPublicKeyP))); ret = GNUNET_OK; drop: return ret; @@ -519,12 +484,10 @@ test_melting (struct TALER_EXCHANGEDB_Session *session) struct TALER_EXCHANGEDB_RefreshMelt *meltp; struct TALER_DenominationPublicKey *new_denom_pubs; struct TALER_DenominationPublicKey *ret_denom_pubs; - struct TALER_EXCHANGEDB_MeltCommitment *mc; struct TALER_EXCHANGEDB_LinkDataList *ldl; struct TALER_EXCHANGEDB_LinkDataList *ldlp; struct TALER_DenominationSignature ev_sigs[MELT_NEW_COINS]; unsigned int cnt; - unsigned int i; int ret; ret = GNUNET_SYSERR; @@ -648,34 +611,6 @@ test_melting (struct TALER_EXCHANGEDB_Session *session) &refresh_session, &session_hash)); - /* checking 'get_melt_commitment' API */ - mc = plugin->get_melt_commitment (plugin->cls, - session, - &session_hash); - FAILIF (NULL == mc); - FAILIF (MELT_NEW_COINS != mc->num_newcoins); - for (cnt=0; cnt < MELT_NEW_COINS; cnt++) - { - FAILIF (0 != - GNUNET_CRYPTO_rsa_public_key_cmp (new_dkp[cnt]->pub.rsa_public_key, - mc->denom_pubs[cnt].rsa_public_key)); - for (i=0;i<TALER_CNC_KAPPA;i++) - { - FAILIF (0 != - commit_coin_cmp (&mc->commit_coins[i][cnt], - &commit_coins[i][cnt])); - } - } - for (i=0;i<TALER_CNC_KAPPA;i++) - { - FAILIF (0 != - memcmp (&rctp[i], - &mc->transfer_pubs[i], - sizeof (struct TALER_TransferPublicKeyP))); - } - plugin->free_melt_commitment (plugin->cls, - mc); - for (cnt=0; cnt < MELT_NEW_COINS; cnt++) { struct GNUNET_HashCode hc; @@ -738,15 +673,14 @@ test_melting (struct TALER_EXCHANGEDB_Session *session) drop: for (cnt=0; cnt < MELT_NEW_COINS; cnt++) GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature); - for (cnt=0;cnt<TALER_CNC_KAPPA;cnt++) - if (NULL != commit_coins[cnt]) - { - plugin->free_refresh_commit_coins (plugin->cls, - MELT_NEW_COINS, - commit_coins[cnt]); - GNUNET_free (commit_coins[cnt]); - commit_coins[cnt] = NULL; - } + if (NULL != commit_coins) + { + plugin->free_refresh_commit_coins (plugin->cls, + MELT_NEW_COINS, + commit_coins); + GNUNET_free (commit_coins); + commit_coins = NULL; + } destroy_denom_key_pair (dkp); GNUNET_CRYPTO_rsa_signature_free (meltp->coin.denom_sig.rsa_signature); for (cnt = 0; diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 0377806f4..32910e960 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -546,34 +546,6 @@ struct TALER_EXCHANGEDB_TransactionList /** - * @brief All of the information from a /refresh/melt commitment. - */ -struct TALER_EXCHANGEDB_MeltCommitment -{ - - /** - * Number of new coins we are creating. - */ - uint16_t num_newcoins; - - /** - * Array of @e num_newcoins denomination keys - */ - struct TALER_DenominationPublicKey *denom_pubs; - - /** - * 2D-Array of #TALER_CNC_KAPPA and @e num_newcoins commitments. - */ - struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins[TALER_CNC_KAPPA]; - - /** - * Array of #TALER_CNC_KAPPA transfer public keys. - */ - struct TALER_TransferPublicKeyP transfer_pubs[TALER_CNC_KAPPA]; -}; - - -/** * @brief Handle for a database session (per-thread, for transactions). */ struct TALER_EXCHANGEDB_Session; @@ -1146,7 +1118,6 @@ struct TALER_EXCHANGEDB_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index (1st dimension), relating to #TALER_CNC_KAPPA * @param num_newcoins coin index size of the @a commit_coins array * @param commit_coin array of coin commitments to store * @return #GNUNET_OK on success @@ -1156,7 +1127,6 @@ struct TALER_EXCHANGEDB_Plugin (*insert_refresh_commit_coins) (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, uint16_t num_newcoins, const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins); @@ -1168,7 +1138,6 @@ struct TALER_EXCHANGEDB_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose set index (1st dimension) * @param num_coins size of the @a commit_coins array * @param[out] commit_coins array of coin commitments to return * @return #GNUNET_OK on success @@ -1179,7 +1148,6 @@ struct TALER_EXCHANGEDB_Plugin (*get_refresh_commit_coins) (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, uint16_t num_coins, struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins); @@ -1203,7 +1171,6 @@ struct TALER_EXCHANGEDB_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index, relating to #TALER_CNC_KAPPA * @param tp public key to store * @return #GNUNET_SYSERR on internal error, #GNUNET_OK on success */ @@ -1211,7 +1178,6 @@ struct TALER_EXCHANGEDB_Plugin (*insert_refresh_transfer_public_key) (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, const struct TALER_TransferPublicKeyP *tp); /** @@ -1221,7 +1187,6 @@ struct TALER_EXCHANGEDB_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param session database connection to use * @param session_hash hash to identify refresh session - * @param cnc_index cut and choose index (1st dimension) * @param[out] tp information to return * @return #GNUNET_SYSERR on internal error, * #GNUNET_NO if commitment was not found @@ -1231,37 +1196,10 @@ struct TALER_EXCHANGEDB_Plugin (*get_refresh_transfer_public_key) (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct GNUNET_HashCode *session_hash, - uint16_t cnc_index, struct TALER_TransferPublicKeyP *tp); /** - * Get all of the information from the given melt commit operation. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param session database connection to use - * @param session_hash hash to identify refresh session - * @return NULL if the @a session_hash does not correspond to any known melt - * operation - */ - struct TALER_EXCHANGEDB_MeltCommitment * - (*get_melt_commitment) (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct GNUNET_HashCode *session_hash); - - - /** - * Free information about a melt commitment. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param mc melt commitment data to free - */ - void - (*free_melt_commitment) (void *cls, - struct TALER_EXCHANGEDB_MeltCommitment *mc); - - - /** * Insert signature of a new coin generated during refresh into * the database indexed by the refresh session and the index * of the coin. This data is later used should an old coin |