save reserve private key

This commit is contained in:
Fournier Nicolas 2015-07-15 16:28:12 +02:00
parent eeafe9a8dc
commit 3a4052d16d
4 changed files with 71 additions and 30 deletions

View File

@ -140,22 +140,25 @@ PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInf
* Generate a dummy reserve for testing * Generate a dummy reserve for testing
* @return a reserve with 1000 EUR in it * @return a reserve with 1000 EUR in it
*/ */
struct TALER_MINTDB_Reserve * struct PERF_TALER_MINTDB_Reserve *
PERF_TALER_MINTDB_reserve_init () PERF_TALER_MINTDB_reserve_init ()
{ {
struct TALER_MINTDB_Reserve *reserve; struct PERF_TALER_MINTDB_Reserve *reserve;
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv;
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(reserve = GNUNET_new (struct TALER_MINTDB_Reserve))); (reserve = GNUNET_new (struct PERF_TALER_MINTDB_Reserve)));
GNUNET_assert (NULL != {/* private */
(reserve_priv = GNUNET_CRYPTO_eddsa_key_create ())); struct GNUNET_CRYPTO_EddsaPrivateKey *private;
GNUNET_CRYPTO_eddsa_key_get_public (reserve_priv , GNUNET_assert (NULL !=
&reserve->pub.eddsa_pub); (private = GNUNET_CRYPTO_eddsa_key_create ()));
reserve->private = *private;
}
GNUNET_CRYPTO_eddsa_key_get_public (&reserve->private,
&reserve->reserve.pub.eddsa_pub);
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":1000", &reserve->balance)); TALER_string_to_amount (CURRENCY ":1000", &reserve->reserve.balance));
reserve->expiry = GNUNET_TIME_absolute_get_forever_ (); reserve->reserve.expiry = GNUNET_TIME_absolute_get_forever_ ();
GNUNET_free (reserve_priv);
return reserve; return reserve;
} }
@ -165,11 +168,12 @@ PERF_TALER_MINTDB_reserve_init ()
* @param reserve the reserve to copy * @param reserve the reserve to copy
* @return a copy of @a reserve; NULL if error * @return a copy of @a reserve; NULL if error
*/ */
struct TALER_MINTDB_Reserve * struct PERF_TALER_MINTDB_Reserve *
PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve) PERF_TALER_MINTDB_reserve_copy (const struct PERF_TALER_MINTDB_Reserve *reserve)
{ {
struct TALER_MINTDB_Reserve *copy; struct PERF_TALER_MINTDB_Reserve *copy;
GNUNET_assert (NULL != (copy = GNUNET_new (struct TALER_MINTDB_Reserve))); GNUNET_assert (NULL !=
(copy = GNUNET_new (struct PERF_TALER_MINTDB_Reserve)));
*copy = *reserve; *copy = *reserve;
return copy; return copy;
} }
@ -180,7 +184,7 @@ PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve)
* @param reserve pointer to the structure to be freed * @param reserve pointer to the structure to be freed
*/ */
int int
PERF_TALER_MINTDB_reserve_free (struct TALER_MINTDB_Reserve *reserve) PERF_TALER_MINTDB_reserve_free (struct PERF_TALER_MINTDB_Reserve *reserve)
{ {
if (NULL == reserve) if (NULL == reserve)
return GNUNET_OK; return GNUNET_OK;
@ -346,10 +350,10 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit)
struct TALER_MINTDB_CollectableBlindcoin * struct TALER_MINTDB_CollectableBlindcoin *
PERF_TALER_MINTDB_collectable_blindcoin_init ( PERF_TALER_MINTDB_collectable_blindcoin_init (
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki, const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
const struct TALER_MINTDB_Reserve *reserve) const struct PERF_TALER_MINTDB_Reserve *reserve)
{ {
uint32_t random_int; uint32_t random_int;
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key; struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key;
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key; struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key;
struct { struct {
struct GNUNET_CRYPTO_EccSignaturePurpose purpose; struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
@ -376,7 +380,7 @@ PERF_TALER_MINTDB_collectable_blindcoin_init (
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(coin->denom_pub.rsa_public_key = (coin->denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key))); GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key)));
coin->reserve_pub.eddsa_pub = reserve->pub.eddsa_pub; coin->reserve_pub.eddsa_pub = reserve->reserve.pub.eddsa_pub;
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":1.1", TALER_string_to_amount (CURRENCY ":1.1",
&coin->amount_with_fee)); &coin->amount_with_fee));

View File

@ -26,6 +26,43 @@
#define CURRENCY "EUR" #define CURRENCY "EUR"
/**
* All information about a reserve
*/
struct PERF_TALER_MINTDB_Reserve
{
/**
* Information about a rserve available to the Mint
*/
struct TALER_MINTDB_Reserve reserve;
/**
* Private key of a reserve
*/
struct GNUNET_CRYPTO_EddsaPrivateKey private;
};
/**
* All informations about a coin
*/
struct PERF_TALER_MINTDB_Coin
{
/**
* Blinded coin, known by the mint
*/
struct TALER_MINTDB_CollectableBlindcoin blind;
/**
* Public key of the coin and othes informations
*/
struct TALER_CoinPublicInfo public_info;
/**
* Private key of the coin
*/
struct GNUNET_CRYPTO_EddsaPrivateKey priv;
};
/** /**
@ -59,7 +96,7 @@ PERF_TALER_MINTDB_denomination_free (
* Generate a dummy reserve for testing * Generate a dummy reserve for testing
* @return a reserve with 1000 EUR in it * @return a reserve with 1000 EUR in it
*/ */
struct TALER_MINTDB_Reserve * struct PERF_TALER_MINTDB_Reserve *
PERF_TALER_MINTDB_reserve_init (void); PERF_TALER_MINTDB_reserve_init (void);
@ -68,8 +105,8 @@ PERF_TALER_MINTDB_reserve_init (void);
* @param reserve the reserve to copy * @param reserve the reserve to copy
* @return a copy of @a reserve; NULL if error * @return a copy of @a reserve; NULL if error
*/ */
struct TALER_MINTDB_Reserve * struct PERF_TALER_MINTDB_Reserve *
PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve); PERF_TALER_MINTDB_reserve_copy (const struct PERF_TALER_MINTDB_Reserve *reserve);
/** /**
@ -77,7 +114,7 @@ PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve);
* @param reserve pointer to the structure to be freed * @param reserve pointer to the structure to be freed
*/ */
int int
PERF_TALER_MINTDB_reserve_free (struct TALER_MINTDB_Reserve *reserve); PERF_TALER_MINTDB_reserve_free (struct PERF_TALER_MINTDB_Reserve *reserve);
/** /**
@ -115,7 +152,7 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit);
struct TALER_MINTDB_CollectableBlindcoin * struct TALER_MINTDB_CollectableBlindcoin *
PERF_TALER_MINTDB_collectable_blindcoin_init ( PERF_TALER_MINTDB_collectable_blindcoin_init (
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki, const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
const struct TALER_MINTDB_Reserve *reserve); const struct PERF_TALER_MINTDB_Reserve *reserve);
/** /**

View File

@ -533,7 +533,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_INSERT_RESERVE: case PERF_TALER_MINTDB_CMD_INSERT_RESERVE:
{ {
struct TALER_MINTDB_Reserve *reserve; struct PERF_TALER_MINTDB_Reserve *reserve;
json_t *details = NULL; json_t *details = NULL;
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(details = json_pack ("{s:i}","justification", (details = json_pack ("{s:i}","justification",
@ -544,8 +544,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
state->plugin->reserves_in_insert ( state->plugin->reserves_in_insert (
state->plugin->cls, state->plugin->cls,
state->session, state->session,
&reserve->pub, &reserve->reserve.pub,
&reserve->balance, &reserve->reserve.balance,
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
details details
); );
@ -568,7 +568,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
(state->plugin->reserve_get (state->plugin->cls, (state->plugin->reserve_get (state->plugin->cls,
state->session, state->session,
data.data.reserve))); &data.data.reserve->reserve)));
} }
break; break;
@ -587,7 +587,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(history = state->plugin->get_reserve_history (state->plugin->cls, (history = state->plugin->get_reserve_history (state->plugin->cls,
state->session, state->session,
&data.data.reserve->pub))); &data.data.reserve->reserve.pub)));
state->plugin->free_reserve_history (state->plugin->cls, state->plugin->free_reserve_history (state->plugin->cls,
history); history);
} }

View File

@ -405,7 +405,7 @@ struct PERF_TALER_MINTDB_Data
/** #PERF_TALER_MINTDB_BLINDCOIN */ /** #PERF_TALER_MINTDB_BLINDCOIN */
struct TALER_MINTDB_CollectableBlindcoin *blindcoin; struct TALER_MINTDB_CollectableBlindcoin *blindcoin;
/** #PERF_TALER_MINTDB_RESERVE */ /** #PERF_TALER_MINTDB_RESERVE */
struct TALER_MINTDB_Reserve *reserve; struct PERF_TALER_MINTDB_Reserve *reserve;
/** #PERF_TALER_MINTDB_DENOMINATION_INFO */ /** #PERF_TALER_MINTDB_DENOMINATION_INFO */
struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
} data; } data;