From ea1d3fd9f54879992fb997a1e94cfd6830085c4b Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 22 Oct 2020 19:09:12 +0200 Subject: -more gnsrecord API --- src/gns/gnunet-gns-import.c | 9 +++++++-- src/gns/gnunet-service-gns_resolver.c | 28 +++++++++++++++++++--------- src/gns/plugin_gnsrecord_gns.c | 29 +++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 19 deletions(-) (limited to 'src/gns') diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c index 78db28cab..972fb49cd 100644 --- a/src/gns/gnunet-gns-import.c +++ b/src/gns/gnunet-gns-import.c @@ -168,12 +168,17 @@ check_pkey (unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, char *pk, int *found_rec) { int i; + struct GNUNET_IDENTITY_PublicKey pubkey; for (i = 0; i < rd_len; i++) { char *s; - if ((GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type) || - (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) ) + if (sizeof (uint32_t) > rd[i].data_size) + continue; + if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (rd[i].data, + rd[i].data_size, + rd[i].record_type, + &pubkey)) continue; s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, rd[i].data, diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 1c13f4df1..d9d0d3099 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -1699,8 +1699,10 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, struct GNUNET_IDENTITY_PublicKey auth; /* delegation to another zone */ - if (GNUNET_OK != GNUNET_GNSRECORD_record_to_identity_key (rd, - &auth)) + if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (rd->data, + rd->data_size, + rd->record_type, + &auth)) { GNUNET_break_op (0); fail_resolution (rh); @@ -1711,8 +1713,6 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, ac->rh = rh; ac->gns_authority = GNUNET_YES; ac->authority_info.gns_authority = auth; - GNUNET_GNSRECORD_record_to_identity_key (rd, - &ac->authority_info.gns_authority); ac->label = resolver_lookup_get_next_label (rh); /* add AC to tail */ GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, @@ -2258,14 +2258,25 @@ handle_gns_resolution_result (void *cls, break; case GNUNET_GNSRECORD_TYPE_PKEY: + case GNUNET_GNSRECORD_TYPE_EDKEY: { - if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) + struct GNUNET_IDENTITY_PublicKey pubkey; + if (rd[i].data_size < sizeof(uint32_t)) + { + GNUNET_break_op (0); + break; + } + if (GNUNET_OK != + GNUNET_GNSRECORD_identity_from_data (rd[i].data, + rd[i].data_size, + rd[i].record_type, + &pubkey)) { GNUNET_break_op (0); break; } rd_off++; - if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) + if (rd[i].record_type != rh->record_type) { /* try to resolve "@" */ struct AuthorityChain *ac; @@ -2273,9 +2284,7 @@ handle_gns_resolution_result (void *cls, ac = GNUNET_new (struct AuthorityChain); ac->rh = rh; ac->gns_authority = GNUNET_YES; - GNUNET_GNSRECORD_record_to_identity_key (&rd[i], - &ac->authority_info. - gns_authority); + ac->authority_info.gns_authority = pubkey; ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, rh->ac_tail, @@ -2365,6 +2374,7 @@ handle_gns_resolution_result (void *cls, return; case GNUNET_GNSRECORD_TYPE_PKEY: + case GNUNET_GNSRECORD_TYPE_EDKEY: GNUNET_break_op (1 == rd_count); /* PKEY should be unique */ recursive_pkey_resolution (rh, &rd[0]); diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c index 0bd1d047f..a2ad0b905 100644 --- a/src/gns/plugin_gnsrecord_gns.c +++ b/src/gns/plugin_gnsrecord_gns.c @@ -55,10 +55,12 @@ gns_value_to_string (void *cls, switch (type) { case GNUNET_GNSRECORD_TYPE_PKEY: - if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) + case GNUNET_GNSRECORD_TYPE_EDKEY: + if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (data, + data_size, + type, + &pk)) return NULL; - pk.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); - memcpy (&pk.ecdsa_key, data, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); return GNUNET_IDENTITY_public_key_to_string (&pk); case GNUNET_GNSRECORD_TYPE_NICK: @@ -156,25 +158,35 @@ gns_string_to_value (void *cls, void **data, size_t *data_size) { - struct GNUNET_CRYPTO_EcdsaPublicKey pkey; struct GNUNET_IDENTITY_PublicKey pk; + uint32_t record_type; if (NULL == s) return GNUNET_SYSERR; switch (type) { case GNUNET_GNSRECORD_TYPE_PKEY: + case GNUNET_GNSRECORD_TYPE_EDKEY: if (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (s, &pk)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Unable to parse PKEY record `%s'\n"), + _ ("Unable to parse zone key record `%s'\n"), s); return GNUNET_SYSERR; } - *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); - GNUNET_memcpy (*data, &pk.ecdsa_key, sizeof(pkey)); - *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); + *data_size = GNUNET_IDENTITY_key_get_length (&pk); + if (GNUNET_OK != GNUNET_GNSRECORD_data_from_identity (&pk, + (char **) data, + data_size, + &record_type)) + return GNUNET_SYSERR; + if (record_type != type) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Record type does not match parsed record type\n")); + return GNUNET_SYSERR; + } return GNUNET_OK; case GNUNET_GNSRECORD_TYPE_NICK: @@ -305,6 +317,7 @@ static struct const char *name; uint32_t number; } gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, + { "EDKEY", GNUNET_GNSRECORD_TYPE_PKEY }, { "NICK", GNUNET_GNSRECORD_TYPE_NICK }, { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO }, { "VPN", GNUNET_GNSRECORD_TYPE_VPN }, -- cgit v1.2.3