fix /refresh/link response handling

This commit is contained in:
Christian Grothoff 2015-08-17 03:24:10 +02:00
parent 81af01a209
commit b5a58e516c
2 changed files with 97 additions and 44 deletions

View File

@ -172,21 +172,67 @@ parse_refresh_link_coin (const struct TALER_MINT_RefreshLinkHandle *rlh,
static int
parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh,
json_t *json)
{
unsigned int session;
unsigned int num_coins;
int ret;
if (! json_is_array (json))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
num_coins = 0;
for (session=0;session<json_array_size (json); session++)
{
json_t *jsona;
struct MAJ_Specification spec[] = {
MAJ_spec_json ("new_coins", &jsona),
MAJ_spec_end
};
if (GNUNET_OK !=
MAJ_parse_json (json_array_get (json,
session),
spec))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
if (! json_is_array (jsona))
{
GNUNET_break_op (0);
MAJ_parse_free (spec);
return GNUNET_SYSERR;
}
/* count all coins over all sessions */
num_coins += json_array_size (jsona);
MAJ_parse_free (spec);
}
{
unsigned int off_coin;
unsigned int i;
struct TALER_CoinSpendPrivateKeyP coin_privs[num_coins];
struct TALER_DenominationSignature sigs[num_coins];
struct TALER_DenominationPublicKey pubs[num_coins];
off_coin = 0;
for (session=0;session<json_array_size (json); session++)
{
json_t *jsona;
struct TALER_TransferPublicKeyP trans_pub;
struct TALER_EncryptedLinkSecretP secret_enc;
struct MAJ_Specification spec[] = {
MAJ_spec_json ("new_coins", &jsona),
MAJ_spec_fixed_auto ("trans_pub", &trans_pub),
MAJ_spec_fixed_auto ("transfer_pub", &trans_pub),
MAJ_spec_fixed_auto ("secret_enc", &secret_enc),
MAJ_spec_end
};
unsigned int num_coins;
int ret;
if (GNUNET_OK !=
MAJ_parse_json (json,
MAJ_parse_json (json_array_get (json,
session),
spec))
{
GNUNET_break_op (0);
@ -200,36 +246,34 @@ parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh,
}
/* decode all coins */
num_coins = json_array_size (json);
{
unsigned int i;
struct TALER_CoinSpendPrivateKeyP coin_privs[num_coins];
struct TALER_DenominationSignature sigs[num_coins];
struct TALER_DenominationPublicKey pubs[num_coins];
for (i=0;i<num_coins;i++)
for (i=0;i<json_array_size (jsona);i++)
{
if (GNUNET_OK !=
parse_refresh_link_coin (rlh,
json_array_get (json, i),
json_array_get (jsona,
i),
&trans_pub,
&secret_enc,
&coin_privs[i],
&sigs[i],
&pubs[i]))
&coin_privs[i+off_coin],
&sigs[i+off_coin],
&pubs[i+off_coin]))
{
GNUNET_break_op (0);
break;
}
}
/* check if we really got all, then invoke callback */
if (i != num_coins)
if (i != json_array_size (jsona))
{
GNUNET_break_op (0);
ret = GNUNET_SYSERR;
MAJ_parse_free (spec);
break;
}
else
off_coin += json_array_size (jsona);
MAJ_parse_free (spec);
}
if (off_coin == num_coins)
{
rlh->link_cb (rlh->link_cb_cls,
MHD_HTTP_OK,
@ -241,6 +285,11 @@ parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh,
rlh->link_cb = NULL;
ret = GNUNET_OK;
}
else
{
GNUNET_break_op (0);
ret = GNUNET_SYSERR;
}
/* clean up */
for (i=0;i<num_coins;i++)

View File

@ -1009,6 +1009,10 @@ link_cb (void *cls,
return;
}
/* check that the coins match */
fprintf (stderr,
"Got %u coins\n",
num_coins);
/* FIXME: note: coins might be legitimately permutated in here... */
for (i=0;i<num_coins;i++)
{
const struct FreshCoin *fc;