diff options
author | Fournier Nicolas <nicolas.fournier@ensta-paristech.fr> | 2015-07-15 17:46:49 +0200 |
---|---|---|
committer | Fournier Nicolas <nicolas.fournier@ensta-paristech.fr> | 2015-07-15 17:46:49 +0200 |
commit | f696b737d005b383f099abcc7355763b86c1be21 (patch) | |
tree | cf2bcc8a5a172e7ecbcc93d1e5740009d6c27dec /src/mintdb | |
parent | 3a4052d16d2b426a1513fd10fdcdbb9fdd13a526 (diff) |
save coin private key
Diffstat (limited to 'src/mintdb')
-rw-r--r-- | src/mintdb/perf_taler_mintdb_init.c | 158 | ||||
-rw-r--r-- | src/mintdb/perf_taler_mintdb_init.h | 16 | ||||
-rw-r--r-- | src/mintdb/perf_taler_mintdb_interpreter.c | 30 | ||||
-rw-r--r-- | src/mintdb/perf_taler_mintdb_interpreter.h | 12 |
4 files changed, 109 insertions, 107 deletions
diff --git a/src/mintdb/perf_taler_mintdb_init.c b/src/mintdb/perf_taler_mintdb_init.c index 7160c8d61..97260940b 100644 --- a/src/mintdb/perf_taler_mintdb_init.c +++ b/src/mintdb/perf_taler_mintdb_init.c @@ -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))); 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))); + (coin = GNUNET_new (struct PERF_TALER_MINTDB_Coin))); + {/* priv */ + struct GNUNET_CRYPTO_EddsaPrivateKey *priv; + 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->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; } @@ -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->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; } @@ -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; } diff --git a/src/mintdb/perf_taler_mintdb_init.h b/src/mintdb/perf_taler_mintdb_init.h index 1925cb2b2..06ce2df82 100644 --- a/src/mintdb/perf_taler_mintdb_init.h +++ b/src/mintdb/perf_taler_mintdb_init.h @@ -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); /** diff --git a/src/mintdb/perf_taler_mintdb_interpreter.c b/src/mintdb/perf_taler_mintdb_interpreter.c index 4a61bbdab..5715a5ed8 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.c +++ b/src/mintdb/perf_taler_mintdb_interpreter.c @@ -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; diff --git a/src/mintdb/perf_taler_mintdb_interpreter.h b/src/mintdb/perf_taler_mintdb_interpreter.h index bde6ca238..b9042262a 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.h +++ b/src/mintdb/perf_taler_mintdb_interpreter.h @@ -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 */ |