aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2024-04-30 11:27:37 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2024-04-30 11:27:37 +0200
commitb54a765c9e8fe780689c4b46eed0434fcae4b221 (patch)
tree86699ac3233756e9d17cbc80a6d3788aa7b76155 /src
parent7e43187c78bdae919861c44b03454db61f46370a (diff)
downloadgnunet-b54a765c9e8fe780689c4b46eed0434fcae4b221.tar.gz
gnunet-b54a765c9e8fe780689c4b46eed0434fcae4b221.zip
GNS: Add helper function to parse zTLDs
NEWS: Added GNUNET_GNS_parse_ztld helper API
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_gns_service.h10
-rw-r--r--src/service/gns/gns_tld_api.c32
-rw-r--r--src/service/reclaim/gnunet-service-reclaim_tickets.c27
-rw-r--r--src/service/rest/reclaim_plugin.c8
4 files changed, 30 insertions, 47 deletions
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 1f19e58ac..e7ed2d3c2 100644
--- 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,
227void * 227void *
228GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); 228GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
229 229
230/**
231 * Try to parse the zTLD into a public key.
232 *
233 * @param[in] name the name to parse
234 * @param[out] ztld_key the identity key (must be allocated by caller). Only set of #GNUNET_OK is returned.
235 * @return GNUNET_OK on success.
236 */
237enum GNUNET_GenericReturnValue
238GNUNET_GNS_parse_ztld (const char *name,
239 struct GNUNET_CRYPTO_PublicKey *ztld_key);
230 240
231#if 0 /* keep Emacsens' auto-indent happy */ 241#if 0 /* keep Emacsens' auto-indent happy */
232{ 242{
diff --git a/src/service/gns/gns_tld_api.c b/src/service/gns/gns_tld_api.c
index 1ea87fd97..63b5ac552 100644
--- a/src/service/gns/gns_tld_api.c
+++ b/src/service/gns/gns_tld_api.c
@@ -23,6 +23,7 @@
23 * @author Martin Schanzenbach 23 * @author Martin Schanzenbach
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet_common.h"
26#include "platform.h" 27#include "platform.h"
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
28#include "gnunet_constants.h" 29#include "gnunet_constants.h"
@@ -223,19 +224,18 @@ identity_zone_cb (void *cls,
223} 224}
224 225
225 226
226/** 227enum GNUNET_GenericReturnValue
227 * Perform an asynchronous lookup operation on the GNS, 228GNUNET_GNS_parse_ztld (const char *name,
228 * determining the zone using the TLD of the given name 229 struct GNUNET_CRYPTO_PublicKey *ztld_key)
229 * and the current configuration to resolve TLDs to zones. 230{
230 * 231 const char *tld;
231 * @param handle handle to the GNS service 232
232 * @param name the name to look up, including TLD (in UTF-8 encoding) 233 /* start with trivial case: TLD is zkey */
233 * @param type the record type to look up 234 tld = get_tld (name);
234 * @param options local options for the lookup 235 return GNUNET_CRYPTO_public_key_from_string (tld, ztld_key);
235 * @param proc processor to call on result 236}
236 * @param proc_cls closure for @a proc 237
237 * @return handle to the get request, NULL on error (e.g. bad configuration) 238
238 */
239struct GNUNET_GNS_LookupWithTldRequest * 239struct GNUNET_GNS_LookupWithTldRequest *
240GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, 240GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
241 const char *name, 241 const char *name,
@@ -258,10 +258,10 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
258 ltr->lookup_proc = proc; 258 ltr->lookup_proc = proc;
259 ltr->lookup_proc_cls = proc_cls; 259 ltr->lookup_proc_cls = proc_cls;
260 /* start with trivial case: TLD is zkey */ 260 /* start with trivial case: TLD is zkey */
261 tld = get_tld (ltr->name);
262 if (GNUNET_OK == 261 if (GNUNET_OK ==
263 GNUNET_CRYPTO_public_key_from_string (tld, &pkey)) 262 GNUNET_GNS_parse_ztld (ltr->name, &pkey))
264 { 263 {
264 tld = get_tld (ltr->name);
265 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG,
266 "`%s' seems to be a valid zone key\n", tld); 266 "`%s' seems to be a valid zone key\n", tld);
267 eat_tld (ltr->name, tld); 267 eat_tld (ltr->name, tld);
@@ -283,7 +283,7 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
283 { 283 {
284 if (GNUNET_OK != 284 if (GNUNET_OK !=
285 GNUNET_CRYPTO_public_key_from_string (zonestr, 285 GNUNET_CRYPTO_public_key_from_string (zonestr,
286 &pkey)) 286 &pkey))
287 { 287 {
288 GNUNET_log_config_invalid ( 288 GNUNET_log_config_invalid (
289 GNUNET_ERROR_TYPE_ERROR, 289 GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/service/reclaim/gnunet-service-reclaim_tickets.c b/src/service/reclaim/gnunet-service-reclaim_tickets.c
index fcedc07ff..6fe77cdb3 100644
--- a/src/service/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/service/reclaim/gnunet-service-reclaim_tickets.c
@@ -26,6 +26,7 @@
26 */ 26 */
27#include "gnunet-service-reclaim_tickets.h" 27#include "gnunet-service-reclaim_tickets.h"
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_gns_service.h"
29#include "gnunet_reclaim_service.h" 30#include "gnunet_reclaim_service.h"
30#include <string.h> 31#include <string.h>
31 32
@@ -906,26 +907,6 @@ rvk_attrs_err_cb (void *cls)
906} 907}
907 908
908 909
909static enum GNUNET_GenericReturnValue
910get_iss_from_ticket (const struct GNUNET_RECLAIM_Ticket *ticket,
911 struct GNUNET_CRYPTO_PublicKey *issuer)
912{
913 char *label;
914 char *key;
915 char *tmp;
916 int ret;
917
918 tmp = GNUNET_strdup (ticket->gns_name);
919 label = strtok (tmp, ".");
920 GNUNET_assert (NULL != label);
921 key = strtok (NULL, ".");
922 GNUNET_assert (NULL != key);
923 ret = GNUNET_CRYPTO_public_key_from_string (key, issuer);
924 GNUNET_free (tmp);
925 return ret;
926}
927
928
929/** 910/**
930 * Revoke a ticket. 911 * Revoke a ticket.
931 * We start by looking up attribute references in order 912 * We start by looking up attribute references in order
@@ -1066,7 +1047,7 @@ process_parallel_lookup_result (void *cls,
1066 if (NULL != cth->parallel_lookups_head) 1047 if (NULL != cth->parallel_lookups_head)
1067 return; // Wait for more 1048 return; // Wait for more
1068 /* Else we are done */ 1049 /* Else we are done */
1069 get_iss_from_ticket (&cth->ticket, &iss); 1050 GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (cth->ticket.gns_name, &iss));
1070 cth->cb (cth->cb_cls, &iss, 1051 cth->cb (cth->cb_cls, &iss,
1071 cth->attrs, cth->presentations, GNUNET_OK, NULL); 1052 cth->attrs, cth->presentations, GNUNET_OK, NULL);
1072 cleanup_cth (cth); 1053 cleanup_cth (cth);
@@ -1171,6 +1152,7 @@ lookup_authz_cb (void *cls,
1171 "Ignoring unknown record type %d", rd[i].record_type); 1152 "Ignoring unknown record type %d", rd[i].record_type);
1172 } 1153 }
1173 } 1154 }
1155 GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (cth->ticket.gns_name, &iss));
1174 if (NULL == rp_uri) 1156 if (NULL == rp_uri)
1175 { 1157 {
1176 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1178,7 +1160,6 @@ lookup_authz_cb (void *cls,
1178 /** 1160 /**
1179 * Return error 1161 * Return error
1180 */ 1162 */
1181 get_iss_from_ticket (&cth->ticket, &iss);
1182 cth->cb (cth->cb_cls, &iss, 1163 cth->cb (cth->cb_cls, &iss,
1183 cth->attrs, NULL, GNUNET_NO, NULL); 1164 cth->attrs, NULL, GNUNET_NO, NULL);
1184 cleanup_cth (cth); 1165 cleanup_cth (cth);
@@ -1192,7 +1173,6 @@ lookup_authz_cb (void *cls,
1192 /** 1173 /**
1193 * Return error 1174 * Return error
1194 */ 1175 */
1195 get_iss_from_ticket (&cth->ticket, &iss);
1196 cth->cb (cth->cb_cls, &iss, 1176 cth->cb (cth->cb_cls, &iss,
1197 cth->attrs, NULL, GNUNET_NO, NULL); 1177 cth->attrs, NULL, GNUNET_NO, NULL);
1198 cleanup_cth (cth); 1178 cleanup_cth (cth);
@@ -1213,7 +1193,6 @@ lookup_authz_cb (void *cls,
1213 /** 1193 /**
1214 * No references found, return empty attribute list 1194 * No references found, return empty attribute list
1215 */ 1195 */
1216 get_iss_from_ticket (&cth->ticket, &iss);
1217 cth->cb (cth->cb_cls, &iss, 1196 cth->cb (cth->cb_cls, &iss,
1218 cth->attrs, NULL, GNUNET_OK, NULL); 1197 cth->attrs, NULL, GNUNET_OK, NULL);
1219 cleanup_cth (cth); 1198 cleanup_cth (cth);
diff --git a/src/service/rest/reclaim_plugin.c b/src/service/rest/reclaim_plugin.c
index 31a795dc8..adddab5c6 100644
--- 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,
1119 struct GNUNET_CRYPTO_PublicKey iss; 1119 struct GNUNET_CRYPTO_PublicKey iss;
1120 struct GNUNET_CRYPTO_PublicKey tmp_pk; 1120 struct GNUNET_CRYPTO_PublicKey tmp_pk;
1121 char term_data[handle->rest_handle->data_size + 1]; 1121 char term_data[handle->rest_handle->data_size + 1];
1122 char *tmp;
1123 char *key;
1124 json_t *data_json; 1122 json_t *data_json;
1125 json_error_t err; 1123 json_error_t err;
1126 struct GNUNET_JSON_Specification tktspec[] = 1124 struct GNUNET_JSON_Specification tktspec[] =
@@ -1157,10 +1155,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1157 return; 1155 return;
1158 } 1156 }
1159 1157
1160 tmp = GNUNET_strdup (ticket->gns_name); 1158 GNUNET_assert (GNUNET_OK == GNUNET_GNS_parse_ztld (ticket->gns_name, &iss));
1161 GNUNET_assert (NULL != strtok (tmp, "."));
1162 key = strtok (NULL, ".");
1163 GNUNET_CRYPTO_public_key_from_string (key, &iss);
1164 1159
1165 for (ego_entry = ego_head; NULL != ego_entry; 1160 for (ego_entry = ego_head; NULL != ego_entry;
1166 ego_entry = ego_entry->next) 1161 ego_entry = ego_entry->next)
@@ -1171,7 +1166,6 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1171 sizeof(struct GNUNET_CRYPTO_PublicKey))) 1166 sizeof(struct GNUNET_CRYPTO_PublicKey)))
1172 break; 1167 break;
1173 } 1168 }
1174 GNUNET_free (tmp);
1175 if (NULL == ego_entry) 1169 if (NULL == ego_entry)
1176 { 1170 {
1177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); 1171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");