summaryrefslogtreecommitdiff
path: root/src/auditor/report-lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/report-lib.c')
-rw-r--r--src/auditor/report-lib.c301
1 files changed, 95 insertions, 206 deletions
diff --git a/src/auditor/report-lib.c b/src/auditor/report-lib.c
index 4addce9e2..d0e1325ea 100644
--- a/src/auditor/report-lib.c
+++ b/src/auditor/report-lib.c
@@ -62,13 +62,18 @@ struct TALER_AuditorPublicKeyP TALER_ARL_auditor_pub;
char *TALER_ARL_auditor_url;
/**
+ * REST API endpoint of the exchange.
+ */
+char *TALER_ARL_exchange_url;
+
+/**
* At what time did the auditor process start?
*/
struct GNUNET_TIME_Absolute start_time;
/**
* Results about denominations, cached per-transaction, maps denomination pub hashes
- * to `struct TALER_DenominationKeyValidityPS`.
+ * to `const struct TALER_EXCHANGEDB_DenominationKeyInformation`.
*/
static struct GNUNET_CONTAINER_MultiHashMap *denominations;
@@ -89,13 +94,6 @@ static struct GNUNET_SIGNAL_Context *sig_int;
static struct GNUNET_SIGNAL_Context *sig_term;
-/**
- * Test if the audit should be aborted because the user
- * pressed CTRL-C.
- *
- * @return false to continue the audit, true to terminate
- * cleanly as soon as possible
- */
bool
TALER_ARL_do_abort (void)
{
@@ -103,12 +101,6 @@ TALER_ARL_do_abort (void)
}
-/**
- * Add @a object to the report @a array. Fail hard if this fails.
- *
- * @param array report array to append @a object to
- * @param object object to append, should be check that it is not NULL
- */
void
TALER_ARL_report (json_t *array,
json_t *object)
@@ -127,74 +119,55 @@ TALER_ARL_report (json_t *array,
*
* @param cls closure, NULL
* @param denom_pub public key, sometimes NULL (!)
- * @param validity issuing information with value, fees and other info about the denomination.
+ * @param issue issuing information with value, fees and other info about the denomination.
*/
static void
add_denomination (
void *cls,
const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyInformationP *validity)
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue)
{
- const struct TALER_DenominationKeyValidityPS *issue = &validity->properties;
-
(void) cls;
(void) denom_pub;
if (NULL !=
GNUNET_CONTAINER_multihashmap_get (denominations,
- &issue->denom_hash))
+ &issue->denom_hash.hash))
return; /* value already known */
#if GNUNET_EXTRA_LOGGING >= 1
{
- struct TALER_Amount value;
-
- TALER_amount_ntoh (&value,
- &issue->value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Tracking denomination `%s' (%s)\n",
- GNUNET_h2s (&issue->denom_hash),
- TALER_amount2s (&value));
- TALER_amount_ntoh (&value,
- &issue->fee_withdraw);
+ GNUNET_h2s (&issue->denom_hash.hash),
+ TALER_amount2s (&issue->value));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Withdraw fee is %s\n",
- TALER_amount2s (&value));
+ TALER_amount2s (&issue->fees.withdraw));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Start time is %s\n",
- GNUNET_STRINGS_absolute_time_to_string
- (GNUNET_TIME_absolute_ntoh (issue->start)));
+ GNUNET_TIME_timestamp2s (issue->start));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Expire deposit time is %s\n",
- GNUNET_STRINGS_absolute_time_to_string
- (GNUNET_TIME_absolute_ntoh (issue->expire_deposit)));
+ GNUNET_TIME_timestamp2s (issue->expire_deposit));
}
#endif
{
- struct TALER_DenominationKeyValidityPS *i;
+ struct TALER_EXCHANGEDB_DenominationKeyInformation *i;
- i = GNUNET_new (struct TALER_DenominationKeyValidityPS);
+ i = GNUNET_new (struct TALER_EXCHANGEDB_DenominationKeyInformation);
*i = *issue;
- i->master = TALER_ARL_master_pub;
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (denominations,
- &issue->denom_hash,
+ &issue->denom_hash.hash,
i,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
}
-/**
- * Obtain information about a @a denom_pub.
- *
- * @param dh hash of the denomination public key to look up
- * @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must
- * NOT be freed by caller
- * @return transaction status code
- */
enum GNUNET_DB_QueryStatus
TALER_ARL_get_denomination_info_by_hash (
- const struct GNUNET_HashCode *dh,
- const struct TALER_DenominationKeyValidityPS **issue)
+ const struct TALER_DenominationHashP *dh,
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation **issue)
{
enum GNUNET_DB_QueryStatus qs;
@@ -207,15 +180,16 @@ TALER_ARL_get_denomination_info_by_hash (
NULL);
if (0 > qs)
{
+ GNUNET_break (0);
*issue = NULL;
return qs;
}
}
{
- const struct TALER_DenominationKeyValidityPS *i;
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *i;
i = GNUNET_CONTAINER_multihashmap_get (denominations,
- dh);
+ &dh->hash);
if (NULL != i)
{
/* cache hit */
@@ -225,13 +199,14 @@ TALER_ARL_get_denomination_info_by_hash (
}
/* maybe database changed since we last iterated, give it one more shot */
{
- struct TALER_EXCHANGEDB_DenominationKeyInformationP issue;
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue;
qs = TALER_ARL_edb->get_denomination_info (TALER_ARL_edb->cls,
dh,
&issue);
if (qs <= 0)
{
+ GNUNET_break (qs >= 0);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Denomination %s not found\n",
@@ -243,10 +218,10 @@ TALER_ARL_get_denomination_info_by_hash (
&issue);
}
{
- const struct TALER_DenominationKeyValidityPS *i;
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *i;
i = GNUNET_CONTAINER_multihashmap_get (denominations,
- dh);
+ &dh->hash);
if (NULL != i)
{
/* cache hit */
@@ -262,27 +237,18 @@ TALER_ARL_get_denomination_info_by_hash (
}
-/**
- * Obtain information about a @a denom_pub.
- *
- * @param denom_pub key to look up
- * @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must
- * NOT be freed by caller
- * @param[out] dh set to the hash of @a denom_pub, may be NULL
- * @return transaction status code
- */
enum GNUNET_DB_QueryStatus
TALER_ARL_get_denomination_info (
const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_DenominationKeyValidityPS **issue,
- struct GNUNET_HashCode *dh)
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation **issue,
+ struct TALER_DenominationHashP *dh)
{
- struct GNUNET_HashCode hc;
+ struct TALER_DenominationHashP hc;
if (NULL == dh)
dh = &hc;
- GNUNET_CRYPTO_rsa_public_key_hash (denom_pub->rsa_public_key,
- dh);
+ TALER_denom_pub_hash (denom_pub,
+ dh);
return TALER_ARL_get_denomination_info_by_hash (dh,
issue);
}
@@ -294,11 +260,11 @@ TALER_ARL_get_denomination_info (
*
* @param analysis analysis to run
* @param analysis_cls closure for @a analysis
- * @return #GNUNET_OK if @a analysis succeessfully committed,
+ * @return #GNUNET_OK if @a analysis successfully committed,
* #GNUNET_NO if we had an error on commit (retry may help)
* #GNUNET_SYSERR on hard errors
*/
-static int
+static enum GNUNET_GenericReturnValue
transact (TALER_ARL_Analysis analysis,
void *analysis_cls)
{
@@ -369,14 +335,7 @@ transact (TALER_ARL_Analysis analysis,
}
-/**
- * Initialize DB sessions and run the analysis.
- *
- * @param ana analysis to run
- * @param ana_cls closure for @a ana
- * @return #GNUNET_OK on success
- */
-int
+enum GNUNET_GenericReturnValue
TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
void *ana_cls)
{
@@ -402,41 +361,6 @@ TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
}
-/**
- * Test if the given @a mpub matches the #TALER_ARL_master_pub.
- * If so, set "found" to GNUNET_YES.
- *
- * @param cls a `int *` pointing to "found"
- * @param mpub exchange master public key to compare
- * @param exchange_url URL of the exchange (ignored)
- */
-static void
-test_master_present (void *cls,
- const struct TALER_MasterPublicKeyP *mpub,
- const char *exchange_url)
-{
- int *found = cls;
-
- (void) exchange_url;
- if (0 == GNUNET_memcmp (mpub,
- &TALER_ARL_master_pub))
- *found = GNUNET_YES;
-}
-
-
-/**
- * Perform addition of amounts. If the addition fails, logs
- * a detailed error and calls exit() to terminate the process (!).
- *
- * Do not call this function directly, use #TALER_ARL_amount_add().
- *
- * @param[out] sum where to store @a a1 + @a a2, set to "invalid" on overflow
- * @param a1 first amount to add
- * @param a2 second amount to add
- * @param filename where is the addition called
- * @param functionname name of the function where the addition is called
- * @param line line number of the addition
- */
void
TALER_ARL_amount_add_ (struct TALER_Amount *sum,
const struct TALER_Amount *a1,
@@ -485,19 +409,6 @@ TALER_ARL_amount_add_ (struct TALER_Amount *sum,
}
-/**
- * Perform subtraction of amounts. If the subtraction fails, logs
- * a detailed error and calls exit() to terminate the process (!).
- *
- * Do not call this function directly, use #TALER_ARL_amount_subtract().
- *
- * @param[out] diff where to store (@a a1 - @a a2)
- * @param a1 amount to subtract from
- * @param a2 amount to subtract
- * @param filename where is the addition called
- * @param functionname name of the function where the addition is called
- * @param line line number of the addition
- */
void
TALER_ARL_amount_subtract_ (struct TALER_Amount *diff,
const struct TALER_Amount *a1,
@@ -546,24 +457,6 @@ TALER_ARL_amount_subtract_ (struct TALER_Amount *diff,
}
-/**
- * Perform subtraction of amounts. Negative results should be signalled by the
- * return value (leaving @a diff set to 'invalid'). If the subtraction fails
- * for other reasons (currency mismatch, normalization failure), logs a
- * detailed error and calls exit() to terminate the process (!).
- *
- * Do not call this function directly, use #TALER_ARL_amount_subtract_neg().
- *
- * @param[out] diff where to store (@a a1 - @a a2)
- * @param a1 amount to subtract from
- * @param a2 amount to subtract
- * @param filename where is the addition called
- * @param functionname name of the function where the addition is called
- * @param line line number of the addition
- * @return #TALER_ARL_SR_INVALID_NEGATIVE if the result was negative (and @a diff is now invalid),
- * #TALER_ARL_SR_ZERO if the result was zero,
- * #TALER_ARL_SR_POSITIVE if the result is positive
- */
enum TALER_ARL_SubtractionResult
TALER_ARL_amount_subtract_neg_ (struct TALER_Amount *diff,
const struct TALER_Amount *a1,
@@ -622,13 +515,7 @@ handle_sigint (void)
}
-/**
- * Setup global variables based on configuration.
- *
- * @param c configuration to use
- * @return #GNUNET_OK on success
- */
-int
+enum GNUNET_GenericReturnValue
TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
{
TALER_ARL_cfg = c;
@@ -645,7 +532,19 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
"BASE_URL");
return GNUNET_SYSERR;
}
- if (GNUNET_YES == GNUNET_is_zero (&TALER_ARL_master_pub))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (TALER_ARL_cfg,
+ "exchange",
+ "BASE_URL",
+ &TALER_ARL_exchange_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+
+ if (GNUNET_is_zero (&TALER_ARL_master_pub))
{
/* -m option not given, try configuration */
char *master_public_key_str;
@@ -676,6 +575,9 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
GNUNET_free (master_public_key_str);
return GNUNET_SYSERR;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running auditor against exchange master public key `%s'\n",
+ master_public_key_str);
GNUNET_free (master_public_key_str);
} /* end of -m not given */
@@ -683,8 +585,36 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
"Taler auditor running for exchange master public key %s\n",
TALER_B2S (&TALER_ARL_master_pub));
- if (GNUNET_YES == GNUNET_is_zero (&TALER_ARL_auditor_pub))
+ if (GNUNET_is_zero (&TALER_ARL_auditor_pub))
{
+ char *auditor_public_key_str;
+
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (c,
+ "auditor",
+ "PUBLIC_KEY",
+ &auditor_public_key_str))
+ {
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (
+ auditor_public_key_str,
+ strlen (auditor_public_key_str),
+ &TALER_ARL_auditor_pub.eddsa_pub))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "auditor",
+ "PUBLIC_KEY",
+ "invalid key");
+ GNUNET_free (auditor_public_key_str);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (auditor_public_key_str);
+ }
+ }
+
+ if (GNUNET_is_zero (&TALER_ARL_auditor_pub))
+ {
+ /* public key not configured */
/* try loading private key and deriving public key */
char *fn;
@@ -696,6 +626,9 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
{
struct TALER_AuditorPrivateKeyP auditor_priv;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Loading offline private key from `%s' to get auditor public key\n",
+ fn);
if (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_key_from_file (fn,
GNUNET_NO, /* do NOT create it! */
@@ -708,36 +641,12 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
}
}
- if (GNUNET_YES == GNUNET_is_zero (&TALER_ARL_auditor_pub))
+ if (GNUNET_is_zero (&TALER_ARL_auditor_pub))
{
- /* private key not available, try configuration for public key */
- char *auditor_public_key_str;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (c,
- "auditor",
- "PUBLIC_KEY",
- &auditor_public_key_str))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "PUBLIC_KEY");
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (
- auditor_public_key_str,
- strlen (auditor_public_key_str),
- &TALER_ARL_auditor_pub.eddsa_pub))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "PUBLIC_KEY",
- "invalid key");
- GNUNET_free (auditor_public_key_str);
- return GNUNET_SYSERR;
- }
- GNUNET_free (auditor_public_key_str);
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
+ "auditor",
+ "PUBLIC_KEY/AUDITOR_PRIV_FILE");
+ return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -794,39 +703,18 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
TALER_ARL_done (NULL);
return GNUNET_SYSERR;
}
+ if (GNUNET_SYSERR ==
+ TALER_ARL_adb->preflight (TALER_ARL_adb->cls))
{
- int found;
-
- if (GNUNET_SYSERR ==
- TALER_ARL_adb->preflight (TALER_ARL_adb->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to start session with auditor database.\n");
- TALER_ARL_done (NULL);
- return GNUNET_SYSERR;
- }
- found = GNUNET_NO;
- (void) TALER_ARL_adb->list_exchanges (TALER_ARL_adb->cls,
- &test_master_present,
- &found);
- if (GNUNET_NO == found)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Exchange's master public key `%s' not known to auditor DB. Did you forget to run `taler-auditor-exchange`?\n",
- GNUNET_p2s (&TALER_ARL_master_pub.eddsa_pub));
- TALER_ARL_done (NULL);
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start session with auditor database.\n");
+ TALER_ARL_done (NULL);
+ return GNUNET_SYSERR;
}
return GNUNET_OK;
}
-/**
- * Generate the report and close connectios to the database.
- *
- * @param report the report to output, may be NULL for no report
- */
void
TALER_ARL_done (json_t *report)
{
@@ -859,6 +747,7 @@ TALER_ARL_done (json_t *report)
JSON_INDENT (2));
json_decref (report);
}
+ GNUNET_free (TALER_ARL_exchange_url);
GNUNET_free (TALER_ARL_auditor_url);
}