From 34243a1a0c04ef5723a327124f96e2571ac5fd2e Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Mon, 19 Mar 2012 17:09:03 +0000 Subject: [PATCH] -fixes, interceptor now speaks zkey --- src/gns/gnunet-service-gns_interceptor.c | 20 ++------ src/gns/gnunet-service-gns_resolver.c | 61 ++++++++++++++++++++---- src/gns/gnunet-service-gns_resolver.h | 17 +++++++ 3 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 15289fc35..7f34c93ce 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c @@ -210,9 +210,6 @@ reply_to_dns(void* cls, uint32_t rd_count, packet->num_additional_records = 0; packet->additional_records = NULL; GNUNET_DNSPARSER_free_packet(packet); - //FIXME free resolver handle in resp functions in resolver! - //GNUNET_free((struct RecordLookupHandle*)rh->proc_cls); - //free_resolver_handle(rh); GNUNET_free(ilh); } @@ -265,8 +262,6 @@ handle_dns_request(void *cls, const char *request) { struct GNUNET_DNSPARSER_Packet *p; - int i; - char *tldoffset; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacked a DNS request...processing\n"); p = GNUNET_DNSPARSER_parse (request, request_length); @@ -310,20 +305,11 @@ handle_dns_request(void *cls, /** - * Check for .gnunet + * Check for .gnunet/.zkey */ - tldoffset = p->queries[0].name + strlen(p->queries[0].name) - 1; - - for (i=0; iqueries[0].name); i++) - { - if (*(tldoffset-i) == '.') - break; - } - - i--; - if ((i==strlen(GNUNET_GNS_TLD)-1) - && (0 == strcmp(tldoffset-i, GNUNET_GNS_TLD))) + if ((is_gnunet_tld(p->queries[0].name) == GNUNET_YES) || + (is_zkey_tld(p->queries[0].name) == GNUNET_YES)) { start_resolution_for_dns(rh, p, p->queries); } diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 1bbb431e0..4ac6cea36 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -1164,26 +1164,26 @@ pop_tld(char* name, char* dest) } /** - * Checks if name is in .zkey TLD + * Checks if name is in tld * * @param name the name to check * @return GNUNET_YES or GNUNET_NO */ int -is_zkey_tld(const char* name) +is_tld(const char* name, const char* tld) { int offset = 0; - if (strlen(name) <= strlen(GNUNET_GNS_TLD_ZKEY)) + if (strlen(name) <= strlen(tld)) { return GNUNET_NO; } - offset = strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY); - if (strcmp(name+offset, GNUNET_GNS_TLD_ZKEY) != 0) + offset = strlen(name)-strlen(tld); + if (strcmp(name+offset, tld) != 0) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "%s is not in zkey TLD\n", name); + "%s is not in .%s TLD\n", name, tld); return GNUNET_NO; } return GNUNET_YES; @@ -1823,6 +1823,7 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, { struct ResolverHandle *rh; struct NameShortenHandle *nsh; + char string_hash[MAX_DNS_NAME_LENGTH]; //FIXME LABEL length when shorthash GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting shorten for %s!\n", name); @@ -1843,10 +1844,50 @@ gns_resolver_shorten_name(GNUNET_HashCode zone, rh = GNUNET_malloc(sizeof (struct ResolverHandle)); rh->authority = zone; - memset(rh->name, 0, - strlen(name)-strlen(GNUNET_GNS_TLD)); - memcpy(rh->name, name, - strlen(name)-strlen(GNUNET_GNS_TLD)-1); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Checking for TLD...\n"); + if (is_zkey_tld(name) == GNUNET_YES) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TLD is zkey\n"); + /** + * This is a zkey tld + * build hash and use as initial authority + */ + memset(rh->name, 0, + strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY)); + memcpy(rh->name, name, + strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1); + pop_tld(rh->name, string_hash); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ZKEY is %s!\n", string_hash); + + if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(string_hash, + &rh->authority)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot convert ZKEY %s to hash!\n", string_hash); + GNUNET_free(rh); + GNUNET_free(nsh); + proc(cls, name); + return; + } + + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TLD is gnunet\n"); + /** + * Presumably GNUNET tld + */ + memset(rh->name, 0, + strlen(name)-strlen(GNUNET_GNS_TLD)); + memcpy(rh->name, name, + strlen(name)-strlen(GNUNET_GNS_TLD) - 1); + } rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); rh->authority_chain_tail = rh->authority_chain_head; diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index fb612d72d..4f857825c 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -266,4 +266,21 @@ gns_resolver_get_authority(GNUNET_HashCode zone, GetAuthorityResultProcessor proc, void* cls); +/** + * Generic function to check for TLDs + * + * @param name the name to check + * @param tld the tld to check + * @return GNUNET_YES or GNUNET_NO + */ +int +is_tld(const char* name, const char* tld); + +/** + * Checks for gnunet/zkey + */ +#define is_gnunet_tld(name) is_tld(name, GNUNET_GNS_TLD) +#define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY) + + #endif -- 2.25.1