diff options
Diffstat (limited to 'src/testing/testing_api_cmd_insert_deposit.c')
-rw-r--r-- | src/testing/testing_api_cmd_insert_deposit.c | 355 |
1 files changed, 200 insertions, 155 deletions
diff --git a/src/testing/testing_api_cmd_insert_deposit.c b/src/testing/testing_api_cmd_insert_deposit.c index 0d57ab6c4..03e704c72 100644 --- a/src/testing/testing_api_cmd_insert_deposit.c +++ b/src/testing/testing_api_cmd_insert_deposit.c @@ -29,6 +29,7 @@ #include "taler_signatures.h" #include "taler_testing_lib.h" #include "taler_exchangedb_plugin.h" +#include "taler_exchangedb_lib.h" /** @@ -37,9 +38,9 @@ struct InsertDepositState { /** - * Configuration file used by the command. + * Database connection we use. */ - const struct TALER_TESTING_DatabaseConnection *dbc; + struct TALER_EXCHANGEDB_Plugin *plugin; /** * Human-readable name of the shop. @@ -60,7 +61,7 @@ struct InsertDepositState /** * When did the exchange receive the deposit? */ - struct GNUNET_TIME_Absolute exchange_timestamp; + struct GNUNET_TIME_Timestamp exchange_timestamp; /** * Amount to deposit, inclusive of deposit fee. @@ -71,6 +72,11 @@ struct InsertDepositState * Deposit fee. */ const char *deposit_fee; + + /** + * Do we used a cached @e plugin? + */ + bool cached; }; /** @@ -79,44 +85,37 @@ struct InsertDepositState * @param[out] issue information to initialize with "valid" data */ static void -fake_issue (struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) +fake_issue (struct TALER_EXCHANGEDB_DenominationKeyInformation *issue) { - struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Timestamp now; memset (issue, 0, - sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP)); - now = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&now); - issue->properties.start - = GNUNET_TIME_absolute_hton (now); - issue->properties.expire_withdraw - = GNUNET_TIME_absolute_hton ( - GNUNET_TIME_absolute_add (now, - GNUNET_TIME_UNIT_MINUTES)); - issue->properties.expire_deposit - = GNUNET_TIME_absolute_hton ( - GNUNET_TIME_absolute_add (now, - GNUNET_TIME_UNIT_HOURS)); - issue->properties.expire_legal - = GNUNET_TIME_absolute_hton ( - GNUNET_TIME_absolute_add (now, - GNUNET_TIME_UNIT_DAYS)); + sizeof (*issue)); + now = GNUNET_TIME_timestamp_get (); + issue->start + = now; + issue->expire_withdraw + = GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_MINUTES); + issue->expire_deposit + = GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_HOURS); + issue->expire_legal + = GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_DAYS); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount_nbo ("EUR:1", - &issue->properties.value)); + TALER_string_to_amount ("EUR:1", + &issue->value)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount_nbo ("EUR:0.1", - &issue->properties.fee_withdraw)); + TALER_string_to_amount ("EUR:0.1", + &issue->fees.withdraw)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount_nbo ("EUR:0.1", - &issue->properties.fee_deposit)); + TALER_string_to_amount ("EUR:0.1", + &issue->fees.deposit)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount_nbo ("EUR:0.1", - &issue->properties.fee_refresh)); + TALER_string_to_amount ("EUR:0.1", + &issue->fees.refresh)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount_nbo ("EUR:0.1", - &issue->properties.fee_refund)); + TALER_string_to_amount ("EUR:0.1", + &issue->fees.refund)); } @@ -133,31 +132,50 @@ insert_deposit_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct InsertDepositState *ids = cls; - struct TALER_EXCHANGEDB_Deposit deposit; + struct TALER_EXCHANGEDB_CoinDepositInformation deposit; + struct TALER_EXCHANGEDB_BatchDeposit bd; struct TALER_MerchantPrivateKeyP merchant_priv; - struct TALER_EXCHANGEDB_DenominationKeyInformationP issue; + struct TALER_EXCHANGEDB_DenominationKeyInformation issue; struct TALER_DenominationPublicKey dpk; - struct GNUNET_CRYPTO_RsaPrivateKey *denom_priv; - struct GNUNET_HashCode hc; + struct TALER_DenominationPrivateKey denom_priv; + char *receiver_wire_account; - // prepare and store issue first. + (void) cmd; + if (NULL == ids->plugin) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + if (GNUNET_OK != + ids->plugin->preflight (ids->plugin->cls)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } fake_issue (&issue); - denom_priv = GNUNET_CRYPTO_rsa_private_key_create (1024); - dpk.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public (denom_priv); - GNUNET_CRYPTO_rsa_public_key_hash (dpk.rsa_public_key, - &issue.properties.denom_hash); + GNUNET_assert (GNUNET_OK == + TALER_denom_priv_create (&denom_priv, + &dpk, + GNUNET_CRYPTO_BSA_RSA, + 1024)); + TALER_denom_pub_hash (&dpk, + &issue.denom_hash); if ( (GNUNET_OK != - ids->dbc->plugin->start (ids->dbc->plugin->cls, - "talertestinglib: denomination insertion")) || + ids->plugin->start (ids->plugin->cls, + "talertestinglib: denomination insertion")) || (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls, - &dpk, - &issue)) || + ids->plugin->insert_denomination_info (ids->plugin->cls, + &dpk, + &issue)) || (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - ids->dbc->plugin->commit (ids->dbc->plugin->cls)) ) + ids->plugin->commit (ids->plugin->cls)) ) { TALER_TESTING_interpreter_fail (is); + TALER_denom_pub_free (&dpk); + TALER_denom_priv_free (&denom_priv); return; } @@ -165,87 +183,132 @@ insert_deposit_run (void *cls, memset (&deposit, 0, sizeof (deposit)); - - GNUNET_CRYPTO_kdf (&merchant_priv, - sizeof (struct TALER_MerchantPrivateKeyP), - "merchant-priv", - strlen ("merchant-priv"), - ids->merchant_name, - strlen (ids->merchant_name), - NULL, - 0); + memset (&bd, + 0, + sizeof (bd)); + bd.cdis = &deposit; + bd.num_cdis = 1; + + GNUNET_assert ( + GNUNET_YES == + GNUNET_CRYPTO_kdf (&merchant_priv, + sizeof (struct TALER_MerchantPrivateKeyP), + "merchant-priv", + strlen ("merchant-priv"), + ids->merchant_name, + strlen (ids->merchant_name), + NULL, + 0)); GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv, - &deposit.merchant_pub.eddsa_pub); + &bd.merchant_pub.eddsa_pub); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &deposit.h_contract_terms); - if ( (GNUNET_OK != - TALER_string_to_amount (ids->amount_with_fee, - &deposit.amount_with_fee)) || - (GNUNET_OK != - TALER_string_to_amount (ids->deposit_fee, - &deposit.deposit_fee)) ) + &bd.h_contract_terms.hash); + if (GNUNET_OK != + TALER_string_to_amount (ids->amount_with_fee, + &deposit.amount_with_fee)) { TALER_TESTING_interpreter_fail (is); + TALER_denom_pub_free (&dpk); + TALER_denom_priv_free (&denom_priv); return; } - GNUNET_CRYPTO_rsa_public_key_hash (dpk.rsa_public_key, - &deposit.coin.denom_pub_hash); + TALER_denom_pub_hash (&dpk, + &deposit.coin.denom_pub_hash); GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &deposit.coin.coin_pub, sizeof (deposit.coin.coin_pub)); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, - &hc); - deposit.coin.denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign_fdh (denom_priv, - &hc); { - char *str; - - GNUNET_asprintf (&str, - "payto://x-taler-bank/localhost/%s", - ids->merchant_account); - deposit.receiver_wire_account - = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("salt", - "this-is-a-salt-value"), - GNUNET_JSON_pack_string ("payto_uri", - str)); - GNUNET_free (str); + struct TALER_CoinPubHashP c_hash; + struct TALER_PlanchetDetail pd; + struct TALER_BlindedDenominationSignature bds; + struct TALER_PlanchetMasterSecretP ps; + union GNUNET_CRYPTO_BlindingSecretP bks; + const struct TALER_ExchangeWithdrawValues *alg_values; + + alg_values = TALER_denom_ewv_rsa_singleton (); + TALER_planchet_blinding_secret_create (&ps, + alg_values, + &bks); + GNUNET_assert (GNUNET_OK == + TALER_denom_blind (&dpk, + &bks, + NULL, /* no age restriction active */ + NULL, /* no nonce needed */ + &deposit.coin.coin_pub, + alg_values, + &c_hash, + &pd.blinded_planchet)); + GNUNET_assert (GNUNET_OK == + TALER_denom_sign_blinded (&bds, + &denom_priv, + false, + &pd.blinded_planchet)); + TALER_blinded_planchet_free (&pd.blinded_planchet); + GNUNET_assert (GNUNET_OK == + TALER_denom_sig_unblind (&deposit.coin.denom_sig, + &bds, + &bks, + &c_hash, + alg_values, + &dpk)); + TALER_blinded_denom_sig_free (&bds); } - - GNUNET_assert (GNUNET_OK == - TALER_JSON_merchant_wire_signature_hash ( - deposit.receiver_wire_account, - &deposit.h_wire)); - deposit.timestamp = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&deposit.timestamp); - deposit.wire_deadline = GNUNET_TIME_relative_to_absolute (ids->wire_deadline); - (void) GNUNET_TIME_round_abs (&deposit.wire_deadline); - + GNUNET_asprintf (&receiver_wire_account, + "payto://x-taler-bank/localhost/%s?receiver-name=%s", + ids->merchant_account, + ids->merchant_account); + bd.receiver_wire_account = receiver_wire_account; + TALER_payto_hash (bd.receiver_wire_account, + &bd.wire_target_h_payto); + memset (&bd.wire_salt, + 46, + sizeof (bd.wire_salt)); + bd.wallet_timestamp = GNUNET_TIME_timestamp_get (); + bd.wire_deadline = GNUNET_TIME_relative_to_timestamp ( + ids->wire_deadline); /* finally, actually perform the DB operation */ - if ( (GNUNET_OK != - ids->dbc->plugin->start (ids->dbc->plugin->cls, - "libtalertesting: insert deposit")) || - (0 > - ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls, - &deposit.coin)) || - (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls, - ids->exchange_timestamp, - &deposit)) || - (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - ids->dbc->plugin->commit (ids->dbc->plugin->cls)) ) { - GNUNET_break (0); - ids->dbc->plugin->rollback (ids->dbc->plugin->cls); - TALER_TESTING_interpreter_fail (is); + uint64_t known_coin_id; + struct TALER_DenominationHashP dph; + struct TALER_AgeCommitmentHash agh; + bool balance_ok; + uint32_t bad_index; + bool ctr_conflict; + + if ( (GNUNET_OK != + ids->plugin->start (ids->plugin->cls, + "libtalertesting: insert deposit")) || + (0 > + ids->plugin->ensure_coin_known (ids->plugin->cls, + &deposit.coin, + &known_coin_id, + &dph, + &agh)) || + (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + ids->plugin->do_deposit (ids->plugin->cls, + &bd, + &ids->exchange_timestamp, + &balance_ok, + &bad_index, + &ctr_conflict)) || + (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + ids->plugin->commit (ids->plugin->cls)) ) + { + GNUNET_break (0); + ids->plugin->rollback (ids->plugin->cls); + GNUNET_free (receiver_wire_account); + TALER_denom_pub_free (&dpk); + TALER_denom_priv_free (&denom_priv); + TALER_TESTING_interpreter_fail (is); + return; + } } - GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig.rsa_signature); - GNUNET_CRYPTO_rsa_public_key_free (dpk.rsa_public_key); - GNUNET_CRYPTO_rsa_private_key_free (denom_priv); - json_decref (deposit.receiver_wire_account); - + TALER_denom_sig_free (&deposit.coin.denom_sig); + TALER_denom_pub_free (&dpk); + TALER_denom_priv_free (&denom_priv); + GNUNET_free (receiver_wire_account); TALER_TESTING_interpreter_next (is); } @@ -263,63 +326,46 @@ insert_deposit_cleanup (void *cls, { struct InsertDepositState *ids = cls; + (void) cmd; + if ( (NULL != ids->plugin) && + (! ids->cached) ) + { + // FIXME: historically, we also did: + // ids->plugin->drop_tables (ids->plugin->cls); + TALER_EXCHANGEDB_plugin_unload (ids->plugin); + ids->plugin = NULL; + } GNUNET_free (ids); } -/** - * Offer "insert-deposit" CMD internal data to other commands. - * - * @param cls closure. - * @param[out] ret result - * @param trait name of the trait. - * @param index index number of the object to offer. - * @return #GNUNET_OK on success. - */ -static int -insert_deposit_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - (void) cls; - (void) ret; - (void) trait; - (void) index; - return GNUNET_NO; -} - - -/** - * Make the "insert-deposit" CMD. - * - * @param label command label. - * @param dbc collects database plugin - * @param merchant_name Human-readable name of the merchant. - * @param merchant_account merchant's account name (NOT a payto:// URI) - * @param exchange_timestamp when did the exchange receive the deposit - * @param wire_deadline point in time where the aggregator should have - * wired money to the merchant. - * @param amount_with_fee amount to deposit (inclusive of deposit fee) - * @param deposit_fee deposit fee - * @return the command. - */ struct TALER_TESTING_Command TALER_TESTING_cmd_insert_deposit ( const char *label, - const struct TALER_TESTING_DatabaseConnection *dbc, + const struct GNUNET_CONFIGURATION_Handle *db_cfg, const char *merchant_name, const char *merchant_account, - struct GNUNET_TIME_Absolute exchange_timestamp, + struct GNUNET_TIME_Timestamp exchange_timestamp, struct GNUNET_TIME_Relative wire_deadline, const char *amount_with_fee, const char *deposit_fee) { + static struct TALER_EXCHANGEDB_Plugin *pluginc; + static const struct GNUNET_CONFIGURATION_Handle *db_cfgc; struct InsertDepositState *ids; - GNUNET_TIME_round_abs (&exchange_timestamp); ids = GNUNET_new (struct InsertDepositState); - ids->dbc = dbc; + if (db_cfgc == db_cfg) + { + ids->plugin = pluginc; + ids->cached = true; + } + else + { + ids->plugin = TALER_EXCHANGEDB_plugin_load (db_cfg); + pluginc = ids->plugin; + db_cfgc = db_cfg; + } ids->merchant_name = merchant_name; ids->merchant_account = merchant_account; ids->exchange_timestamp = exchange_timestamp; @@ -332,8 +378,7 @@ TALER_TESTING_cmd_insert_deposit ( .cls = ids, .label = label, .run = &insert_deposit_run, - .cleanup = &insert_deposit_cleanup, - .traits = &insert_deposit_traits + .cleanup = &insert_deposit_cleanup }; return cmd; |