From 6143cf95a47f8ec7de7898a416557f5034c36b27 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 9 May 2012 11:07:47 +0000 Subject: [PATCH] -per user lookups done --- src/gns/gnunet-gns.c | 41 +++++++++++++++++++++++++++++++++--- src/gns/gnunet-service-gns.c | 16 ++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index c17f15be3..7695f4213 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -60,7 +60,7 @@ static char *auth_name; /** * raw output */ -static int raw; +static int raw = 0; static enum GNUNET_GNS_RecordType rtype; @@ -142,6 +142,41 @@ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + char* keyfile; + struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; + struct GNUNET_CRYPTO_ShortHashCode *zone = NULL; + struct GNUNET_CRYPTO_ShortHashCode user_zone; + struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", + "ZONEKEY", &keyfile)) + { + if (!raw) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No private key for root zone found, using default!\n"); + zone = NULL; + } + else + { + if (GNUNET_YES == GNUNET_DISK_file_test (keyfile)) + { + key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); + GNUNET_CRYPTO_short_hash(&pkey, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &user_zone); + GNUNET_free(keyfile); + zone = &user_zone; + GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename); + printf("asdsad\n"); + if (!raw) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Using zone: %s!\n", &zonename); + GNUNET_CRYPTO_rsa_key_free(key); + } + } + gns = GNUNET_GNS_connect (cfg); if (lookup_type != NULL) rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type); @@ -158,7 +193,7 @@ run (void *cls, char *const *args, const char *cfgfile, if (shorten_name != NULL) { /** shorten name */ - GNUNET_GNS_shorten(gns, shorten_name, &process_shorten_result, + GNUNET_GNS_shorten_zone (gns, shorten_name, zone, &process_shorten_result, shorten_name); } @@ -166,7 +201,7 @@ run (void *cls, char *const *args, const char *cfgfile, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup\n"); - GNUNET_GNS_lookup(gns, lookup_name, rtype, + GNUNET_GNS_lookup_zone (gns, lookup_name, zone, rtype, &process_lookup_result, lookup_name); } diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index d964a6f68..6e157ca4b 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -435,6 +435,9 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone) struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; char* location; struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Looking for private key\n"); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg, "namestore", @@ -445,10 +448,19 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone) return NULL; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Zonefile directory is %s\n", keydir); + GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Zonefile is %s.zkey\n", &zonename); + GNUNET_asprintf(&location, "%s%s%s.zkey", keydir, - DIR_SEPARATOR_STR, zonename); + DIR_SEPARATOR_STR, &zonename); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Checking for %s\n", location); if (GNUNET_YES == GNUNET_DISK_file_test (location)) key = GNUNET_CRYPTO_rsa_key_create_from_file (location); @@ -862,7 +874,7 @@ handle_lookup(void *cls, key = zone_key; else { - key = lookup_private_key(&sh_msg->zone); + key = lookup_private_key(&zone); clh->zone_key = key; } -- 2.25.1