gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit b54a765c9e8fe780689c4b46eed0434fcae4b221
parent 7e43187c78bdae919861c44b03454db61f46370a
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Tue, 30 Apr 2024 11:27:37 +0200

GNS: Add helper function to parse zTLDs

NEWS: Added GNUNET_GNS_parse_ztld helper API

Diffstat:
Msrc/include/gnunet_gns_service.h | 10++++++++++
Msrc/service/gns/gns_tld_api.c | 32++++++++++++++++----------------
Msrc/service/reclaim/gnunet-service-reclaim_tickets.c | 27+++------------------------
Msrc/service/rest/reclaim_plugin.c | 8+-------
4 files changed, 30 insertions(+), 47 deletions(-)

diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h @@ -227,6 +227,16 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, void * GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); +/** + * Try to parse the zTLD into a public key. + * + * @param[in] name the name to parse + * @param[out] ztld_key the identity key (must be allocated by caller). Only set of #GNUNET_OK is returned. + * @return GNUNET_OK on success. + */ +enum GNUNET_GenericReturnValue +GNUNET_GNS_parse_ztld (const char *name, + struct GNUNET_CRYPTO_PublicKey *ztld_key); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/service/gns/gns_tld_api.c b/src/service/gns/gns_tld_api.c @@ -23,6 +23,7 @@ * @author Martin Schanzenbach * @author Christian Grothoff */ +#include "gnunet_common.h" #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_constants.h" @@ -223,19 +224,18 @@ identity_zone_cb (void *cls, } -/** - * Perform an asynchronous lookup operation on the GNS, - * determining the zone using the TLD of the given name - * and the current configuration to resolve TLDs to zones. - * - * @param handle handle to the GNS service - * @param name the name to look up, including TLD (in UTF-8 encoding) - * @param type the record type to look up - * @param options local options for the lookup - * @param proc processor to call on result - * @param proc_cls closure for @a proc - * @return handle to the get request, NULL on error (e.g. bad configuration) - */ +enum GNUNET_GenericReturnValue +GNUNET_GNS_parse_ztld (const char *name, + struct GNUNET_CRYPTO_PublicKey *ztld_key) +{ + const char *tld; + + /* start with trivial case: TLD is zkey */ + tld = get_tld (name); + return GNUNET_CRYPTO_public_key_from_string (tld, ztld_key); +} + + struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, const char *name, @@ -258,10 +258,10 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, ltr->lookup_proc = proc; ltr->lookup_proc_cls = proc_cls; /* start with trivial case: TLD is zkey */ - tld = get_tld (ltr->name); if (GNUNET_OK == - GNUNET_CRYPTO_public_key_from_string (tld, &pkey)) + GNUNET_GNS_parse_ztld (ltr->name, &pkey)) { + tld = get_tld (ltr->name); LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' seems to be a valid zone key\n", tld); eat_tld (ltr->name, tld); @@ -283,7 +283,7 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, { if (GNUNET_OK != GNUNET_CRYPTO_public_key_from_string (zonestr, - &pkey)) + &pkey)) { GNUNET_log_config_invalid ( GNUNET_ERROR_TYPE_ERROR, diff --git a/src/service/reclaim/gnunet-service-reclaim_tickets.c b/src/service/reclaim/gnunet-service-reclaim_tickets.c @@ -26,6 +26,7 @@ */ #include "gnunet-service-reclaim_tickets.h" #include "gnunet_common.h" +#include "gnunet_gns_service.h" #include "gnunet_reclaim_service.h" #include <string.h> @@ -906,26 +907,6 @@ rvk_attrs_err_cb (void *cls) } -static enum GNUNET_GenericReturnValue -get_iss_from_ticket (const struct GNUNET_RECLAIM_Ticket *ticket, - struct GNUNET_CRYPTO_PublicKey *issuer) -{ - char *label; - char *key; - char *tmp; - int ret; - - tmp = GNUNET_strdup (ticket->gns_name); - label = strtok (tmp, "."); - GNUNET_assert (NULL != label); - key = strtok (NULL, "."); - GNUNET_assert (NULL != key); - ret = GNUNET_CRYPTO_public_key_from_string (key, issuer); - GNUNET_free (tmp); - return ret; -} - - /** * Revoke a ticket. * We start by looking up attribute references in order @@ -1066,7 +1047,7 @@ process_parallel_lookup_result (void *cls, if (NULL != cth->parallel_lookups_head) return; // Wait for more /* Else we are done */ - get_iss_from_ticket (&cth->ticket, &iss); + GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (cth->ticket.gns_name, &iss)); cth->cb (cth->cb_cls, &iss, cth->attrs, cth->presentations, GNUNET_OK, NULL); cleanup_cth (cth); @@ -1171,6 +1152,7 @@ lookup_authz_cb (void *cls, "Ignoring unknown record type %d", rd[i].record_type); } } + GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (cth->ticket.gns_name, &iss)); if (NULL == rp_uri) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -1178,7 +1160,6 @@ lookup_authz_cb (void *cls, /** * Return error */ - get_iss_from_ticket (&cth->ticket, &iss); cth->cb (cth->cb_cls, &iss, cth->attrs, NULL, GNUNET_NO, NULL); cleanup_cth (cth); @@ -1192,7 +1173,6 @@ lookup_authz_cb (void *cls, /** * Return error */ - get_iss_from_ticket (&cth->ticket, &iss); cth->cb (cth->cb_cls, &iss, cth->attrs, NULL, GNUNET_NO, NULL); cleanup_cth (cth); @@ -1213,7 +1193,6 @@ lookup_authz_cb (void *cls, /** * No references found, return empty attribute list */ - get_iss_from_ticket (&cth->ticket, &iss); cth->cb (cth->cb_cls, &iss, cth->attrs, NULL, GNUNET_OK, NULL); cleanup_cth (cth); diff --git a/src/service/rest/reclaim_plugin.c b/src/service/rest/reclaim_plugin.c @@ -1119,8 +1119,6 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, struct GNUNET_CRYPTO_PublicKey iss; struct GNUNET_CRYPTO_PublicKey tmp_pk; char term_data[handle->rest_handle->data_size + 1]; - char *tmp; - char *key; json_t *data_json; json_error_t err; struct GNUNET_JSON_Specification tktspec[] = @@ -1157,10 +1155,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, return; } - tmp = GNUNET_strdup (ticket->gns_name); - GNUNET_assert (NULL != strtok (tmp, ".")); - key = strtok (NULL, "."); - GNUNET_CRYPTO_public_key_from_string (key, &iss); + GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (ticket->gns_name, &iss)); for (ego_entry = ego_head; NULL != ego_entry; ego_entry = ego_entry->next) @@ -1171,7 +1166,6 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, sizeof(struct GNUNET_CRYPTO_PublicKey))) break; } - GNUNET_free (tmp); if (NULL == ego_entry) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");