From f299130c50ca79efbfc8daf7f73aaba7ffb3a258 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 12 Nov 2017 14:11:05 +0100 Subject: make -m option optional for taler-auditor and taler-wire-auditor --- src/auditor/taler-auditor.c | 47 +++++++++++++++++++++++++++++++++++----- src/auditor/taler-wire-auditor.c | 47 +++++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 12 deletions(-) (limited to 'src/auditor') diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index d33b23dff..faaf55193 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -3901,12 +3901,48 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { + static const struct TALER_MasterPublicKeyP zeromp; struct TALER_Amount income_fee_total; json_t *report; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching auditor\n"); cfg = c; + if (0 == memcmp (&zeromp, + &master_pub, + sizeof (struct TALER_MasterPublicKeyP))) + { + /* -m option not given, try configuration */ + char *master_public_key_str; + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "exchange", + "MASTER_PUBLIC_KEY", + &master_public_key_str)) + { + fprintf (stderr, + "Pass option -m or set it in the configuration!\n"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchange", + "MASTER_PUBLIC_KEY"); + global_ret = 1; + return; + } + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_public_key_from_string (master_public_key_str, + strlen (master_public_key_str), + &master_pub.eddsa_pub)) + { + fprintf (stderr, + "Invalid master public key given in configuration file."); + GNUNET_free (master_public_key_str); + global_ret = 1; + return; + } + GNUNET_free (master_public_key_str); + } /* end of -m not given */ + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "taler", @@ -4163,12 +4199,11 @@ main (int argc, char *const *argv) { const struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_mandatory - (GNUNET_GETOPT_option_base32_auto ('m', - "exchange-key", - "KEY", - "public key of the exchange (Crockford base32 encoded)", - &master_pub)), + GNUNET_GETOPT_option_base32_auto ('m', + "exchange-key", + "KEY", + "public key of the exchange (Crockford base32 encoded)", + &master_pub), GNUNET_GETOPT_option_flag ('r', "restart", "restart audit from the beginning (required on first run)", diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c index f34fc7e71..4ee92566e 100644 --- a/src/auditor/taler-wire-auditor.c +++ b/src/auditor/taler-wire-auditor.c @@ -1091,12 +1091,48 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { + static const struct TALER_MasterPublicKeyP zeromp; enum GNUNET_DB_QueryStatus qs; int ret; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching auditor\n"); cfg = c; + if (0 == memcmp (&zeromp, + &master_pub, + sizeof (struct TALER_MasterPublicKeyP))) + { + /* -m option not given, try configuration */ + char *master_public_key_str; + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "exchange", + "MASTER_PUBLIC_KEY", + &master_public_key_str)) + { + fprintf (stderr, + "Pass option -m or set it in the configuration!\n"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchange", + "MASTER_PUBLIC_KEY"); + global_ret = 1; + return; + } + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_public_key_from_string (master_public_key_str, + strlen (master_public_key_str), + &master_pub.eddsa_pub)) + { + fprintf (stderr, + "Invalid master public key given in configuration file."); + GNUNET_free (master_public_key_str); + global_ret = 1; + return; + } + GNUNET_free (master_public_key_str); + } /* end of -m not given */ + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "taler", @@ -1305,12 +1341,11 @@ main (int argc, char *const *argv) { const struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_mandatory - (GNUNET_GETOPT_option_base32_auto ('m', - "exchange-key", - "KEY", - "public key of the exchange (Crockford base32 encoded)", - &master_pub)), + GNUNET_GETOPT_option_base32_auto ('m', + "exchange-key", + "KEY", + "public key of the exchange (Crockford base32 encoded)", + &master_pub), GNUNET_GETOPT_option_flag ('r', "restart", "restart audit from the beginning (required on first run)", -- cgit v1.2.3