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

@ -173,73 +173,122 @@ static int
parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh, parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh,
json_t *json) json_t *json)
{ {
json_t *jsona; unsigned int session;
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 ("secret_enc", &secret_enc),
MAJ_spec_end
};
unsigned int num_coins; unsigned int num_coins;
int ret; int ret;
if (GNUNET_OK != if (! json_is_array (json))
MAJ_parse_json (json,
spec))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (! json_is_array (jsona)) num_coins = 0;
for (session=0;session<json_array_size (json); session++)
{ {
GNUNET_break_op (0); json_t *jsona;
MAJ_parse_free (spec); struct MAJ_Specification spec[] = {
return GNUNET_SYSERR; MAJ_spec_json ("new_coins", &jsona),
} MAJ_spec_end
};
/* decode all coins */ if (GNUNET_OK !=
num_coins = json_array_size (json); 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; unsigned int i;
struct TALER_CoinSpendPrivateKeyP coin_privs[num_coins]; struct TALER_CoinSpendPrivateKeyP coin_privs[num_coins];
struct TALER_DenominationSignature sigs[num_coins]; struct TALER_DenominationSignature sigs[num_coins];
struct TALER_DenominationPublicKey pubs[num_coins]; struct TALER_DenominationPublicKey pubs[num_coins];
for (i=0;i<num_coins;i++) 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 ("transfer_pub", &trans_pub),
MAJ_spec_fixed_auto ("secret_enc", &secret_enc),
MAJ_spec_end
};
if (GNUNET_OK != if (GNUNET_OK !=
parse_refresh_link_coin (rlh, MAJ_parse_json (json_array_get (json,
json_array_get (json, i), session),
&trans_pub, spec))
&secret_enc,
&coin_privs[i],
&sigs[i],
&pubs[i]))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
break; return GNUNET_SYSERR;
} }
if (! json_is_array (jsona))
{
GNUNET_break_op (0);
MAJ_parse_free (spec);
return GNUNET_SYSERR;
}
/* decode all coins */
for (i=0;i<json_array_size (jsona);i++)
{
if (GNUNET_OK !=
parse_refresh_link_coin (rlh,
json_array_get (jsona,
i),
&trans_pub,
&secret_enc,
&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 != json_array_size (jsona))
{
GNUNET_break_op (0);
ret = GNUNET_SYSERR;
MAJ_parse_free (spec);
break;
}
off_coin += json_array_size (jsona);
MAJ_parse_free (spec);
} }
if (off_coin == num_coins)
/* check if we really got all, then invoke callback */
if (i != num_coins)
{ {
GNUNET_break_op (0); rlh->link_cb (rlh->link_cb_cls,
ret = GNUNET_SYSERR; MHD_HTTP_OK,
num_coins,
coin_privs,
sigs,
pubs,
json);
rlh->link_cb = NULL;
ret = GNUNET_OK;
} }
else else
{ {
rlh->link_cb (rlh->link_cb_cls, GNUNET_break_op (0);
MHD_HTTP_OK, ret = GNUNET_SYSERR;
num_coins,
coin_privs,
sigs,
pubs,
json);
rlh->link_cb = NULL;
ret = GNUNET_OK;
} }
/* clean up */ /* clean up */

View File

@ -1009,6 +1009,10 @@ link_cb (void *cls,
return; return;
} }
/* check that the coins match */ /* 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++) for (i=0;i<num_coins;i++)
{ {
const struct FreshCoin *fc; const struct FreshCoin *fc;