more work on #4401

This commit is contained in:
Christian Grothoff 2016-05-19 17:11:35 +02:00
parent f2b20f3ad0
commit 9dab61c91a
2 changed files with 155 additions and 45 deletions

View File

@ -2755,8 +2755,8 @@ postgres_get_refresh_session (void *cls,
}; };
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_session", "get_refresh_session",
params); params);
if (PGRES_TUPLES_OK != PQresultStatus (result)) if (PGRES_TUPLES_OK != PQresultStatus (result))
{ {
BREAK_DB_ERR (result); BREAK_DB_ERR (result);
@ -2782,15 +2782,20 @@ postgres_get_refresh_session (void *cls,
{ {
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint16 ("num_newcoins", GNUNET_PQ_result_spec_uint16 ("num_newcoins",
&refresh_session->num_newcoins), &refresh_session->num_newcoins),
GNUNET_PQ_result_spec_uint16 ("noreveal_index", GNUNET_PQ_result_spec_uint16 ("noreveal_index",
&refresh_session->noreveal_index), &refresh_session->noreveal_index),
GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub", &refresh_session->melt.coin.coin_pub), GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig", &refresh_session->melt.coin_sig), &refresh_session->melt.coin.coin_pub),
TALER_PQ_result_spec_amount ("amount_with_fee", &refresh_session->melt.amount_with_fee), GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
TALER_PQ_result_spec_amount ("melt_fee", &refresh_session->melt.melt_fee), &refresh_session->melt.coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
&refresh_session->melt.amount_with_fee),
TALER_PQ_result_spec_amount ("melt_fee",
&refresh_session->melt.melt_fee),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PQ_extract_result (result, rs, 0)) GNUNET_PQ_extract_result (result, rs, 0))
{ {
@ -3429,8 +3434,8 @@ postgres_insert_refresh_out (void *cls,
}; };
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_out", "insert_refresh_out",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result)) if (PGRES_COMMAND_OK != PQresultStatus (result))
{ {
BREAK_DB_ERR (result); BREAK_DB_ERR (result);
@ -3469,7 +3474,6 @@ postgres_get_link_data_list (void *cls,
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"get_link", "get_link",
params); params);
ldl = NULL; ldl = NULL;
if (PGRES_TUPLES_OK != PQresultStatus (result)) if (PGRES_TUPLES_OK != PQresultStatus (result))
{ {
@ -3493,12 +3497,12 @@ postgres_get_link_data_list (void *cls,
size_t ld_buf_size; size_t ld_buf_size;
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_variable_size ("link_vector_enc", GNUNET_PQ_result_spec_variable_size ("link_vector_enc",
&ld_buf, &ld_buf,
&ld_buf_size), &ld_buf_size),
GNUNET_PQ_result_spec_rsa_signature ("ev_sig", GNUNET_PQ_result_spec_rsa_signature ("ev_sig",
&sig), &sig),
GNUNET_PQ_result_spec_rsa_public_key ("denom_pub", GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pub), &denom_pub),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };

View File

@ -318,11 +318,62 @@ free_refresh_commit_coins_array (struct TALER_EXCHANGEDB_RefreshCommitCoin *comm
} }
/**
* Compare two coin encrypted refresh links.
*
* @param rc1 first commitment
* @param rc2 second commitment
* @return 0 if they are equal
*/
static int
refresh_link_encrypted_cmp (struct TALER_RefreshLinkEncrypted *rl1,
struct TALER_RefreshLinkEncrypted *rl2)
{
if ( (rl1->blinding_key_enc_size == rl2->blinding_key_enc_size) &&
(0 ==
memcmp (rl1->coin_priv_enc,
rl2->coin_priv_enc,
sizeof (struct TALER_CoinSpendPrivateKeyP))) &&
(0 ==
memcmp (rl1->blinding_key_enc,
rl2->blinding_key_enc,
rl1->blinding_key_enc_size)) )
return 0;
return 1;
}
/**
* 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));
FAILIF (0 !=
refresh_link_encrypted_cmp (rc1->refresh_link,
rc2->refresh_link));
return 0;
drop:
return 1;
}
/** /**
* Number of newly minted coins to use in the test. * Number of newly minted coins to use in the test.
*/ */
#define MELT_NEW_COINS 5 #define MELT_NEW_COINS 5
static struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins[TALER_CNC_KAPPA];
/** /**
* Test APIs related to the "insert_refresh_commit_coins" function. * Test APIs related to the "insert_refresh_commit_coins" function.
* *
@ -336,7 +387,6 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_RefreshSession *refresh_session, const struct TALER_EXCHANGEDB_RefreshSession *refresh_session,
const struct GNUNET_HashCode *session_hash) const struct GNUNET_HashCode *session_hash)
{ {
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins;
struct TALER_EXCHANGEDB_RefreshCommitCoin *ret_commit_coins; struct TALER_EXCHANGEDB_RefreshCommitCoin *ret_commit_coins;
struct TALER_EXCHANGEDB_RefreshCommitCoin *a_ccoin; struct TALER_EXCHANGEDB_RefreshCommitCoin *a_ccoin;
struct TALER_RefreshLinkEncrypted *a_rlink; struct TALER_RefreshLinkEncrypted *a_rlink;
@ -350,15 +400,17 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
#define COIN_ENC_MAX_SIZE 512 #define COIN_ENC_MAX_SIZE 512
ret = GNUNET_SYSERR; ret = GNUNET_SYSERR;
ret_commit_coins = NULL; ret_commit_coins = NULL;
commit_coins = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_EXCHANGEDB_RefreshCommitCoin);
for (cnc_index=0;cnc_index < TALER_CNC_KAPPA; cnc_index++) for (cnc_index=0;cnc_index < TALER_CNC_KAPPA; cnc_index++)
{ {
commit_coins[cnc_index]
= GNUNET_new_array (MELT_NEW_COINS,
struct TALER_EXCHANGEDB_RefreshCommitCoin);
for (cnt=0; cnt < MELT_NEW_COINS; cnt++) for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
{ {
struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin; struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin;
struct TALER_RefreshLinkEncrypted *rlink; struct TALER_RefreshLinkEncrypted *rlink;
ccoin = &commit_coins[cnt];
ccoin = &commit_coins[cnc_index][cnt];
size = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, size = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
COIN_ENC_MAX_SIZE); COIN_ENC_MAX_SIZE);
rlink = GNUNET_malloc (sizeof (struct TALER_RefreshLinkEncrypted) + size); rlink = GNUNET_malloc (sizeof (struct TALER_RefreshLinkEncrypted) + size);
@ -382,7 +434,7 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
session_hash, session_hash,
cnc_index, cnc_index,
MELT_NEW_COINS, MELT_NEW_COINS,
commit_coins)); commit_coins[cnc_index]));
ret_commit_coins = GNUNET_new_array (MELT_NEW_COINS, ret_commit_coins = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_EXCHANGEDB_RefreshCommitCoin); struct TALER_EXCHANGEDB_RefreshCommitCoin);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
@ -395,7 +447,7 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
/* compare the refresh commit coin arrays */ /* compare the refresh commit coin arrays */
for (cnt = 0; cnt < MELT_NEW_COINS; cnt++) for (cnt = 0; cnt < MELT_NEW_COINS; cnt++)
{ {
a_ccoin = &commit_coins[cnt]; a_ccoin = &commit_coins[cnc_index][cnt];
b_ccoin = &ret_commit_coins[cnt]; b_ccoin = &ret_commit_coins[cnt];
FAILIF (a_ccoin->coin_ev_size != b_ccoin->coin_ev_size); FAILIF (a_ccoin->coin_ev_size != b_ccoin->coin_ev_size);
FAILIF (0 != memcmp (a_ccoin->coin_ev, FAILIF (0 != memcmp (a_ccoin->coin_ev,
@ -417,12 +469,13 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
drop: drop:
if (NULL != ret_commit_coins) if (NULL != ret_commit_coins)
free_refresh_commit_coins_array (ret_commit_coins, MELT_NEW_COINS); free_refresh_commit_coins_array (ret_commit_coins, MELT_NEW_COINS);
if (NULL != commit_coins)
free_refresh_commit_coins_array (commit_coins, MELT_NEW_COINS);
return ret; return ret;
} }
static struct TALER_RefreshCommitLinkP rclp[TALER_CNC_KAPPA];
/** /**
* Test APIs related to the "insert_refresh_commit_coins" function. * Test APIs related to the "insert_refresh_commit_coins" function.
* *
@ -436,7 +489,6 @@ test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_RefreshSession *refresh_session, const struct TALER_EXCHANGEDB_RefreshSession *refresh_session,
const struct GNUNET_HashCode *session_hash) const struct GNUNET_HashCode *session_hash)
{ {
struct TALER_RefreshCommitLinkP cl;
struct TALER_RefreshCommitLinkP cl2; struct TALER_RefreshCommitLinkP cl2;
int ret; int ret;
unsigned int i; unsigned int i;
@ -447,16 +499,16 @@ test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session,
session, session,
session_hash, session_hash,
1, 1,
&cl)); &cl2));
for (i=0;i<TALER_CNC_KAPPA;i++) for (i=0;i<TALER_CNC_KAPPA;i++)
{ {
RND_BLK (&cl); RND_BLK (&rclp[i]);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->insert_refresh_commit_link (plugin->cls, plugin->insert_refresh_commit_link (plugin->cls,
session, session,
session_hash, session_hash,
i, i,
&cl)); &rclp[i]));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->get_refresh_commit_link (plugin->cls, plugin->get_refresh_commit_link (plugin->cls,
@ -465,7 +517,7 @@ test_refresh_commit_links (struct TALER_EXCHANGEDB_Session *session,
i, i,
&cl2)); &cl2));
FAILIF (0 != FAILIF (0 !=
memcmp (&cl, memcmp (&rclp[i],
&cl2, &cl2,
sizeof (struct TALER_RefreshCommitLinkP))); sizeof (struct TALER_RefreshCommitLinkP)));
} }
@ -496,7 +548,9 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
struct TALER_DenominationPublicKey *ret_denom_pubs; struct TALER_DenominationPublicKey *ret_denom_pubs;
struct TALER_EXCHANGEDB_MeltCommitment *mc; struct TALER_EXCHANGEDB_MeltCommitment *mc;
struct TALER_EXCHANGEDB_LinkDataList *ldl; struct TALER_EXCHANGEDB_LinkDataList *ldl;
struct TALER_EXCHANGEDB_LinkDataList *ldlp;
unsigned int cnt; unsigned int cnt;
unsigned int i;
int ret; int ret;
ret = GNUNET_SYSERR; ret = GNUNET_SYSERR;
@ -507,7 +561,7 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
new_denom_pubs = NULL; new_denom_pubs = NULL;
ret_denom_pubs = NULL; ret_denom_pubs = NULL;
/* create and test a refresh session */ /* create and test a refresh session */
refresh_session.num_newcoins = 1; refresh_session.num_newcoins = MELT_NEW_COINS;
refresh_session.noreveal_index = 1; refresh_session.noreveal_index = 1;
/* create a denomination (value: 1; fraction: 100) */ /* create a denomination (value: 1; fraction: 100) */
dkp = create_denom_key_pair (512, dkp = create_denom_key_pair (512,
@ -585,20 +639,22 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
&fee_deposit, &fee_deposit,
&fee_refresh, &fee_refresh,
&fee_refund); &fee_refund);
new_denom_pubs[cnt]=new_dkp[cnt]->pub; new_denom_pubs[cnt] = new_dkp[cnt]->pub;
} }
FAILIF (GNUNET_OK != plugin->insert_refresh_order (plugin->cls, FAILIF (GNUNET_OK !=
session, plugin->insert_refresh_order (plugin->cls,
&session_hash, session,
MELT_NEW_COINS, &session_hash,
new_denom_pubs)); MELT_NEW_COINS,
new_denom_pubs));
ret_denom_pubs = GNUNET_new_array (MELT_NEW_COINS, ret_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_DenominationPublicKey); struct TALER_DenominationPublicKey);
FAILIF (GNUNET_OK != plugin->get_refresh_order (plugin->cls, FAILIF (GNUNET_OK !=
session, plugin->get_refresh_order (plugin->cls,
&session_hash, session,
MELT_NEW_COINS, &session_hash,
ret_denom_pubs)); MELT_NEW_COINS,
ret_denom_pubs));
for (cnt=0; cnt < MELT_NEW_COINS; cnt++) for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
{ {
FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
@ -619,24 +675,74 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
session, session,
&session_hash); &session_hash);
FAILIF (NULL == mc); FAILIF (NULL == mc);
/* FIXME #4401 test: get_melt_commitment: FAILIF (MELT_NEW_COINS != mc->num_newcoins);
check detailed information contained in 'mc' */ 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 (&rclp[i],
&mc->commit_links[i],
sizeof (struct TALER_RefreshCommitLinkP)));
}
plugin->free_melt_commitment (plugin->cls, plugin->free_melt_commitment (plugin->cls,
mc); mc);
/* FIXME #4401: test: insert_refresh_out */
ldl = plugin->get_link_data_list (plugin->cls, ldl = plugin->get_link_data_list (plugin->cls,
session, session,
&session_hash); &session_hash);
FAILIF (NULL != ldl); FAILIF (NULL != ldl); /* this will change once we 'insert_refresh_out()' */
/* FIXME: #4401 check more about ldl */ for (ldlp = ldl; NULL != ldlp; ldlp = ldlp->next)
{
struct TALER_RefreshLinkEncrypted *r1;
struct TALER_RefreshLinkEncrypted *r2;
int found;
for (cnt=0;cnt < MELT_NEW_COINS;cnt++)
{
r1 = commit_coins[1][cnt].refresh_link;
r2 = ldlp->link_data_enc;
found = GNUNET_NO;
FAILIF (NULL == ldlp->ev_sig.rsa_signature);
/* FIXME #4401: check ldlp->ev_sig */
if ( (0 ==
GNUNET_CRYPTO_rsa_public_key_cmp (ldlp->denom_pub.rsa_public_key,
new_dkp[cnt]->pub.rsa_public_key)) &&
(0 ==
refresh_link_encrypted_cmp (r1, r2)) )
{
found = GNUNET_YES;
break;
}
FAILIF (GNUNET_NO == found);
}
}
plugin->free_link_data_list (plugin->cls, plugin->free_link_data_list (plugin->cls,
ldl); ldl);
/* FIXME #4401: test: get_transfer */ /* FIXME #4401: test: get_transfer */
/* FIXME #4401: test: insert_refresh_out */
ret = GNUNET_OK; ret = GNUNET_OK;
drop: drop:
for (cnt=0;cnt<TALER_CNC_KAPPA;cnt++)
if (NULL != commit_coins[cnt])
{
free_refresh_commit_coins_array (commit_coins[cnt],
MELT_NEW_COINS);
commit_coins[cnt] = NULL;
}
if (NULL != dkp) if (NULL != dkp)
destroy_denom_key_pair (dkp); destroy_denom_key_pair (dkp);
GNUNET_CRYPTO_rsa_signature_free (meltp->coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (meltp->coin.denom_sig.rsa_signature);