diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001.sql | 7 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 41 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 108 |
3 files changed, 117 insertions, 39 deletions
diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 51fd26ec..a8e79335 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -297,17 +297,14 @@ COMMENT ON TABLE signkey_revocations CREATE TABLE IF NOT EXISTS extensions (extension_id BIGSERIAL UNIQUE ,name VARCHAR NOT NULL UNIQUE - ,config BYTEA NOT NULL - ,config_sig BYTEA NOT NULL + ,config BYTEA ); COMMENT ON TABLE extensions IS 'Configurations of the activated extensions'; COMMENT ON COLUMN extensions.name IS 'Name of the extension'; COMMENT ON COLUMN extensions.config - IS 'Configuration of the extension as JSON-blob'; -COMMENT ON COLUMN extensions.config - IS 'Signature of the configuration of an extension, signed with the master key of the exchange'; + IS 'Configuration of the extension as JSON-blob, maybe NULL'; CREATE TABLE IF NOT EXISTS known_coins diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 4b009607..918fc38c 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -2745,15 +2745,17 @@ prepare_statements (struct PostgresClosure *pg) /* Used in #postgres_set_extension_config */ GNUNET_PQ_make_prepare ( "set_extension_config", - "INSERT INTO extensions (name, config, config_sig) VALUES ($1, $2, $3) " + "INSERT INTO extensions (name, config) VALUES ($1, $2) " "ON CONFLICT (name) " - "DO UPDATE SET (config, config_sig) = ($2, $3)", - 3), + "DO UPDATE SET config=$2", + 2), /* Used in #postgres_get_extension_config */ GNUNET_PQ_make_prepare ( "get_extension_config", - "SELECT (config) FROM extensions" - " WHERE name=$1;", + "SELECT " + " config " + "FROM extensions" + " WHERE name=$1;", 1), GNUNET_PQ_PREPARED_STATEMENT_END }; @@ -11410,20 +11412,20 @@ postgres_delete_shard_locks (void *cls) * @param cls the @e cls of this struct with the plugin-specific state * @param extension_name the name of the extension * @param config JSON object of the configuration as string - * @param config_sig signature of the configuration by the offline master key * @return transaction status code */ enum GNUNET_DB_QueryStatus postgres_set_extension_config (void *cls, const char *extension_name, - const char *config, - const struct TALER_MasterSignatureP *config_sig) + const char *config) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam pcfg = (NULL == config || 0 == *config) ? + GNUNET_PQ_query_param_null () : + GNUNET_PQ_query_param_string (config); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (extension_name), - GNUNET_PQ_query_param_string (config), - GNUNET_PQ_query_param_auto_from_type (config_sig), + pcfg, GNUNET_PQ_query_param_end }; @@ -11452,15 +11454,24 @@ postgres_get_extension_config (void *cls, GNUNET_PQ_query_param_string (extension_name), GNUNET_PQ_query_param_end }; + bool is_null; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("config", config), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("config", config), + &is_null), GNUNET_PQ_result_spec_end }; + enum GNUNET_DB_QueryStatus qs; - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_extension_config", - params, - rs); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "get_extension_config", + params, + rs); + if (is_null) + { + *config = NULL; + } + return qs; } diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 6724e7b4..cca7c3f4 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -109,6 +109,63 @@ mark_prepare_cb (void *cls, /** + * Simple check that config retrieval and setting for extensions work + */ +static enum GNUNET_GenericReturnValue +test_extension_config (void) +{ + char *config; + + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->get_extension_config (plugin->cls, + "fnord", + &config)); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->set_extension_config (plugin->cls, + "fnord", + "bar")); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->get_extension_config (plugin->cls, + "fnord", + &config)); + + FAILIF (0 != strcmp ("bar", config)); + + /* let's do this again! */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->set_extension_config (plugin->cls, + "fnord", + "buzz")); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->get_extension_config (plugin->cls, + "fnord", + &config)); + + FAILIF (0 != strcmp ("buzz", config)); + + /* let's do this again, with NULL */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->set_extension_config (plugin->cls, + "fnord", + NULL)); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->get_extension_config (plugin->cls, + "fnord", + &config)); + + FAILIF (NULL != config); + + return GNUNET_OK; +drop: + return GNUNET_SYSERR; +} + + +/** * Test API relating to persisting the wire plugins preparation data. * * @return #GNUNET_OK on success @@ -1334,6 +1391,10 @@ run (void *cls) 0, &recoup_cb, NULL)); + /* simple extension check */ + FAILIF (GNUNET_OK != + test_extension_config ()); + RND_BLK (&reserve_pub); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":1.000010", @@ -1406,27 +1467,36 @@ run (void *cls) { struct TALER_PlanchetDetail pd; struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_AgeHash age_hash; + struct TALER_AgeHash *p_ah[2] = {NULL, &age_hash}; - RND_BLK (&coin_pub); - TALER_blinding_secret_create (&bks); - GNUNET_assert (GNUNET_OK == - TALER_denom_blind (&dkp->pub, - &bks, - NULL, /* FIXME-Oec */ - &coin_pub, - &c_hash, - &pd.coin_ev, - &pd.coin_ev_size)); - TALER_coin_ev_hash (pd.coin_ev, - pd.coin_ev_size, - &cbc.h_coin_envelope); - GNUNET_assert (GNUNET_OK == - TALER_denom_sign_blinded (&cbc.sig, - &dkp->priv, - pd.coin_ev, - pd.coin_ev_size)); - GNUNET_free (pd.coin_ev); + /* Call TALER_denom_blind()/TALER_denom_sign_blinded() twice, once without + * age_hash, once with age_hash */ + RND_BLK (&age_hash); + for (size_t i = 0; i < sizeof(p_ah) / sizeof(p_ah[0]); i++) + { + RND_BLK (&coin_pub); + TALER_blinding_secret_create (&bks); + GNUNET_assert (GNUNET_OK == + TALER_denom_blind (&dkp->pub, + &bks, + p_ah[i], + &coin_pub, + &c_hash, + &pd.coin_ev, + &pd.coin_ev_size)); + TALER_coin_ev_hash (pd.coin_ev, + pd.coin_ev_size, + &cbc.h_coin_envelope); + GNUNET_assert (GNUNET_OK == + TALER_denom_sign_blinded (&cbc.sig, + &dkp->priv, + pd.coin_ev, + pd.coin_ev_size)); + GNUNET_free (pd.coin_ev); + } } + cbc.reserve_pub = reserve_pub; cbc.amount_with_fee = value; GNUNET_assert (GNUNET_OK == |