summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_auditors.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-11-26 13:41:59 +0100
committerChristian Grothoff <christian@grothoff.org>2015-11-26 13:41:59 +0100
commit9ac12f14e9d2272b67877525c076824ff4b813f5 (patch)
tree4a30bda0bfe1e2e321a76a12b9698eb3141d2522 /src/backend/taler-merchant-httpd_auditors.c
parent7c94fa50d13de092b80c78d66c5e91637209e64f (diff)
downloadmerchant-9ac12f14e9d2272b67877525c076824ff4b813f5.tar.gz
merchant-9ac12f14e9d2272b67877525c076824ff4b813f5.tar.bz2
merchant-9ac12f14e9d2272b67877525c076824ff4b813f5.zip
modify auditor logic to include public keys and URI, also now matches latest API spec
Diffstat (limited to 'src/backend/taler-merchant-httpd_auditors.c')
-rw-r--r--src/backend/taler-merchant-httpd_auditors.c147
1 files changed, 95 insertions, 52 deletions
diff --git a/src/backend/taler-merchant-httpd_auditors.c b/src/backend/taler-merchant-httpd_auditors.c
index 7edcdb9e..84fbb344 100644
--- a/src/backend/taler-merchant-httpd_auditors.c
+++ b/src/backend/taler-merchant-httpd_auditors.c
@@ -28,10 +28,20 @@
struct Auditor
{
/**
- * Auditor's legal name (FIXME: this is not what we really want.)
+ * Auditor's legal name.
*/
char *name;
+ /**
+ * Auditor's URI.
+ */
+ char *uri;
+
+ /**
+ * Public key of the auditor.
+ */
+ struct TALER_AuditorPublicKeyP public_key;
+
};
@@ -52,6 +62,81 @@ json_t *j_auditors;
/**
+ * Function called on each configuration section. Finds sections
+ * about auditors and parses the entries.
+ *
+ * @param cls closure
+ * @param section name of the section
+ */
+static void
+parse_auditors (void *cls,
+ const char *section)
+{
+ char *pks;
+ struct Auditor auditor;
+
+ if (0 != strncasecmp (section,
+ "auditor-",
+ strlen ("auditor-")))
+ return;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "NAME",
+ &auditor.name))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "NAME");
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "URI",
+ &auditor.uri))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "URI");
+ GNUNET_free (auditor.name);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "PUBLIC_KEY",
+ &pks))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "PUBLIC_KEY");
+ GNUNET_free (auditor.name);
+ GNUNET_free (auditor.uri);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (pks,
+ strlen (pks),
+ &auditor.public_key.eddsa_pub))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "PUBLIC_KEY",
+ "valid public key");
+ GNUNET_free (auditor.name);
+ GNUNET_free (auditor.uri);
+ GNUNET_free (pks);
+ return;
+ }
+ GNUNET_free (pks);
+ GNUNET_array_append (auditors,
+ nauditors,
+ auditor);
+}
+
+
+/**
* Parses auditor information from the configuration.
*
* @param cfg the configuration
@@ -61,65 +146,22 @@ json_t *j_auditors;
int
TMH_AUDITORS_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- char *auditors_str;
- char *token_nf; /* do no free (nf) */
- char *auditor_section;
- char *auditor_name;
- struct Auditor *r_auditors;
- struct Auditor auditor;
unsigned int cnt;
int ok;
- ok = 0;
- auditors_str = NULL;
- token_nf = NULL;
- auditor_section = NULL;
- auditor_name = NULL;
- r_auditors = NULL;
- cnt = 0;
- EXITIF (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "merchant",
- "AUDITORS",
- &auditors_str));
- for (token_nf = strtok (auditors_str, " ");
- NULL != token_nf;
- token_nf = strtok (NULL, " "))
- {
- GNUNET_assert (0 < GNUNET_asprintf (&auditor_section,
- "auditor-%s", token_nf));
- EXITIF (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- auditor_section,
- "NAME",
- &auditor_name));
- auditor.name = auditor_name;
- GNUNET_array_append (r_auditors, cnt, auditor);
- auditor_name = NULL;
- GNUNET_free (auditor_section);
- auditor_section = NULL;
- }
- ok = 1;
-
- EXITIF_exit:
- GNUNET_free_non_null (auditors_str);
- GNUNET_free_non_null (auditor_section);
- GNUNET_free_non_null (auditor_name);
- if (! ok)
- {
- GNUNET_free_non_null (r_auditors);
- return GNUNET_SYSERR;
- }
-
- auditors = r_auditors;
- nauditors = cnt;
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &parse_auditors,
+ NULL);
/* Generate preferred mint(s) array. */
j_auditors = json_array ();
for (cnt = 0; cnt < nauditors; cnt++)
json_array_append_new (j_auditors,
- json_pack ("{s:s}",
- "name", auditors[cnt].name));
+ json_pack ("{s:s, s:o, s:s}",
+ "name", auditors[cnt].name,
+ "auditor_pub", TALER_json_from_data (&auditors[cnt].public_key,
+ sizeof (struct TALER_AuditorPublicKeyP)),
+ "uri", auditors[cnt].uri));
return nauditors;
}
@@ -137,6 +179,7 @@ TMH_AUDITORS_done ()
for (i=0;i<nauditors;i++)
{
GNUNET_free (auditors[i].name);
+ GNUNET_free (auditors[i].uri);
}
GNUNET_free (auditors);
auditors = NULL;