rename fest

This commit is contained in:
Christian Grothoff 2021-10-27 13:23:14 +02:00
parent 3900531e0d
commit b148a5a81a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
13 changed files with 249 additions and 421 deletions

View File

@ -1639,8 +1639,8 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
dk->meta.expire_deposit), dk->meta.expire_deposit),
GNUNET_JSON_pack_time_abs ("stamp_expire_legal", GNUNET_JSON_pack_time_abs ("stamp_expire_legal",
dk->meta.expire_legal), dk->meta.expire_legal),
TALER_JSON_pack_denomination_public_key ("denom_pub", TALER_JSON_pack_denom_pub ("denom_pub",
&dk->denom_pub), &dk->denom_pub),
TALER_JSON_pack_amount ("value", TALER_JSON_pack_amount ("value",
&dk->meta.value), &dk->meta.value),
TALER_JSON_pack_amount ("fee_withdraw", TALER_JSON_pack_amount ("fee_withdraw",
@ -2430,8 +2430,8 @@ add_future_denomkey_cb (void *cls,
meta.expire_deposit), meta.expire_deposit),
GNUNET_JSON_pack_time_abs ("stamp_expire_legal", GNUNET_JSON_pack_time_abs ("stamp_expire_legal",
meta.expire_legal), meta.expire_legal),
TALER_JSON_pack_denomination_public_key ("denom_pub", TALER_JSON_pack_denom_pub ("denom_pub",
&hd->denom_pub), &hd->denom_pub),
TALER_JSON_pack_amount ("fee_withdraw", TALER_JSON_pack_amount ("fee_withdraw",
&meta.fee_withdraw), &meta.fee_withdraw),
TALER_JSON_pack_amount ("fee_deposit", TALER_JSON_pack_amount ("fee_deposit",

View File

@ -82,10 +82,10 @@ handle_link_data (void *cls,
json_t *obj; json_t *obj;
obj = GNUNET_JSON_PACK ( obj = GNUNET_JSON_PACK (
TALER_JSON_pack_denomination_public_key ("denom_pub", TALER_JSON_pack_denom_pub ("denom_pub",
&pos->denom_pub), &pos->denom_pub),
TALER_JSON_pack_denomination_signature ("ev_sig", TALER_JSON_pack_denom_sig ("ev_sig",
&pos->ev_sig), &pos->ev_sig),
GNUNET_JSON_pack_data_auto ("link_sig", GNUNET_JSON_pack_data_auto ("link_sig",
&pos->orig_coin_link_sig)); &pos->orig_coin_link_sig));
if ( (NULL == obj) || if ( (NULL == obj) ||

View File

@ -68,8 +68,8 @@ reply_refreshes_reveal_success (struct MHD_Connection *connection,
json_t *obj; json_t *obj;
obj = GNUNET_JSON_PACK ( obj = GNUNET_JSON_PACK (
TALER_JSON_pack_denomination_signature ("ev_sig", TALER_JSON_pack_denom_sig ("ev_sig",
&sigs[freshcoin_index])); &sigs[freshcoin_index]));
GNUNET_assert (0 == GNUNET_assert (0 ==
json_array_append_new (list, json_array_append_new (list,
obj)); obj));

View File

@ -607,8 +607,8 @@ TEH_handler_withdraw (struct TEH_RequestContext *rc,
ret = TALER_MHD_REPLY_JSON_PACK ( ret = TALER_MHD_REPLY_JSON_PACK (
rc->connection, rc->connection,
MHD_HTTP_OK, MHD_HTTP_OK,
TALER_JSON_pack_denomination_signature ("ev_sig", TALER_JSON_pack_denom_sig ("ev_sig",
&wc.collectable.sig)); &wc.collectable.sig));
TALER_denom_sig_free (&wc.collectable.sig); TALER_denom_sig_free (&wc.collectable.sig);
return ret; return ret;
} }

View File

@ -1469,22 +1469,20 @@ TALER_EXCHANGE_withdraw2_cancel (struct TALER_EXCHANGE_Withdraw2Handle *wh);
* validity of the keys * validity of the keys
* @param fresh_pks_len length of the @a pks array * @param fresh_pks_len length of the @a pks array
* @param fresh_pks array of @a pks_len denominations of fresh coins to create * @param fresh_pks array of @a pks_len denominations of fresh coins to create
* @param[out] res_size set to the size of the return value, or 0 on error
* @return NULL * @return NULL
* if the inputs are invalid (i.e. denomination key not with this exchange). * if the inputs are invalid (i.e. denomination key not with this exchange).
* Otherwise, pointer to a buffer of @a res_size to store persistently * Otherwise, JSON data structure to store persistently
* before proceeding to #TALER_EXCHANGE_melt(). * before proceeding to #TALER_EXCHANGE_melt().
* Non-null results should be freed using GNUNET_free(). * Non-null results should be freed using GNUNET_free().
*/ */
char * json_t *
TALER_EXCHANGE_refresh_prepare ( TALER_EXCHANGE_refresh_prepare (
const struct TALER_CoinSpendPrivateKeyP *melt_priv, const struct TALER_CoinSpendPrivateKeyP *melt_priv,
const struct TALER_Amount *melt_amount, const struct TALER_Amount *melt_amount,
const struct TALER_DenominationSignature *melt_sig, const struct TALER_DenominationSignature *melt_sig,
const struct TALER_EXCHANGE_DenomPublicKey *melt_pk, const struct TALER_EXCHANGE_DenomPublicKey *melt_pk,
unsigned int fresh_pks_len, unsigned int fresh_pks_len,
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks, const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks);
size_t *res_size);
/* ********************* /coins/$COIN_PUB/melt ***************************** */ /* ********************* /coins/$COIN_PUB/melt ***************************** */
@ -1526,8 +1524,6 @@ typedef void
* prior to calling this function. * prior to calling this function.
* *
* @param exchange the exchange handle; the exchange must be ready to operate * @param exchange the exchange handle; the exchange must be ready to operate
* @param refresh_data_length size of the @a refresh_data (returned
* in the `res_size` argument from #TALER_EXCHANGE_refresh_prepare())
* @param refresh_data the refresh data as returned from * @param refresh_data the refresh data as returned from
#TALER_EXCHANGE_refresh_prepare()) #TALER_EXCHANGE_refresh_prepare())
* @param melt_cb the callback to call with the result * @param melt_cb the callback to call with the result
@ -1537,8 +1533,7 @@ typedef void
*/ */
struct TALER_EXCHANGE_MeltHandle * struct TALER_EXCHANGE_MeltHandle *
TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
size_t refresh_data_length, const json_t *refresh_data,
const char *refresh_data,
TALER_EXCHANGE_MeltCallback melt_cb, TALER_EXCHANGE_MeltCallback melt_cb,
void *melt_cb_cls); void *melt_cb_cls);

View File

@ -139,7 +139,7 @@ TALER_JSON_pack_time_rel_nbo (const char *name,
* @return json pack specification * @return json pack specification
*/ */
struct GNUNET_JSON_PackSpec struct GNUNET_JSON_PackSpec
TALER_JSON_pack_denomination_public_key ( TALER_JSON_pack_denom_pub (
const char *name, const char *name,
const struct TALER_DenominationPublicKey *pk); const struct TALER_DenominationPublicKey *pk);
@ -153,7 +153,7 @@ TALER_JSON_pack_denomination_public_key (
* @return json pack specification * @return json pack specification
*/ */
struct GNUNET_JSON_PackSpec struct GNUNET_JSON_PackSpec
TALER_JSON_pack_denomination_signature ( TALER_JSON_pack_denom_sig (
const char *name, const char *name,
const struct TALER_DenominationSignature *sig); const struct TALER_DenominationSignature *sig);

View File

@ -88,7 +88,7 @@ TALER_JSON_pack_time_rel_nbo (const char *name,
struct GNUNET_JSON_PackSpec struct GNUNET_JSON_PackSpec
TALER_JSON_pack_denomination_public_key ( TALER_JSON_pack_denom_pub (
const char *name, const char *name,
const struct TALER_DenominationPublicKey *pk) const struct TALER_DenominationPublicKey *pk)
{ {
@ -116,7 +116,7 @@ TALER_JSON_pack_denomination_public_key (
struct GNUNET_JSON_PackSpec struct GNUNET_JSON_PackSpec
TALER_JSON_pack_denomination_signature ( TALER_JSON_pack_denom_sig (
const char *name, const char *name,
const struct TALER_DenominationSignature *sig) const struct TALER_DenominationSignature *sig)
{ {

View File

@ -652,8 +652,8 @@ TALER_EXCHANGE_deposit (
h_contract_terms), h_contract_terms),
GNUNET_JSON_pack_data_auto ("denom_pub_hash", GNUNET_JSON_pack_data_auto ("denom_pub_hash",
&denom_pub_hash), &denom_pub_hash),
TALER_JSON_pack_denomination_signature ("ub_sig", TALER_JSON_pack_denom_sig ("ub_sig",
denom_sig), denom_sig),
GNUNET_JSON_pack_time_abs ("timestamp", GNUNET_JSON_pack_time_abs ("timestamp",
timestamp), timestamp),
GNUNET_JSON_pack_data_auto ("merchant_pub", GNUNET_JSON_pack_data_auto ("merchant_pub",

View File

@ -1673,8 +1673,8 @@ TALER_EXCHANGE_serialize_data (struct TALER_EXCHANGE_Handle *exchange)
&dk->fee_refund), &dk->fee_refund),
GNUNET_JSON_pack_data_auto ("master_sig", GNUNET_JSON_pack_data_auto ("master_sig",
&dk->master_sig), &dk->master_sig),
TALER_JSON_pack_denomination_public_key ("denom_pub", TALER_JSON_pack_denom_pub ("denom_pub",
&dk->key)); &dk->key));
GNUNET_assert (0 == GNUNET_assert (0 ==
json_array_append_new (denoms, json_array_append_new (denoms,
denom)); denom));

View File

@ -451,8 +451,7 @@ handle_melt_finished (void *cls,
struct TALER_EXCHANGE_MeltHandle * struct TALER_EXCHANGE_MeltHandle *
TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
size_t refresh_data_length, const json_t *refresh_data,
const char *refresh_data,
TALER_EXCHANGE_MeltCallback melt_cb, TALER_EXCHANGE_MeltCallback melt_cb,
void *melt_cb_cls) void *melt_cb_cls)
{ {
@ -472,8 +471,7 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
TEAH_handle_is_ready (exchange)); TEAH_handle_is_ready (exchange));
md = TALER_EXCHANGE_deserialize_melt_data_ (refresh_data, md = TALER_EXCHANGE_deserialize_melt_data_ (refresh_data);
refresh_data_length);
if (NULL == md) if (NULL == md)
{ {
GNUNET_break (0); GNUNET_break (0);
@ -496,8 +494,8 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
&melt.coin_pub), &melt.coin_pub),
GNUNET_JSON_pack_data_auto ("denom_pub_hash", GNUNET_JSON_pack_data_auto ("denom_pub_hash",
&melt.h_denom_pub), &melt.h_denom_pub),
TALER_JSON_pack_denomination_signature ("denom_sig", TALER_JSON_pack_denom_sig ("denom_sig",
&md->melted_coin.sig), &md->melted_coin.sig),
GNUNET_JSON_pack_data_auto ("confirm_sig", GNUNET_JSON_pack_data_auto ("confirm_sig",
&confirm_sig), &confirm_sig),
TALER_JSON_pack_amount ("value_with_fee", TALER_JSON_pack_amount ("value_with_fee",

View File

@ -334,8 +334,8 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
recoup_obj = GNUNET_JSON_PACK ( recoup_obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("denom_pub_hash", GNUNET_JSON_pack_data_auto ("denom_pub_hash",
&h_denom_pub), &h_denom_pub),
TALER_JSON_pack_denomination_signature ("denom_sig", TALER_JSON_pack_denom_sig ("denom_sig",
denom_sig), denom_sig),
GNUNET_JSON_pack_data_auto ("coin_sig", GNUNET_JSON_pack_data_auto ("coin_sig",
&coin_sig), &coin_sig),
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret", GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",

View File

@ -37,15 +37,6 @@ free_melted_coin (struct MeltedCoin *mc)
} }
/**
* Free all information associated with a melting session. Note
* that we allow the melting session to be only partially initialized,
* as we use this function also when freeing melt data that was not
* fully initialized (i.e. due to failures in #TALER_EXCHANGE_deserialize_melt_data_()).
*
* @param md melting data to release, the pointer itself is NOT
* freed (as it is typically not allocated by itself)
*/
void void
TALER_EXCHANGE_free_melt_data_ (struct MeltData *md) TALER_EXCHANGE_free_melt_data_ (struct MeltData *md)
{ {
@ -56,7 +47,6 @@ TALER_EXCHANGE_free_melt_data_ (struct MeltData *md)
TALER_denom_pub_free (&md->fresh_pks[i]); TALER_denom_pub_free (&md->fresh_pks[i]);
GNUNET_free (md->fresh_pks); GNUNET_free (md->fresh_pks);
} }
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++) for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++)
GNUNET_free (md->fresh_coins[i]); GNUNET_free (md->fresh_coins[i]);
/* Finally, clean up a bit... */ /* Finally, clean up a bit... */
@ -69,63 +59,40 @@ TALER_EXCHANGE_free_melt_data_ (struct MeltData *md)
* Serialize information about a coin we are melting. * Serialize information about a coin we are melting.
* *
* @param mc information to serialize * @param mc information to serialize
* @param buf buffer to write data in, NULL to just compute * @return NULL on error
* required size
* @param off offeset at @a buf to use
* @return number of bytes written to @a buf at @a off, or if
* @a buf is NULL, number of bytes required; 0 on error
*/ */
static size_t static json_t *
serialize_melted_coin (const struct MeltedCoin *mc, serialize_melted_coin (const struct MeltedCoin *mc)
char *buf,
size_t off)
{ {
struct MeltedCoinP mcp; json_t *tprivs;
void *pbuf;
size_t pbuf_size;
void *sbuf;
size_t sbuf_size;
sbuf_size = GNUNET_CRYPTO_rsa_signature_encode (mc->sig.rsa_signature, tprivs = json_array ();
&sbuf); GNUNET_assert (NULL != tprivs);
pbuf_size = GNUNET_CRYPTO_rsa_public_key_encode (mc->pub_key.rsa_public_key,
&pbuf);
if (NULL == buf)
{
GNUNET_free (sbuf);
GNUNET_free (pbuf);
return sizeof (struct MeltedCoinP) + sbuf_size + pbuf_size;
}
if ( (sbuf_size > UINT16_MAX) ||
(pbuf_size > UINT16_MAX) )
{
GNUNET_break (0);
return 0;
}
mcp.coin_priv = mc->coin_priv;
TALER_amount_hton (&mcp.melt_amount_with_fee,
&mc->melt_amount_with_fee);
TALER_amount_hton (&mcp.fee_melt,
&mc->fee_melt);
TALER_amount_hton (&mcp.original_value,
&mc->original_value);
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++) for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++)
mcp.transfer_priv[i] = mc->transfer_priv[i]; GNUNET_assert (0 ==
mcp.expire_deposit = GNUNET_TIME_absolute_hton (mc->expire_deposit); json_array_append_new (
mcp.pbuf_size = htons ((uint16_t) pbuf_size); tprivs,
mcp.sbuf_size = htons ((uint16_t) sbuf_size); GNUNET_JSON_PACK (
memcpy (&buf[off], GNUNET_JSON_pack_data_auto (
&mcp, "transfer_priv",
sizeof (struct MeltedCoinP)); &mc->transfer_priv[i]))));
memcpy (&buf[off + sizeof (struct MeltedCoinP)], return GNUNET_JSON_PACK (
pbuf, GNUNET_JSON_pack_data_auto ("coin_priv",
pbuf_size); &mc->coin_priv),
memcpy (&buf[off + sizeof (struct MeltedCoinP) + pbuf_size], TALER_JSON_pack_denom_sig ("denom_sig",
sbuf, &mc->sig),
sbuf_size); TALER_JSON_pack_denom_pub ("denom_pub",
GNUNET_free (sbuf); &mc->pub_key),
GNUNET_free (pbuf); TALER_JSON_pack_amount ("melt_amount_with_fee",
return sizeof (struct MeltedCoinP) + sbuf_size + pbuf_size; &mc->melt_amount_with_fee),
TALER_JSON_pack_amount ("original_value",
&mc->original_value),
TALER_JSON_pack_amount ("melt_fee",
&mc->fee_melt),
GNUNET_JSON_pack_time_abs ("expire_deposit",
mc->expire_deposit),
GNUNET_JSON_pack_array_steal ("transfer_privs",
tprivs));
} }
@ -133,204 +100,69 @@ serialize_melted_coin (const struct MeltedCoin *mc,
* Deserialize information about a coin we are melting. * Deserialize information about a coin we are melting.
* *
* @param[out] mc information to deserialize * @param[out] mc information to deserialize
* @param buf buffer to read data from * @param in JSON object to read data from
* @param size number of bytes available at @a buf to use * @return #GNUNET_NO to report errors
* @param[out] ok set to #GNUNET_NO to report errors
* @return number of bytes read from @a buf, 0 on error
*/ */
static size_t static enum GNUNET_GenericReturnValue
deserialize_melted_coin (struct MeltedCoin *mc, deserialize_melted_coin (struct MeltedCoin *mc,
const char *buf, const json_t *in)
size_t size,
int *ok)
{ {
struct MeltedCoinP mcp; json_t *trans_privs;
size_t pbuf_size; struct GNUNET_JSON_Specification spec[] = {
size_t sbuf_size; GNUNET_JSON_spec_fixed_auto ("coin_priv",
size_t off; &mc->coin_priv),
TALER_JSON_spec_denom_sig ("denom_sig",
&mc->sig),
TALER_JSON_spec_denom_pub ("denom_pub",
&mc->pub_key),
TALER_JSON_spec_amount ("melt_amount_with_fee",
&mc->melt_amount_with_fee),
TALER_JSON_spec_amount ("original_value",
&mc->original_value),
TALER_JSON_spec_amount ("melt_fee",
&mc->melt_fee),
TALER_JSON_spec_absolute_time ("expire_deposit",
&mc->expire_deposit),
TALER_JSON_spec_json ("transfer_privs",
&trans_privs),
GNUNET_JSON_spec_end ()
};
if (size < sizeof (struct MeltedCoinP)) if (GNUNET_OK !=
GNUNET_JSON_parse (in,
spec,
NULL, NULL))
{ {
GNUNET_break (0); GNUNET_break_op (0);
*ok = GNUNET_NO; return GNUNET_NO;
return 0;
} }
memcpy (&mcp, if (TALER_CNC_KAPPA != json_array_size (trans_privs))
buf,
sizeof (struct MeltedCoinP));
pbuf_size = ntohs (mcp.pbuf_size);
sbuf_size = ntohs (mcp.sbuf_size);
if (size < sizeof (struct MeltedCoinP) + pbuf_size + sbuf_size)
{ {
GNUNET_break (0); GNUNET_JSON_parse_free (spec);
*ok = GNUNET_NO; GNUNET_break_op (0);
return 0; return GNUNET_NO;
} }
off = sizeof (struct MeltedCoinP);
mc->pub_key.rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_decode (&buf[off],
pbuf_size);
off += pbuf_size;
mc->sig.rsa_signature
= GNUNET_CRYPTO_rsa_signature_decode (&buf[off],
sbuf_size);
off += sbuf_size;
if ( (NULL == mc->pub_key.rsa_public_key) ||
(NULL == mc->sig.rsa_signature) )
{
GNUNET_break (0);
*ok = GNUNET_NO;
return 0;
}
mc->coin_priv = mcp.coin_priv;
TALER_amount_ntoh (&mc->melt_amount_with_fee,
&mcp.melt_amount_with_fee);
TALER_amount_ntoh (&mc->fee_melt,
&mcp.fee_melt);
TALER_amount_ntoh (&mc->original_value,
&mcp.original_value);
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++) for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++)
mc->transfer_priv[i] = mcp.transfer_priv[i];
mc->expire_deposit = GNUNET_TIME_absolute_ntoh (mcp.expire_deposit);
return off;
}
/**
* Serialize information about a denomination key.
*
* @param dk information to serialize
* @param buf buffer to write data in, NULL to just compute
* required size
* @param off offset at @a buf to use
* @return number of bytes written to @a buf at @a off (in addition to @a off itself), or if
* @a buf is NULL, number of bytes required, excluding @a off
*/
static size_t
serialize_denomination_key (const struct TALER_DenominationPublicKey *dk,
char *buf,
size_t off)
{
void *pbuf;
size_t pbuf_size;
uint32_t be;
pbuf_size = GNUNET_CRYPTO_rsa_public_key_encode (dk->rsa_public_key,
&pbuf);
if (NULL == buf)
{ {
GNUNET_free (pbuf); struct GNUNET_JSON_Specification spec[] = {
return pbuf_size + sizeof (uint32_t); GNUNET_JSON_spec_fixed_auto ("transfer_priv",
&mc->transfer_priv[i]),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
GNUNET_JSON_parse (json_array_get (trans_privs,
i),
spec,
NULL, NULL))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
return GNUNET_NO;
}
} }
be = htonl ((uint32_t) pbuf_size); json_decref (trans_privs);
memcpy (&buf[off], return GNUNET_OK;
&be,
sizeof (uint32_t));
memcpy (&buf[off + sizeof (uint32_t)],
pbuf,
pbuf_size);
GNUNET_free (pbuf);
return pbuf_size + sizeof (uint32_t);
}
/**
* Deserialize information about a denomination key.
*
* @param[out] dk information to deserialize
* @param buf buffer to read data from
* @param size number of bytes available at @a buf to use
* @param[out] ok set to #GNUNET_NO to report errors
* @return number of bytes read from @a buf, 0 on error
*/
static size_t
deserialize_denomination_key (struct TALER_DenominationPublicKey *dk,
const char *buf,
size_t size,
int *ok)
{
size_t pbuf_size;
uint32_t be;
if (size < sizeof (uint32_t))
{
GNUNET_break (0);
*ok = GNUNET_NO;
return 0;
}
memcpy (&be,
buf,
sizeof (uint32_t));
pbuf_size = ntohl (be);
if ( (size < sizeof (uint32_t) + pbuf_size) ||
(sizeof (uint32_t) + pbuf_size < pbuf_size) )
{
GNUNET_break (0);
*ok = GNUNET_NO;
return 0;
}
dk->rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_decode (&buf[sizeof (uint32_t)],
pbuf_size);
if (NULL == dk->rsa_public_key)
{
GNUNET_break (0);
*ok = GNUNET_NO;
return 0;
}
return sizeof (uint32_t) + pbuf_size;
}
/**
* Serialize information about a fresh coin we are generating.
*
* @param fc information to serialize
* @param buf buffer to write data in, NULL to just compute
* required size
* @param off offeset at @a buf to use
* @return number of bytes written to @a buf at @a off, or if
* @a buf is NULL, number of bytes required
*/
static size_t
serialize_fresh_coin (const struct TALER_PlanchetSecretsP *fc,
char *buf,
size_t off)
{
if (NULL != buf)
memcpy (&buf[off],
fc,
sizeof (struct TALER_PlanchetSecretsP));
return sizeof (struct TALER_PlanchetSecretsP);
}
/**
* Deserialize information about a fresh coin we are generating.
*
* @param[out] fc information to deserialize
* @param buf buffer to read data from
* @param size number of bytes available at @a buf to use
* @param[out] ok set to #GNUNET_NO to report errors
* @return number of bytes read from @a buf, 0 on error
*/
static size_t
deserialize_fresh_coin (struct TALER_PlanchetSecretsP *fc,
const char *buf,
size_t size,
int *ok)
{
if (size < sizeof (struct TALER_PlanchetSecretsP))
{
GNUNET_break (0);
*ok = GNUNET_NO;
return 0;
}
memcpy (fc,
buf,
sizeof (struct TALER_PlanchetSecretsP));
return sizeof (struct TALER_PlanchetSecretsP);
} }
@ -338,110 +170,153 @@ deserialize_fresh_coin (struct TALER_PlanchetSecretsP *fc,
* Serialize melt data. * Serialize melt data.
* *
* @param md data to serialize * @param md data to serialize
* @param[out] res_size size of buffer returned
* @return serialized melt data * @return serialized melt data
*/ */
static char * static json_t *
serialize_melt_data (const struct MeltData *md, serialize_melt_data (const struct MeltData *md)
size_t *res_size)
{ {
size_t size; json_t *fresh_coins;
size_t asize;
char *buf;
size = 0; fresh_coins = json_array ();
asize = (size_t) -1; /* make the compiler happy */ GNUNET_assert (NULL != fresh_coins);
buf = NULL; for (int i = 0; i<md->num_fresh_coins; i++)
/* we do 2 iterations, #1 to determine total size, #2 to {
actually construct the buffer */ json_t *planchet_secrets;
do {
if (0 == size)
{
size = sizeof (struct MeltDataP);
}
else
{
struct MeltDataP *mdp;
buf = GNUNET_malloc (size); planchet_secrets = json_array ();
asize = size; /* just for invariant check later */ GNUNET_assert (NULL != planchet_secrets);
size = sizeof (struct MeltDataP); for (unsigned int j = 0; j<TALER_CNC_KAPPA; j++)
mdp = (struct MeltDataP *) buf; {
mdp->rc = md->rc; json_t *ps;
mdp->num_fresh_coins = htons (md->num_fresh_coins);
ps = GNUNET_JSON_PACK (
GNUNET_JSON_pack_fixed_auto ("ps",
&md->fresh_coins[i][j]));
GNUNET_assert (0 ==
json_array_append (planchet_secrets,
ps));
} }
size += serialize_melted_coin (&md->melted_coin, GNUNET_assert (0 ==
buf, json_array_append (
size); GNUNET_JSON_PACK (
for (unsigned int i = 0; i<md->num_fresh_coins; i++) TALER_JSON_pack_denom_pub ("denom_pub",
size += serialize_denomination_key (&md->fresh_pks[i], &md->fresh_pks[i]),
buf, TALER_JSON_pack_array_steal ("planchet_secrets",
size); ps)))
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++) );
for (unsigned int j = 0; j<md->num_fresh_coins; j++) }
size += serialize_fresh_coin (&md->fresh_coins[i][j], return GNUNET_JSON_PACK (
buf, TALER_JSON_pack_array_steal ("fresh_coins",
size); fresh_coins),
} while (NULL == buf); TALER_JSON_pack_object_steal ("melted_coin",
GNUNET_assert (size == asize); serialize_melted_coin (&mc->melted_coin)),
*res_size = size; GNUNET_JSON_pack_fixed_auto ("rc",
return buf; &md->rc));
} }
/**
* Deserialize melt data.
*
* @param buf serialized data
* @param buf_size size of @a buf
* @return deserialized melt data, NULL on error
*/
struct MeltData * struct MeltData *
TALER_EXCHANGE_deserialize_melt_data_ (const char *buf, TALER_EXCHANGE_deserialize_melt_data_ (const json_t *melt_data)
size_t buf_size)
{ {
struct MeltData *md; struct MeltData *md = GNUNET_new (struct MeltData);
struct MeltDataP mdp; json_t *fresh_coins;
size_t off; json_t *melted_coin;
int ok; struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("rc",
&md->rc),
GNUNET_JSON_spec_json ("melted_coin",
&melted_coin),
GNUNET_JSON_spec_json ("fresh_coins",
&fresh_coins),
GNUNET_JSON_spec_end ()
};
bool ok;
if (buf_size < sizeof (struct MeltDataP)) if (GNUNET_OK !=
GNUNET_JSON_parse (melt_data,
spec,
NULL, NULL))
{
GNUNET_break (0);
GNUNET_JSON_parse_free (spec);
GNUNET_free (md);
return NULL; return NULL;
memcpy (&mdp, }
buf, if (! (json_is_array (fresh_coins) &&
sizeof (struct MeltDataP)); json_is_object (melted_coin)) )
md = GNUNET_new (struct MeltData); {
md->rc = mdp.rc; GNUNET_break (0);
md->num_fresh_coins = ntohs (mdp.num_fresh_coins); GNUNET_JSON_parse_free (spec);
return NULL;
}
if (GNUNET_OK !=
deserialize_melted_coin (&md->mc,
melted_coin))
{
GNUNET_break (0);
GNUNET_JSON_parse_free (spec);
return NULL;
}
md->num_fresh_coins = json_array_size (fresh_coins);
md->fresh_pks = GNUNET_new_array (md->num_fresh_coins, md->fresh_pks = GNUNET_new_array (md->num_fresh_coins,
struct TALER_DenominationPublicKey); struct TALER_DenominationPublicKey);
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++) for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++)
md->fresh_coins[i] = GNUNET_new_array (md->num_fresh_coins, md->fresh_coins[i] = GNUNET_new_array (md->num_fresh_coins,
struct TALER_PlanchetSecretsP); struct TALER_PlanchetSecretsP);
off = sizeof (struct MeltDataP); ok = true;
ok = GNUNET_YES; for (unsigned int i = 0; i<md->num_fresh_coins; i++)
off += deserialize_melted_coin (&md->melted_coin,
&buf[off],
buf_size - off,
&ok);
for (unsigned int i = 0; (i<md->num_fresh_coins) && (GNUNET_YES == ok); i++)
off += deserialize_denomination_key (&md->fresh_pks[i],
&buf[off],
buf_size - off,
&ok);
for (unsigned int i = 0; i<TALER_CNC_KAPPA; i++)
for (unsigned int j = 0; (j<md->num_fresh_coins) && (GNUNET_YES == ok); j++)
off += deserialize_fresh_coin (&md->fresh_coins[i][j],
&buf[off],
buf_size - off,
&ok);
if (off != buf_size)
{ {
GNUNET_break (0); const json_t *ji = json_array_get (fresh_coins,
ok = GNUNET_NO; i);
json_t *planchet_secrets;
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_json ("planchet_secrets",
&planchet_secrets),
TALER_JSON_spec_denom_pub ("denom_pub",
&md->fresh_pks[i]),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
GNUNET_JSON_parse (melt_data,
spec,
NULL, NULL))
{
GNUNET_break (0);
ok = false;
break;
}
if ( (! json_is_array (planchet_secrets)) ||
(TALER_CNC_KAPPA != json_array_size (planchet_secrets)) )
{
GNUNET_break (0);
ok = false;
break;
}
for (unsigned int j = 0; j<TALER_CNC_KAPPA; j++)
{
struct GNUNET_JSON_Specification jspec[] = {
GNUNET_JSON_spec_data_auto ("ps",
&md->fresh_coins[i][j]),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
GNUNET_JSON_parse (json_array_get (planchet_secrets,
j),
jspec,
NULL, NULL))
{
GNUNET_break (0);
ok = false;
break;
}
}
if (! ok)
break;
} }
if (GNUNET_YES != ok)
if (! ok)
{ {
TALER_EXCHANGE_free_melt_data_ (md); TALER_EXCHANGE_free_melt_data_ (md);
GNUNET_free (md); GNUNET_free (md);
@ -451,56 +326,17 @@ TALER_EXCHANGE_deserialize_melt_data_ (const char *buf,
} }
/** json_t *
* Melt (partially spent) coins to obtain fresh coins that are
* unlinkable to the original coin(s). Note that melting more
* than one coin in a single request will make those coins linkable,
* so the safest operation only melts one coin at a time.
*
* This API is typically used by a wallet. Note that to ensure that
* no money is lost in case of hardware failures, this operation does
* not actually initiate the request. Instead, it generates a buffer
* which the caller must store before proceeding with the actual call
* to #TALER_EXCHANGE_melt() that will generate the request.
*
* This function does verify that the given request data is internally
* consistent. However, the @a melts_sigs are NOT verified.
*
* Aside from some non-trivial cryptographic operations that might
* take a bit of CPU time to complete, this function returns
* its result immediately and does not start any asynchronous
* processing. This function is also thread-safe.
*
* @param melt_priv private key of the coin to melt
* @param melt_amount amount specifying how much
* the coin will contribute to the melt (including fee)
* @param melt_sig signature affirming the
* validity of the public keys corresponding to the
* @a melt_priv private key
* @param melt_pk denomination key information
* record corresponding to the @a melt_sig
* validity of the keys
* @param fresh_pks_len length of the @a pks array
* @param fresh_pks array of @a pks_len denominations of fresh coins to create
* @param[out] res_size set to the size of the return value, or 0 on error
* @return NULL
* if the inputs are invalid (i.e. denomination key not with this exchange).
* Otherwise, pointer to a buffer of @a res_size to store persistently
* before proceeding to #TALER_EXCHANGE_melt().
* Non-null results should be freed using GNUNET_free().
*/
char *
TALER_EXCHANGE_refresh_prepare ( TALER_EXCHANGE_refresh_prepare (
const struct TALER_CoinSpendPrivateKeyP *melt_priv, const struct TALER_CoinSpendPrivateKeyP *melt_priv,
const struct TALER_Amount *melt_amount, const struct TALER_Amount *melt_amount,
const struct TALER_DenominationSignature *melt_sig, const struct TALER_DenominationSignature *melt_sig,
const struct TALER_EXCHANGE_DenomPublicKey *melt_pk, const struct TALER_EXCHANGE_DenomPublicKey *melt_pk,
unsigned int fresh_pks_len, unsigned int fresh_pks_len,
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks, const struct TALER_EXCHANGE_DenomPublicKey *fresh_pks)
size_t *res_size)
{ {
struct MeltData md; struct MeltData md;
char *buf; json_t *ret;
struct TALER_Amount total; struct TALER_Amount total;
struct TALER_CoinSpendPublicKeyP coin_pub; struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_TransferSecretP trans_sec[TALER_CNC_KAPPA]; struct TALER_TransferSecretP trans_sec[TALER_CNC_KAPPA];
@ -509,7 +345,9 @@ TALER_EXCHANGE_refresh_prepare (
GNUNET_CRYPTO_eddsa_key_get_public (&melt_priv->eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&melt_priv->eddsa_priv,
&coin_pub.eddsa_pub); &coin_pub.eddsa_pub);
/* build up melt data structure */ /* build up melt data structure */
memset (&md, 0, sizeof (md)); memset (&md,
0,
sizeof (md));
md.num_fresh_coins = fresh_pks_len; md.num_fresh_coins = fresh_pks_len;
md.melted_coin.coin_priv = *melt_priv; md.melted_coin.coin_priv = *melt_priv;
md.melted_coin.melt_amount_with_fee = *melt_amount; md.melted_coin.melt_amount_with_fee = *melt_amount;
@ -605,8 +443,7 @@ TALER_EXCHANGE_refresh_prepare (
&coin_pub, &coin_pub,
melt_amount); melt_amount);
/* finally, serialize everything */ /* finally, serialize everything */
buf = serialize_melt_data (&md, ret = serialize_melt_data (&md);
res_size);
for (unsigned int i = 0; i < TALER_CNC_KAPPA; i++) for (unsigned int i = 0; i < TALER_CNC_KAPPA; i++)
{ {
for (unsigned int j = 0; j < fresh_pks_len; j++) for (unsigned int j = 0; j < fresh_pks_len; j++)

View File

@ -204,13 +204,11 @@ struct MeltData
/** /**
* Deserialize melt data. * Deserialize melt data.
* *
* @param buf serialized data * @param data json data to deserialize
* @param buf_size size of @a buf
* @return deserialized melt data, NULL on error * @return deserialized melt data, NULL on error
*/ */
struct MeltData * struct MeltData *
TALER_EXCHANGE_deserialize_melt_data_ (const char *buf, TALER_EXCHANGE_deserialize_melt_data_ (const json_t *data);
size_t buf_size);
/** /**
@ -219,7 +217,7 @@ TALER_EXCHANGE_deserialize_melt_data_ (const char *buf,
* as we use this function also when freeing melt data that was not * as we use this function also when freeing melt data that was not
* fully initialized (i.e. due to failures in #TALER_EXCHANGE_deserialize_melt_data_()). * fully initialized (i.e. due to failures in #TALER_EXCHANGE_deserialize_melt_data_()).
* *
* @param md melting data to release, the pointer itself is NOT * @param[in] md melting data to release, the pointer itself is NOT
* freed (as it is typically not allocated by itself) * freed (as it is typically not allocated by itself)
*/ */
void void