more work towards fixing #4401

This commit is contained in:
Christian Grothoff 2016-05-19 16:24:29 +02:00
parent 763c8ab512
commit f2b20f3ad0
2 changed files with 110 additions and 145 deletions

View File

@ -3352,20 +3352,23 @@ postgres_get_melt_commitment (void *cls,
return NULL; return NULL;
mc = GNUNET_new (struct TALER_EXCHANGEDB_MeltCommitment); mc = GNUNET_new (struct TALER_EXCHANGEDB_MeltCommitment);
mc->num_newcoins = rs.num_newcoins; mc->num_newcoins = rs.num_newcoins;
mc->denom_pubs = GNUNET_malloc (mc->num_newcoins * mc->denom_pubs = GNUNET_new_array (mc->num_newcoins,
sizeof (struct TALER_DenominationPublicKey)); struct TALER_DenominationPublicKey);
if (GNUNET_OK != if (GNUNET_OK !=
postgres_get_refresh_order (cls, postgres_get_refresh_order (cls,
session, session,
session_hash, session_hash,
mc->num_newcoins, mc->num_newcoins,
mc->denom_pubs)) mc->denom_pubs))
{
GNUNET_break (0);
goto cleanup; goto cleanup;
}
for (cnc_index=0;cnc_index<TALER_CNC_KAPPA;cnc_index++) for (cnc_index=0;cnc_index<TALER_CNC_KAPPA;cnc_index++)
{ {
mc->commit_coins[cnc_index] mc->commit_coins[cnc_index]
= GNUNET_malloc (mc->num_newcoins * = GNUNET_new_array (mc->num_newcoins,
sizeof (struct TALER_EXCHANGEDB_RefreshCommitCoin)); struct TALER_EXCHANGEDB_RefreshCommitCoin);
if (GNUNET_OK != if (GNUNET_OK !=
postgres_get_refresh_commit_coins (cls, postgres_get_refresh_commit_coins (cls,
session, session,
@ -3373,19 +3376,26 @@ postgres_get_melt_commitment (void *cls,
cnc_index, cnc_index,
mc->num_newcoins, mc->num_newcoins,
mc->commit_coins[cnc_index])) mc->commit_coins[cnc_index]))
{
GNUNET_break (0);
goto cleanup; goto cleanup;
}
if (GNUNET_OK != if (GNUNET_OK !=
postgres_get_refresh_commit_link (cls, postgres_get_refresh_commit_link (cls,
session, session,
session_hash, session_hash,
cnc_index, cnc_index,
&mc->commit_links[cnc_index])) &mc->commit_links[cnc_index]))
{
GNUNET_break (0);
goto cleanup; goto cleanup;
} }
}
return mc; return mc;
cleanup: cleanup:
common_free_melt_commitment (cls, mc); common_free_melt_commitment (cls, mc);
GNUNET_break (0);
return NULL; return NULL;
} }

View File

@ -352,8 +352,8 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
ret_commit_coins = NULL; ret_commit_coins = NULL;
commit_coins = GNUNET_new_array (MELT_NEW_COINS, commit_coins = GNUNET_new_array (MELT_NEW_COINS,
struct TALER_EXCHANGEDB_RefreshCommitCoin); struct TALER_EXCHANGEDB_RefreshCommitCoin);
cnc_index = (uint16_t) GNUNET_CRYPTO_random_u32 for (cnc_index=0;cnc_index < TALER_CNC_KAPPA; cnc_index++)
(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_MIN (MELT_NEW_COINS, UINT16_MAX)); {
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;
@ -411,6 +411,7 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
b_rlink->coin_priv_enc, b_rlink->coin_priv_enc,
sizeof (a_rlink->coin_priv_enc))); sizeof (a_rlink->coin_priv_enc)));
} }
}
ret = GNUNET_OK; ret = GNUNET_OK;
drop: drop:
@ -435,93 +436,41 @@ 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_EXCHANGEDB_RefreshCommitCoin cc[2]; struct TALER_RefreshCommitLinkP cl;
struct TALER_EXCHANGEDB_RefreshCommitCoin cx[2]; struct TALER_RefreshCommitLinkP cl2;
struct TALER_RefreshLinkEncrypted *rle;
struct TALER_RefreshLinkEncrypted *rle2;
struct TALER_LinkSecretP secret;
struct TALER_LinkSecretP secret2;
struct TALER_RefreshLinkDecrypted rld;
struct TALER_RefreshLinkDecrypted *rld2;
struct TALER_EXCHANGEDB_LinkDataList *ldl;
int ret; int ret;
unsigned int i;
if (1)
return GNUNET_OK;
ret = GNUNET_SYSERR; ret = GNUNET_SYSERR;
RND_BLK (&secret);
RND_BLK (&rld.coin_priv);
rld.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create (1024);
rle = TALER_refresh_encrypt (&rld,
&secret);
cc[0].refresh_link = rle;
cc[0].coin_ev = "envelope";
cc[0].coin_ev_size = strlen ("envelope");
RND_BLK (&secret2);
rle2 = TALER_refresh_encrypt (&rld,
&secret2);
cc[1].refresh_link = rle2;
cc[1].coin_ev = "another envelope";
cc[1].coin_ev_size = strlen ("another envelope");
FAILIF (GNUNET_NO != FAILIF (GNUNET_NO !=
plugin->get_refresh_commit_coins (plugin->cls, plugin->get_refresh_commit_link (plugin->cls,
session, session,
session_hash, session_hash,
1, 1,
2, &cl));
cx)); for (i=0;i<TALER_CNC_KAPPA;i++)
{
RND_BLK (&cl);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->insert_refresh_commit_coins (plugin->cls, plugin->insert_refresh_commit_link (plugin->cls,
session, session,
session_hash, session_hash,
1, i,
2, &cl));
cc));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->get_refresh_commit_coins (plugin->cls, plugin->get_refresh_commit_link (plugin->cls,
session, session,
session_hash, session_hash,
1, i,
2, &cl2));
cx));
rld2 = TALER_refresh_decrypt (cx[1].refresh_link,
&secret2);
FAILIF (0 != FAILIF (0 !=
GNUNET_CRYPTO_rsa_blinding_key_cmp (rld.blinding_key.rsa_blinding_key, memcmp (&cl,
rld2->blinding_key.rsa_blinding_key)); &cl2,
FAILIF (0 != sizeof (struct TALER_RefreshCommitLinkP)));
memcmp (&rld.coin_priv, }
&rld2->coin_priv,
sizeof (struct TALER_CoinSpendPrivateKeyP)));
GNUNET_free (rld2);
rld2 = TALER_refresh_decrypt (cx[0].refresh_link,
&secret);
FAILIF (0 !=
GNUNET_CRYPTO_rsa_blinding_key_cmp (rld.blinding_key.rsa_blinding_key,
rld2->blinding_key.rsa_blinding_key));
FAILIF (0 !=
memcmp (&rld.coin_priv,
&rld2->coin_priv,
sizeof (struct TALER_CoinSpendPrivateKeyP)));
GNUNET_free (rld2);
ldl = plugin->get_link_data_list (plugin->cls,
session,
session_hash);
FAILIF (NULL != ldl);
/* FIXME: #4401 check more about ldl */
plugin->free_link_data_list (plugin->cls,
ldl);
/*
FIXME #4401: test: get_transfer
*/
ret = GNUNET_OK; ret = GNUNET_OK;
drop: drop:
GNUNET_free (rle);
GNUNET_free (rle2);
GNUNET_CRYPTO_rsa_blinding_key_free (rld.blinding_key.rsa_blinding_key);
return ret; return ret;
} }
@ -546,6 +495,7 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
struct TALER_DenominationPublicKey *new_denom_pubs; struct TALER_DenominationPublicKey *new_denom_pubs;
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;
unsigned int cnt; unsigned int cnt;
int ret; int ret;
@ -668,19 +618,24 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
mc = plugin->get_melt_commitment (plugin->cls, mc = plugin->get_melt_commitment (plugin->cls,
session, session,
&session_hash); &session_hash);
FAILIF (NULL != mc); /* NOTE: this will change once FAILIF (NULL == mc);
'test_refresh_commit_links' is implemented properly */
#if 0
/* FIXME #4401 test: get_melt_commitment: /* FIXME #4401 test: get_melt_commitment:
check detailed information contained in 'mc' */ check detailed information contained in 'mc' */
plugin->free_melt_commitment (plugin->cls, plugin->free_melt_commitment (plugin->cls,
mc); mc);
#endif
ldl = plugin->get_link_data_list (plugin->cls,
session,
&session_hash);
FAILIF (NULL != ldl);
/* FIXME: #4401 check more about ldl */
plugin->free_link_data_list (plugin->cls,
ldl);
/* FIXME #4401: test: get_transfer */
/* FIXME #4401: test: insert_refresh_out */ /* FIXME #4401: test: insert_refresh_out */
ret = GNUNET_OK; ret = GNUNET_OK;
drop: drop:
if (NULL != dkp) if (NULL != dkp)
destroy_denom_key_pair (dkp); destroy_denom_key_pair (dkp);