test for link data

This commit is contained in:
Joseph 2023-01-30 08:43:38 -05:00
parent a1c0c2fafd
commit 4bb96abc97
No known key found for this signature in database
GPG Key ID: E709789D3076B5CC
4 changed files with 259 additions and 146 deletions

View File

@ -0,0 +1,59 @@
--
-- This file is part of TALER
-- Copyright (C) 2014--2022 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
/*DROP FUNCTION exchange_do_refund_by_coin(
IN in_coin_pub BYTEA,
IN in_merchant_pub BYTEA,
IN in_h_contract BYTEA
);*/
CREATE OR REPLACE FUNCTION exchange_do_get_link_data(
IN in_coin_pub BYTEA
)
RETURNS SETOF record
LANGUAGE plpgsql
AS $$
DECLARE
curs CURSOR
FOR
SELECT
melt_serial_id
FROM refresh_commitments
WHERE old_coin_pub=in_coin_pub;
DECLARE
i RECORD;
BEGIN
OPEN curs;
LOOP
FETCH NEXT FROM curs INTO i;
EXIT WHEN NOT FOUND;
RETURN QUERY
SELECT
tp.transfer_pub
,denoms.denom_pub
,rrc.ev_sig
,rrc.ewv
,rrc.link_sig
,rrc.freshcoin_index
,rrc.coin_ev
FROM refresh_revealed_coins rrc
JOIN refresh_transfer_keys tp
ON (tp.melt_serial_id=rrc.melt_serial_id)
JOIN denominations denoms
ON (rrc.denominations_serial=denoms.denominations_serial)
WHERE rrc.melt_serial_id =i.melt_serial_id;
END LOOP;
CLOSE curs;
END $$;

View File

@ -177,11 +177,35 @@ TEH_PG_get_link_data (void *cls,
}; };
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
struct LinkDataContext ldctx; struct LinkDataContext ldctx;
static int percent_refund = -2;
const char *query;
if (NULL == getenv ("NEW_LOGIC")) if (-2 == percent_refund)
{ {
const char *mode = getenv ("NEW_LOGIC");
char dummy;
if ( (NULL==mode) ||
(1 != sscanf (mode,
"%d%c",
&percent_refund,
&dummy)) )
{
if (NULL != mode)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Bad mode `%s' specified\n",
mode);
}
if (NULL==mode)
percent_refund=0;
}
switch (percent_refund)
{
case 0:
query="get_link";
PREPARE (pg, PREPARE (pg,
"get_link", query,
"SELECT " "SELECT "
" tp.transfer_pub" " tp.transfer_pub"
",denoms.denom_pub" ",denoms.denom_pub"
@ -199,15 +223,15 @@ TEH_PG_get_link_data (void *cls,
" ON (rrc.denominations_serial = denoms.denominations_serial)" " ON (rrc.denominations_serial = denoms.denominations_serial)"
" WHERE old_coin_pub=$1" " WHERE old_coin_pub=$1"
" ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC"); " ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC");
} break;
case 1:
else query="get_link_v1";
{
PREPARE (pg, PREPARE (pg,
"get_link", query,
"WITH rc AS MATERIALIZED (" "WITH rc AS MATERIALIZED ("
"SELECT" "SELECT"
"* FROM refresh_commitments" " melt_serial_id"
" FROM refresh_commitments"
" WHERE old_coin_pub=$1" " WHERE old_coin_pub=$1"
")" ")"
"SELECT " "SELECT "
@ -218,12 +242,36 @@ TEH_PG_get_link_data (void *cls,
",rrc.link_sig" ",rrc.link_sig"
",rrc.freshcoin_index" ",rrc.freshcoin_index"
",rrc.coin_ev " ",rrc.coin_ev "
" FROM refresh_revealed_coins rrc" "FROM "
"refresh_revealed_coins rrc"
" JOIN refresh_transfer_keys tp" " JOIN refresh_transfer_keys tp"
" USING (melt_serial_id)" " USING (melt_serial_id)"
" JOIN denominations denoms" " JOIN denominations denoms"
" USING (denominations_serial)" " USING (denominations_serial)"
" WHERE rrc.melt_serial_id = (SELECT melt_serial_id FROM rc)"
" ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC"); " ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC");
break;
case 2:
query="get_link_v2";
PREPARE (pg,
query,
"SELECT"
" *"
" FROM"
" exchange_do_get_link_data"
" ($1) "
" AS "
" (transfer_pub BYTEA"
" ,denom_pub BYTEA"
" ,ev_sig BYTEA"
" ,ewv BYTEA"
" ,link_sig BYTEA"
" ,freshcoin_index INT4"
" ,coin_ev BYTEA);");
break;
default:
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
} }
ldctx.ldc = ldc; ldctx.ldc = ldc;
@ -231,7 +279,7 @@ TEH_PG_get_link_data (void *cls,
ldctx.last = NULL; ldctx.last = NULL;
ldctx.status = GNUNET_OK; ldctx.status = GNUNET_OK;
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
"get_link", query,
params, params,
&add_ldl, &add_ldl,
&ldctx); &ldctx);

View File

@ -46,5 +46,6 @@ SET search_path TO exchange;
#include "exchange_do_batch8_reserves_in_insert.sql" #include "exchange_do_batch8_reserves_in_insert.sql"
#include "exchange_do_refund_by_coin.sql" #include "exchange_do_refund_by_coin.sql"
#include "exchange_do_get_ready_deposit.sql" #include "exchange_do_get_ready_deposit.sql"
#include "exchange_do_get_link_data.sql"
COMMIT; COMMIT;

View File

@ -49,9 +49,10 @@
#define CURRENCY "EUR" #define CURRENCY "EUR"
#define RSA_KEY_SIZE 1024 #define RSA_KEY_SIZE 1024
#define ROUNDS 10 #define ROUNDS 2
#define NUM_ROWS 1000 #define NUM_ROWS 10
#define MELT_NEW_COINS 5 #define MELT_NEW_COINS 5
#define DENOMINATIONS 5
#define MELT_NOREVEAL_INDEX 1 #define MELT_NOREVEAL_INDEX 1
/** /**
* Database plugin under test. * Database plugin under test.
@ -63,7 +64,7 @@ static struct TALER_DenomFeeSet fees;
*/ */
static struct DenomKeyPair **new_dkp; static struct DenomKeyPair **new_dkp;
static int result; static int result;
static struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coins;
static struct TALER_TransferPrivateKeyP tprivs[TALER_CNC_KAPPA]; static struct TALER_TransferPrivateKeyP tprivs[TALER_CNC_KAPPA];
static struct TALER_TransferPublicKeyP tpub; static struct TALER_TransferPublicKeyP tpub;
struct DenomKeyPair struct DenomKeyPair
@ -165,7 +166,6 @@ create_denom_key_pair (unsigned int size,
} }
return dkp; return dkp;
} }
/** /**
* Function called with the session hashes and transfer secret * Function called with the session hashes and transfer secret
* information for a given coin. * information for a given coin.
@ -181,29 +181,9 @@ handle_link_data_cb (void *cls,
{ {
(void) cls; (void) cls;
(void) transfer_pub; (void) transfer_pub;
for (const struct TALER_EXCHANGEDB_LinkList *ldlp = ldl; (void) ldl;
NULL != ldlp; }
ldlp = ldlp->next)
{
bool found;
found = false;
for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
{
if ( (0 ==
TALER_denom_pub_cmp (&ldlp->denom_pub,
&new_dkp[cnt]->pub)) &&
(0 ==
TALER_blinded_denom_sig_cmp (&ldlp->ev_sig,
&revealed_coins[cnt].coin_sig)) )
{
found = true;
break;
}
}
GNUNET_assert (GNUNET_NO != found);
}
}
/** /**
* Main function that will be run by the scheduler. * Main function that will be run by the scheduler.
@ -221,13 +201,11 @@ run (void *cls)
struct DenomKeyPair *dkp = NULL; struct DenomKeyPair *dkp = NULL;
struct TALER_EXCHANGEDB_Deposit *depos=NULL; struct TALER_EXCHANGEDB_Deposit *depos=NULL;
struct TALER_Amount value; struct TALER_Amount value;
struct TALER_DenominationPublicKey *new_denom_pubs = NULL;
struct GNUNET_TIME_Relative times = GNUNET_TIME_UNIT_ZERO; struct GNUNET_TIME_Relative times = GNUNET_TIME_UNIT_ZERO;
unsigned long long sqrs=0; unsigned long long sqrs=0;
struct TALER_EXCHANGEDB_Refund *ref=NULL; struct TALER_EXCHANGEDB_Refund *ref=NULL;
unsigned int *perm; unsigned int *perm;
unsigned long long duration_sq; unsigned long long duration_sq;
struct TALER_EXCHANGEDB_RefreshRevealedCoin *ccoin;
struct TALER_ExchangeWithdrawValues alg_values = { struct TALER_ExchangeWithdrawValues alg_values = {
.cipher = TALER_DENOMINATION_RSA .cipher = TALER_DENOMINATION_RSA
}; };
@ -283,49 +261,16 @@ run (void *cls)
//PAIR KEY LIST //PAIR KEY LIST
new_dkp = GNUNET_new_array (MELT_NEW_COINS, new_dkp = GNUNET_new_array (MELT_NEW_COINS,
struct DenomKeyPair *); struct DenomKeyPair *);
//PUBLIC KEY LIST
new_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_DenominationPublicKey);
//REFRESH REVEAL COIN LIST
revealed_coins
= GNUNET_new_array (MELT_NEW_COINS,
struct TALER_EXCHANGEDB_RefreshRevealedCoin);
for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++) for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
{ {
struct GNUNET_TIME_Timestamp now; struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
struct TALER_BlindedRsaPlanchet *rp;
struct TALER_BlindedPlanchet *bp;
now = GNUNET_TIME_timestamp_get ();
//5 KEY PAIR
new_dkp[cnt] = create_denom_key_pair (RSA_KEY_SIZE, new_dkp[cnt] = create_denom_key_pair (RSA_KEY_SIZE,
now, now,
&value, &value,
&fees); &fees);
GNUNET_assert (NULL != new_dkp[cnt]); GNUNET_assert (NULL != new_dkp[cnt]);
new_denom_pubs[cnt] = new_dkp[cnt]->pub;
ccoin = &revealed_coins[cnt];
bp = &ccoin->blinded_planchet;
bp->cipher = TALER_DENOMINATION_RSA;
rp = &bp->details.rsa_blinded_planchet;
rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
GNUNET_CRYPTO_QUALITY_WEAK,
(RSA_KEY_SIZE / 8) - 1);
rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
rp->blinded_msg,
rp->blinded_msg_size);
TALER_denom_pub_hash (&new_dkp[cnt]->pub,
&ccoin->h_denom_pub);
ccoin->exchange_vals = alg_values;
TALER_coin_ev_hash (bp,
&ccoin->h_denom_pub,
&ccoin->coin_envelope_hash);
GNUNET_assert (GNUNET_OK ==
TALER_denom_sign_blinded (&ccoin->coin_sig,
&new_dkp[cnt]->priv,
true,
bp));
} }
} }
perm = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_NONCE, perm = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_NONCE,
@ -337,32 +282,73 @@ run (void *cls)
for (unsigned int j = 0; j < NUM_ROWS; j++) for (unsigned int j = 0; j < NUM_ROWS; j++)
{ {
union TALER_DenominationBlindingKeyP bks; union TALER_DenominationBlindingKeyP bks;
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_CoinPubHashP c_hash; struct TALER_CoinPubHashP c_hash;
unsigned int k = (unsigned int)rand()%5;
unsigned int i = perm[j]; unsigned int i = perm[j];
uint64_t known_coin_id;
struct TALER_EXCHANGEDB_CollectableBlindcoin cbc;
if (i >= ROUNDS) if (i >= ROUNDS)
i = ROUNDS; /* throw-away slot, do not keep around */ i = ROUNDS; /* throw-away slot, do not keep around */
RND_BLK (&coin_pub);
RND_BLK (&c_hash);
RND_BLK (&depos[i].coin.coin_pub); RND_BLK (&depos[i].coin.coin_pub);
TALER_denom_pub_hash (&new_dkp[k]->pub, ZR_BLK (&cbc);
TALER_denom_pub_hash (&new_dkp[(unsigned int)rand()%MELT_NEW_COINS]->pub,
&depos[i].coin.denom_pub_hash); &depos[i].coin.denom_pub_hash);
{
struct TALER_EXCHANGEDB_RefreshRevealedCoin revealed_coins[MELT_NEW_COINS];
for (unsigned int p=0;p<MELT_NEW_COINS;p++)
{
struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coin = &revealed_coins[p];
struct TALER_BlindedPlanchet *bp = &revealed_coin->blinded_planchet;
struct TALER_BlindedRsaPlanchet *rp = &bp->details.rsa_blinded_planchet;
/* h_coin_ev must be unique, but we only have MELT_NEW_COINS created
above for NUM_ROWS iterations; instead of making "all new" coins,
we simply randomize the hash here as nobody is checking for consistency
anyway ;-) */
bp->cipher = TALER_DENOMINATION_RSA;
rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
GNUNET_CRYPTO_QUALITY_WEAK,
(RSA_KEY_SIZE / 8) - 1);
rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
rp->blinded_msg,
rp->blinded_msg_size);
TALER_denom_pub_hash (&new_dkp[(unsigned int)rand()%MELT_NEW_COINS]->pub,
&revealed_coin->h_denom_pub);
revealed_coin->exchange_vals = alg_values;
TALER_coin_ev_hash (bp,
&revealed_coin->h_denom_pub,
&revealed_coin->coin_envelope_hash);
GNUNET_assert (GNUNET_OK ==
TALER_denom_sign_blinded (&revealed_coin->coin_sig,
&new_dkp[(unsigned int)rand()%MELT_NEW_COINS]->priv,
true,
bp));
GNUNET_assert (
GNUNET_OK ==
TALER_denom_sign_blinded (
&cbc.sig,
&new_dkp[(unsigned int)rand()%MELT_NEW_COINS]->priv,
false,
bp));
}
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_denom_sig_unblind (&depos[i].coin.denom_sig, TALER_denom_sig_unblind (&depos[i].coin.denom_sig,
&ccoin->coin_sig, &cbc.sig,
&bks, &bks,
&c_hash, &c_hash,
&alg_values, &alg_values,
&new_dkp[k]->pub)); &new_dkp[(unsigned int)rand()%MELT_NEW_COINS]->pub));
{ {
/* ENSURE_COIN_KNOWN */ /* ENSURE_COIN_KNOWN */
uint64_t known_coin_id;
struct TALER_DenominationHashP dph; struct TALER_DenominationHashP dph;
struct TALER_AgeCommitmentHash agh; struct TALER_AgeCommitmentHash agh;
bool zombie_required = false; bool zombie_required = false;
bool balance_ok; bool balance_ok;
FAILIF (TALER_EXCHANGEDB_CKS_ADDED != FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
plugin->ensure_coin_known (plugin->cls, plugin->ensure_coin_known (plugin->cls,
&depos[i].coin, &depos[i].coin,
@ -382,13 +368,23 @@ run (void *cls)
known_coin_id, known_coin_id,
&zombie_required, &zombie_required,
&balance_ok)); &balance_ok));
FAILIF (! balance_ok); }
FAILIF (zombie_required); /****GET melt_serial_id generated by default****/
{
struct TALER_EXCHANGEDB_Melt ret_refresh_session;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_melt (plugin->cls,
&refresh[i].rc,
&ret_refresh_session,
&melt_serial_id));
} }
/**** INSERT REFRESH_REVEAL + TRANSFER_KEYS *****/ /**** INSERT REFRESH_REVEAL + TRANSFER_KEYS *****/
{
static unsigned int cnt;
RND_BLK (&tprivs); RND_BLK (&tprivs);
RND_BLK (&tpub); RND_BLK (&tpub);
RND_BLK(&melt_serial_id);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_refresh_reveal (plugin->cls, plugin->insert_refresh_reveal (plugin->cls,
melt_serial_id, melt_serial_id,
@ -397,6 +393,26 @@ run (void *cls)
TALER_CNC_KAPPA - 1, TALER_CNC_KAPPA - 1,
tprivs, tprivs,
&tpub)); &tpub));
cnt++;
// fprintf (stderr, "CNT: %u - %llu\n", cnt, (unsigned long long) melt_serial_id);
}
for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
{
TALER_blinded_denom_sig_free (&revealed_coins[cnt].coin_sig);
TALER_blinded_planchet_free (&revealed_coins[cnt].blinded_planchet);
}
{
struct TALER_CoinSpendPublicKeyP ocp;
uint64_t rrc_serial;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_old_coin_by_h_blind (plugin->cls,
&revealed_coins[0].coin_envelope_hash,
&ocp,
&rrc_serial));
}
}
if (ROUNDS == i) if (ROUNDS == i)
TALER_denom_sig_free (&depos[i].coin.denom_sig); TALER_denom_sig_free (&depos[i].coin.denom_sig);
} }
@ -412,6 +428,7 @@ run (void *cls)
struct GNUNET_TIME_Relative duration; struct GNUNET_TIME_Relative duration;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
time = GNUNET_TIME_absolute_get(); time = GNUNET_TIME_absolute_get();
qs = plugin->get_link_data (plugin->cls, qs = plugin->get_link_data (plugin->cls,
&refresh[r].coin.coin_pub, &refresh[r].coin.coin_pub,
&handle_link_data_cb, &handle_link_data_cb,
@ -444,22 +461,10 @@ run (void *cls)
} }
result = 0; result = 0;
drop: drop:
GNUNET_break (GNUNET_OK == // GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls));
plugin->drop_tables (plugin->cls));
cleanup: cleanup:
if (NULL != dkp) if (NULL != dkp)
destroy_denom_key_pair (dkp); destroy_denom_key_pair (dkp);
if (NULL != revealed_coins)
{
for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
{
TALER_blinded_denom_sig_free (&revealed_coins[cnt].coin_sig);
TALER_blinded_planchet_free (&revealed_coins[cnt].blinded_planchet);
}
GNUNET_free (revealed_coins);
revealed_coins = NULL;
}
GNUNET_free (new_denom_pubs);
for (unsigned int cnt = 0; for (unsigned int cnt = 0;
(NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]); (NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]);
cnt++) cnt++)