save coin private key

This commit is contained in:
Fournier Nicolas 2015-07-15 17:46:49 +02:00
parent 3a4052d16d
commit f696b737d0
4 changed files with 109 additions and 107 deletions

View File

@ -347,67 +347,63 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit)
* @param reserve reserve providing the money for the coin * @param reserve reserve providing the money for the coin
* @return a randomly generated CollectableBlindcoin * @return a randomly generated CollectableBlindcoin
*/ */
struct TALER_MINTDB_CollectableBlindcoin * struct PERF_TALER_MINTDB_Coin *
PERF_TALER_MINTDB_collectable_blindcoin_init ( PERF_TALER_MINTDB_coin_init (
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki, const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
const struct PERF_TALER_MINTDB_Reserve *reserve) const struct PERF_TALER_MINTDB_Reserve *reserve)
{ {
uint32_t random_int; struct PERF_TALER_MINTDB_Coin *coin;
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;
GNUNET_assert (NULL !=
(coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin)));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ())); (coin = GNUNET_new (struct PERF_TALER_MINTDB_Coin)));
{ {/* priv */
char *buffer = NULL; struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
int size;
GNUNET_assert (0 <
(size = GNUNET_CRYPTO_rsa_private_key_encode (
dki->denom_priv.rsa_private_key,
&buffer)));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(denomination_key = (priv = GNUNET_CRYPTO_eddsa_key_create()));
GNUNET_CRYPTO_rsa_private_key_decode (buffer, size))); coin->priv = *priv;
GNUNET_free (buffer); }
{/* public_info */
GNUNET_CRYPTO_eddsa_key_get_public (&coin->priv,
&coin->public_info.coin_pub.eddsa_pub);
GNUNET_assert (NULL !=
(coin->public_info.denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key)));
GNUNET_assert (NULL !=
(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->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))));
}
} }
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);
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);
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);
return coin; return coin;
} }
@ -417,31 +413,36 @@ PERF_TALER_MINTDB_collectable_blindcoin_init (
* @param coin the coin to copy * @param coin the coin to copy
* @return a copy of coin; NULL if error * @return a copy of coin; NULL if error
*/ */
struct TALER_MINTDB_CollectableBlindcoin * struct PERF_TALER_MINTDB_Coin *
PERF_TALER_MINTDB_collectable_blindcoin_copy (const struct TALER_MINTDB_CollectableBlindcoin *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 != GNUNET_assert (NULL !=
(copy = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin))); (copy = GNUNET_new (struct PERF_TALER_MINTDB_Coin)));
*copy = *coin; copy->priv = coin->priv;
// No signature copy function found, Hacking it in {/* public_info */
{ copy->public_info.coin_pub = coin->public_info.coin_pub;
char *buffer = NULL;
int size;
GNUNET_assert (0 <
(size = GNUNET_CRYPTO_rsa_signature_encode (
coin->sig.rsa_signature,
&buffer)));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(copy->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_decode( (copy->public_info.denom_pub.rsa_public_key =
buffer, GNUNET_CRYPTO_rsa_public_key_dup (coin->public_info.denom_pub.rsa_public_key)));
size))); GNUNET_assert (NULL !=
GNUNET_free (buffer); (copy->public_info.denom_sig.rsa_signature =
GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature)));
}
{/* blind */
GNUNET_assert (NULL !=
(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;
} }
GNUNET_assert (NULL !=
(copy->denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_public_key_dup (coin->denom_pub.rsa_public_key)));
return copy; 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 * @param coin pointer to the structure to free
*/ */
int 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) if (NULL == coin)
return GNUNET_OK; return GNUNET_OK;
GNUNET_CRYPTO_rsa_public_key_free (coin->public_info.denom_pub.rsa_public_key);
GNUNET_CRYPTO_rsa_signature_free (coin->sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (coin->public_info.denom_sig.rsa_signature);
GNUNET_CRYPTO_rsa_public_key_free (coin->denom_pub.rsa_public_key); 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; return GNUNET_OK;
} }

View File

@ -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 dki denomination key used to sign the coin
* @param reserve reserve providing the money for the coin * @param reserve reserve providing the money for the coin
* @return a randomly generated CollectableBlindcoin * @return a randomly generated CollectableBlindcoin
*/ */
struct TALER_MINTDB_CollectableBlindcoin * struct PERF_TALER_MINTDB_Coin *
PERF_TALER_MINTDB_collectable_blindcoin_init ( PERF_TALER_MINTDB_coin_init (
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki, const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
const struct PERF_TALER_MINTDB_Reserve *reserve); const struct PERF_TALER_MINTDB_Reserve *reserve);
@ -160,9 +160,9 @@ PERF_TALER_MINTDB_collectable_blindcoin_init (
* @param coin the coin to copy * @param coin the coin to copy
* @return a copy of coin; NULL if error * @return a copy of coin; NULL if error
*/ */
struct TALER_MINTDB_CollectableBlindcoin * struct PERF_TALER_MINTDB_Coin *
PERF_TALER_MINTDB_collectable_blindcoin_copy ( PERF_TALER_MINTDB_coin_copy (
const struct TALER_MINTDB_CollectableBlindcoin *coin); 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 * @param coin pointer to the structure to free
*/ */
int int
PERF_TALER_MINTDB_collectable_blindcoin_free ( PERF_TALER_MINTDB_coin_free (
struct TALER_MINTDB_CollectableBlindcoin *coin); struct PERF_TALER_MINTDB_Coin *coin);
/** /**

View File

@ -69,12 +69,12 @@ data_free (struct PERF_TALER_MINTDB_Data *data)
data->data.deposit = NULL; data->data.deposit = NULL;
return; return;
case PERF_TALER_MINTDB_BLINDCOIN: case PERF_TALER_MINTDB_COIN:
if (NULL == data->data.blindcoin) if (NULL == data->data.coin)
return; return;
PERF_TALER_MINTDB_collectable_blindcoin_free (data->data.blindcoin); PERF_TALER_MINTDB_coin_free (data->data.coin);
GNUNET_free (data->data.blindcoin); GNUNET_free (data->data.coin);
data->data.blindcoin = NULL; data->data.coin = NULL;
return; return;
case PERF_TALER_MINTDB_RESERVE: 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); PERF_TALER_MINTDB_deposit_copy (data->data.deposit);
return; return;
case PERF_TALER_MINTDB_BLINDCOIN: case PERF_TALER_MINTDB_COIN:
copy->data.blindcoin = copy->data.coin =
PERF_TALER_MINTDB_collectable_blindcoin_copy (data->data.blindcoin); PERF_TALER_MINTDB_coin_copy (data->data.coin);
return; return;
case PERF_TALER_MINTDB_RESERVE: case PERF_TALER_MINTDB_RESERVE:
@ -627,7 +627,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW: case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
{ {
int dki_index, reserve_index; int dki_index, reserve_index;
struct TALER_MINTDB_CollectableBlindcoin *blindcoin ; struct PERF_TALER_MINTDB_Coin *coin ;
GNUNET_assert (GNUNET_SYSERR != GNUNET_assert (GNUNET_SYSERR !=
(dki_index = cmd_find ( (dki_index = cmd_find (
@ -638,15 +638,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
state->cmd, state->cmd,
state->cmd[state->i].details.insert_withdraw.label_reserve))); state->cmd[state->i].details.insert_withdraw.label_reserve)));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(blindcoin = (coin =
PERF_TALER_MINTDB_collectable_blindcoin_init ( PERF_TALER_MINTDB_coin_init (
state->cmd[dki_index].exposed.data.dki, state->cmd[dki_index].exposed.data.dki,
state->cmd[reserve_index].exposed.data.reserve))); state->cmd[reserve_index].exposed.data.reserve)));
state->plugin->insert_withdraw_info (state->plugin->cls, state->plugin->insert_withdraw_info (state->plugin->cls,
state->session, state->session,
blindcoin); &coin->blind);
state->cmd[state->i].exposed.data.blindcoin = blindcoin; state->cmd[state->i].exposed.data.coin = coin;
} }
break; break;
@ -663,8 +663,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
&data); &data);
state->plugin->get_withdraw_info (state->plugin->cls, state->plugin->get_withdraw_info (state->plugin->cls,
state->session, state->session,
&data.data.blindcoin->h_coin_envelope, &data.data.coin->blind.h_coin_envelope,
data.data.blindcoin); &data.data.coin->blind);
} }
break; break;

View File

@ -322,7 +322,7 @@
/** /**
* Inserts informations about a withdrawal in the database * 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 the label of this command
* @param _label_dki denomination key used to sign the coin * @param _label_dki denomination key used to sign the coin
@ -332,7 +332,7 @@
{ \ { \
.command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \ .command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \
.label = _label, \ .label = _label, \
.exposed.type = PERF_TALER_MINTDB_BLINDCOIN, \ .exposed.type = PERF_TALER_MINTDB_COIN, \
.details.insert_withdraw = {\ .details.insert_withdraw = {\
.label_dki = _label_dki, \ .label_dki = _label_dki, \
.label_reserve = _label_reserve, \ .label_reserve = _label_reserve, \
@ -360,7 +360,7 @@
* It first access the reserve history to check the ballance * It first access the reserve history to check the ballance
* and hen emits a coin. * and hen emits a coin.
* *
* @exposes #PERF_TALER_MINTDB_BLINDCOIN * @exposes #PERF_TALER_MINTDB_COIN
* *
* @param _label the label of this command * @param _label the label of this command
* @param _label_reserve the reserve used to provide currency * @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_NONE,
PERF_TALER_MINTDB_TIME, PERF_TALER_MINTDB_TIME,
PERF_TALER_MINTDB_DEPOSIT, PERF_TALER_MINTDB_DEPOSIT,
PERF_TALER_MINTDB_BLINDCOIN, PERF_TALER_MINTDB_COIN,
PERF_TALER_MINTDB_RESERVE, PERF_TALER_MINTDB_RESERVE,
PERF_TALER_MINTDB_DENOMINATION_INFO, PERF_TALER_MINTDB_DENOMINATION_INFO,
}; };
@ -402,8 +402,8 @@ struct PERF_TALER_MINTDB_Data
struct timespec time; struct timespec time;
/** #PERF_TALER_MINTDB_DEPOSIT */ /** #PERF_TALER_MINTDB_DEPOSIT */
struct TALER_MINTDB_Deposit *deposit; struct TALER_MINTDB_Deposit *deposit;
/** #PERF_TALER_MINTDB_BLINDCOIN */ /** #PERF_TALER_MINTDB_COIN */
struct TALER_MINTDB_CollectableBlindcoin *blindcoin; struct PERF_TALER_MINTDB_Coin *coin;
/** #PERF_TALER_MINTDB_RESERVE */ /** #PERF_TALER_MINTDB_RESERVE */
struct PERF_TALER_MINTDB_Reserve *reserve; struct PERF_TALER_MINTDB_Reserve *reserve;
/** #PERF_TALER_MINTDB_DENOMINATION_INFO */ /** #PERF_TALER_MINTDB_DENOMINATION_INFO */