save coin private key
This commit is contained in:
parent
3a4052d16d
commit
f696b737d0
@ -347,67 +347,63 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit)
|
||||
* @param reserve reserve providing the money for the coin
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
struct PERF_TALER_MINTDB_Coin *
|
||||
PERF_TALER_MINTDB_coin_init (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
|
||||
const struct PERF_TALER_MINTDB_Reserve *reserve)
|
||||
{
|
||||
uint32_t random_int;
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key;
|
||||
struct {
|
||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||
uint32_t data;
|
||||
} unsigned_data;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin;
|
||||
struct PERF_TALER_MINTDB_Coin *coin;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin)));
|
||||
(coin = GNUNET_new (struct PERF_TALER_MINTDB_Coin)));
|
||||
{/* priv */
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_private_key_encode (
|
||||
dki->denom_priv.rsa_private_key,
|
||||
&buffer)));
|
||||
GNUNET_assert (NULL !=
|
||||
(denomination_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_decode (buffer, size)));
|
||||
GNUNET_free (buffer);
|
||||
(priv = GNUNET_CRYPTO_eddsa_key_create()));
|
||||
coin->priv = *priv;
|
||||
}
|
||||
{/* public_info */
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (&coin->priv,
|
||||
&coin->public_info.coin_pub.eddsa_pub);
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key)));
|
||||
coin->reserve_pub.eddsa_pub = reserve->reserve.pub.eddsa_pub;
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
TALER_string_to_amount (CURRENCY ":1.1",
|
||||
&coin->amount_with_fee));
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
TALER_string_to_amount (CURRENCY ":1.1",
|
||||
&coin->withdraw_fee));
|
||||
random_int =
|
||||
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
|
||||
(coin->public_info.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key)));
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_sign (denomination_key,
|
||||
&random_int,
|
||||
sizeof (random_int))));
|
||||
char *buffer;
|
||||
GNUNET_CRYPTO_rsa_signature_encode (coin->sig.rsa_signature, &buffer);
|
||||
free (buffer);
|
||||
(coin->public_info.denom_sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_sign (dki->denom_priv.rsa_private_key,
|
||||
&coin->public_info.coin_pub,
|
||||
sizeof (struct TALER_CoinSpendPublicKeyP))));
|
||||
}
|
||||
{/* blind */
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->blind.sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature)));
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->blind.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key)));
|
||||
TALER_amount_ntoh (&coin->blind.amount_with_fee,
|
||||
&dki->issue.properties.value);
|
||||
TALER_amount_ntoh (&coin->blind.withdraw_fee,
|
||||
&dki->issue.properties.fee_withdraw);
|
||||
coin->blind.reserve_pub = reserve->reserve.pub;
|
||||
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
&coin->h_coin_envelope);
|
||||
unsigned_data.purpose.size = htonl (sizeof (unsigned_data));
|
||||
unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
|
||||
unsigned_data.data = htonl (random_int);
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_CRYPTO_eddsa_sign (reserve_sig_key,
|
||||
(struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data,
|
||||
&coin->reserve_sig.eddsa_signature));
|
||||
GNUNET_free (reserve_sig_key);
|
||||
GNUNET_CRYPTO_rsa_private_key_free (denomination_key);
|
||||
&coin->blind.h_coin_envelope);
|
||||
{
|
||||
struct {
|
||||
struct TALER_ReservePublicKeyP reserve_pub;
|
||||
struct GNUNET_HashCode hash;
|
||||
} data;
|
||||
|
||||
data.reserve_pub = reserve->reserve.pub;
|
||||
data.hash = coin->blind.h_coin_envelope;
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->blind.sig.rsa_signature
|
||||
= GNUNET_CRYPTO_rsa_sign (dki->denom_priv.rsa_private_key,
|
||||
&data,
|
||||
sizeof (data))));
|
||||
}
|
||||
}
|
||||
return coin;
|
||||
}
|
||||
|
||||
@ -417,31 +413,36 @@ PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
* @param coin the coin to copy
|
||||
* @return a copy of coin; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_copy (const struct TALER_MINTDB_CollectableBlindcoin *coin)
|
||||
struct PERF_TALER_MINTDB_Coin *
|
||||
PERF_TALER_MINTDB_coin_copy (const struct PERF_TALER_MINTDB_Coin *coin)
|
||||
{
|
||||
struct TALER_MINTDB_CollectableBlindcoin *copy;
|
||||
struct PERF_TALER_MINTDB_Coin *copy;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(copy = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin)));
|
||||
*copy = *coin;
|
||||
// No signature copy function found, Hacking it in
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_signature_encode (
|
||||
coin->sig.rsa_signature,
|
||||
&buffer)));
|
||||
(copy = GNUNET_new (struct PERF_TALER_MINTDB_Coin)));
|
||||
copy->priv = coin->priv;
|
||||
{/* public_info */
|
||||
copy->public_info.coin_pub = coin->public_info.coin_pub;
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_decode(
|
||||
buffer,
|
||||
size)));
|
||||
GNUNET_free (buffer);
|
||||
(copy->public_info.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (coin->public_info.denom_pub.rsa_public_key)));
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->public_info.denom_sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature)));
|
||||
}
|
||||
{/* blind */
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (coin->denom_pub.rsa_public_key)));
|
||||
(copy->blind.sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_signature_dup (coin->blind.sig.rsa_signature)));
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->blind.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (coin->blind.denom_pub.rsa_public_key)));
|
||||
copy->blind.amount_with_fee = coin->blind.amount_with_fee;
|
||||
copy->blind.withdraw_fee = coin->blind.withdraw_fee;
|
||||
copy->blind.reserve_pub = coin->blind.reserve_pub;
|
||||
copy->blind.h_coin_envelope = coin->blind.h_coin_envelope;
|
||||
copy->blind.reserve_sig = coin->blind.reserve_sig;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -451,13 +452,14 @@ PERF_TALER_MINTDB_collectable_blindcoin_copy (const struct TALER_MINTDB_Collecta
|
||||
* @param coin pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin)
|
||||
PERF_TALER_MINTDB_coin_free (struct PERF_TALER_MINTDB_Coin *coin)
|
||||
{
|
||||
if (NULL == coin)
|
||||
return GNUNET_OK;
|
||||
|
||||
GNUNET_CRYPTO_rsa_signature_free (coin->sig.rsa_signature);
|
||||
GNUNET_CRYPTO_rsa_public_key_free (coin->denom_pub.rsa_public_key);
|
||||
GNUNET_CRYPTO_rsa_public_key_free (coin->public_info.denom_pub.rsa_public_key);
|
||||
GNUNET_CRYPTO_rsa_signature_free (coin->public_info.denom_sig.rsa_signature);
|
||||
GNUNET_CRYPTO_rsa_signature_free (coin->blind.sig.rsa_signature);
|
||||
GNUNET_CRYPTO_rsa_public_key_free (coin->blind.denom_pub.rsa_public_key);
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
@ -144,13 +144,13 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a CollectableBlindcoin for testing purpuses
|
||||
* Generate a coin for testing purpuses
|
||||
* @param dki denomination key used to sign the coin
|
||||
* @param reserve reserve providing the money for the coin
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
struct PERF_TALER_MINTDB_Coin *
|
||||
PERF_TALER_MINTDB_coin_init (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
|
||||
const struct PERF_TALER_MINTDB_Reserve *reserve);
|
||||
|
||||
@ -160,9 +160,9 @@ PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
* @param coin the coin to copy
|
||||
* @return a copy of coin; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_copy (
|
||||
const struct TALER_MINTDB_CollectableBlindcoin *coin);
|
||||
struct PERF_TALER_MINTDB_Coin *
|
||||
PERF_TALER_MINTDB_coin_copy (
|
||||
const struct PERF_TALER_MINTDB_Coin *coin);
|
||||
|
||||
|
||||
/**
|
||||
@ -170,8 +170,8 @@ PERF_TALER_MINTDB_collectable_blindcoin_copy (
|
||||
* @param coin pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin);
|
||||
PERF_TALER_MINTDB_coin_free (
|
||||
struct PERF_TALER_MINTDB_Coin *coin);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -69,12 +69,12 @@ data_free (struct PERF_TALER_MINTDB_Data *data)
|
||||
data->data.deposit = NULL;
|
||||
return;
|
||||
|
||||
case PERF_TALER_MINTDB_BLINDCOIN:
|
||||
if (NULL == data->data.blindcoin)
|
||||
case PERF_TALER_MINTDB_COIN:
|
||||
if (NULL == data->data.coin)
|
||||
return;
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (data->data.blindcoin);
|
||||
GNUNET_free (data->data.blindcoin);
|
||||
data->data.blindcoin = NULL;
|
||||
PERF_TALER_MINTDB_coin_free (data->data.coin);
|
||||
GNUNET_free (data->data.coin);
|
||||
data->data.coin = NULL;
|
||||
return;
|
||||
|
||||
case PERF_TALER_MINTDB_RESERVE:
|
||||
@ -120,9 +120,9 @@ data_copy (const struct PERF_TALER_MINTDB_Data *data, struct PERF_TALER_MINTDB_D
|
||||
PERF_TALER_MINTDB_deposit_copy (data->data.deposit);
|
||||
return;
|
||||
|
||||
case PERF_TALER_MINTDB_BLINDCOIN:
|
||||
copy->data.blindcoin =
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_copy (data->data.blindcoin);
|
||||
case PERF_TALER_MINTDB_COIN:
|
||||
copy->data.coin =
|
||||
PERF_TALER_MINTDB_coin_copy (data->data.coin);
|
||||
return;
|
||||
|
||||
case PERF_TALER_MINTDB_RESERVE:
|
||||
@ -627,7 +627,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
|
||||
{
|
||||
int dki_index, reserve_index;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin ;
|
||||
struct PERF_TALER_MINTDB_Coin *coin ;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(dki_index = cmd_find (
|
||||
@ -638,15 +638,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
state->cmd,
|
||||
state->cmd[state->i].details.insert_withdraw.label_reserve)));
|
||||
GNUNET_assert (NULL !=
|
||||
(blindcoin =
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
(coin =
|
||||
PERF_TALER_MINTDB_coin_init (
|
||||
state->cmd[dki_index].exposed.data.dki,
|
||||
state->cmd[reserve_index].exposed.data.reserve)));
|
||||
|
||||
state->plugin->insert_withdraw_info (state->plugin->cls,
|
||||
state->session,
|
||||
blindcoin);
|
||||
state->cmd[state->i].exposed.data.blindcoin = blindcoin;
|
||||
&coin->blind);
|
||||
state->cmd[state->i].exposed.data.coin = coin;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -663,8 +663,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
&data);
|
||||
state->plugin->get_withdraw_info (state->plugin->cls,
|
||||
state->session,
|
||||
&data.data.blindcoin->h_coin_envelope,
|
||||
data.data.blindcoin);
|
||||
&data.data.coin->blind.h_coin_envelope,
|
||||
&data.data.coin->blind);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -322,7 +322,7 @@
|
||||
/**
|
||||
* Inserts informations about a withdrawal in the database
|
||||
*
|
||||
* @exposes #PERF_TALER_MINTDB_BLINDCOIN
|
||||
* @exposes #PERF_TALER_MINTDB_COIN
|
||||
*
|
||||
* @param _label the label of this command
|
||||
* @param _label_dki denomination key used to sign the coin
|
||||
@ -332,7 +332,7 @@
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \
|
||||
.label = _label, \
|
||||
.exposed.type = PERF_TALER_MINTDB_BLINDCOIN, \
|
||||
.exposed.type = PERF_TALER_MINTDB_COIN, \
|
||||
.details.insert_withdraw = {\
|
||||
.label_dki = _label_dki, \
|
||||
.label_reserve = _label_reserve, \
|
||||
@ -360,7 +360,7 @@
|
||||
* It first access the reserve history to check the ballance
|
||||
* and hen emits a coin.
|
||||
*
|
||||
* @exposes #PERF_TALER_MINTDB_BLINDCOIN
|
||||
* @exposes #PERF_TALER_MINTDB_COIN
|
||||
*
|
||||
* @param _label the label of this command
|
||||
* @param _label_reserve the reserve used to provide currency
|
||||
@ -379,7 +379,7 @@ enum PERF_TALER_MINTDB_Type
|
||||
PERF_TALER_MINTDB_NONE,
|
||||
PERF_TALER_MINTDB_TIME,
|
||||
PERF_TALER_MINTDB_DEPOSIT,
|
||||
PERF_TALER_MINTDB_BLINDCOIN,
|
||||
PERF_TALER_MINTDB_COIN,
|
||||
PERF_TALER_MINTDB_RESERVE,
|
||||
PERF_TALER_MINTDB_DENOMINATION_INFO,
|
||||
};
|
||||
@ -402,8 +402,8 @@ struct PERF_TALER_MINTDB_Data
|
||||
struct timespec time;
|
||||
/** #PERF_TALER_MINTDB_DEPOSIT */
|
||||
struct TALER_MINTDB_Deposit *deposit;
|
||||
/** #PERF_TALER_MINTDB_BLINDCOIN */
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin;
|
||||
/** #PERF_TALER_MINTDB_COIN */
|
||||
struct PERF_TALER_MINTDB_Coin *coin;
|
||||
/** #PERF_TALER_MINTDB_RESERVE */
|
||||
struct PERF_TALER_MINTDB_Reserve *reserve;
|
||||
/** #PERF_TALER_MINTDB_DENOMINATION_INFO */
|
||||
|
Loading…
Reference in New Issue
Block a user