aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c94
1 files changed, 89 insertions, 5 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index a27d79cc7..d964a6f68 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -60,6 +60,9 @@ struct ClientShortenHandle
60 /* request type */ 60 /* request type */
61 enum GNUNET_GNS_RecordType type; 61 enum GNUNET_GNS_RecordType type;
62 62
63 /* optional zone private key used for lookup */
64 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
65
63 /* name to shorten */ 66 /* name to shorten */
64 char* name; 67 char* name;
65 68
@@ -97,6 +100,9 @@ struct ClientLookupHandle
97 /* request type */ 100 /* request type */
98 enum GNUNET_GNS_RecordType type; 101 enum GNUNET_GNS_RecordType type;
99 102
103 /* optional zone private key used for lookup */
104 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
105
100 /* the name to look up */ 106 /* the name to look up */
101 char* name; //Needed? 107 char* name; //Needed?
102}; 108};
@@ -416,6 +422,43 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
416 NULL); 422 NULL);
417} 423}
418 424
425/**
426 * Lookup the private key for the zone
427 *
428 * @param zone the zone we want a private key for
429 * @return NULL of not found else the key
430 */
431struct GNUNET_CRYPTO_RsaPrivateKey*
432lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
433{
434 char* keydir;
435 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
436 char* location;
437 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
438
439 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
440 "namestore",
441 "ZONEFILE_DIRECTORY", &keydir))
442 {
443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
444 "No zonefile directory!\n");
445 return NULL;
446 }
447
448 GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
449
450 GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
451 DIR_SEPARATOR_STR, zonename);
452
453 if (GNUNET_YES == GNUNET_DISK_file_test (location))
454 key = GNUNET_CRYPTO_rsa_key_create_from_file (location);
455
456 GNUNET_free(location);
457 GNUNET_free(keydir);
458
459 return key;
460
461}
419 462
420/* END DHT ZONE PROPAGATION */ 463/* END DHT ZONE PROPAGATION */
421 464
@@ -456,6 +499,7 @@ send_shorten_response(void* cls, const char* name)
456 499
457 GNUNET_free(rmsg); 500 GNUNET_free(rmsg);
458 GNUNET_free_non_null(csh->name); 501 GNUNET_free_non_null(csh->name);
502 GNUNET_free_non_null(csh->zone_key);
459 GNUNET_free(csh); 503 GNUNET_free(csh);
460 504
461} 505}
@@ -477,6 +521,8 @@ static void handle_shorten(void *cls,
477 struct ClientShortenHandle *csh; 521 struct ClientShortenHandle *csh;
478 char name[MAX_DNS_NAME_LENGTH]; 522 char name[MAX_DNS_NAME_LENGTH];
479 char* nameptr = name; 523 char* nameptr = name;
524 struct GNUNET_CRYPTO_ShortHashCode zone;
525 struct GNUNET_CRYPTO_RsaPrivateKey *key;
480 526
481 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) 527 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
482 { 528 {
@@ -501,6 +547,7 @@ static void handle_shorten(void *cls,
501 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle)); 547 csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
502 csh->client = client; 548 csh->client = client;
503 csh->unique_id = sh_msg->id; 549 csh->unique_id = sh_msg->id;
550 csh->zone_key = NULL;
504 551
505 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); 552 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
506 553
@@ -531,12 +578,26 @@ static void handle_shorten(void *cls,
531 578
532 GNUNET_SERVER_notification_context_add (nc, client); 579 GNUNET_SERVER_notification_context_add (nc, client);
533 580
581 if (1 == ntohl(sh_msg->use_default_zone))
582 zone = zone_hash; //Default zone
583 else
584 zone = sh_msg->zone;
585
534 /* Start shortening */ 586 /* Start shortening */
535 if (GNUNET_YES == auto_import_pkey) 587 if (GNUNET_YES == auto_import_pkey)
536 gns_resolver_shorten_name(zone_hash, name, zone_key, 588 {
589 if (1 == ntohl(sh_msg->use_default_zone))
590 key = zone_key;
591 else
592 {
593 key = lookup_private_key(&sh_msg->zone);
594 csh->zone_key = key;
595 }
596 gns_resolver_shorten_name(zone, name, key,
537 &send_shorten_response, csh); 597 &send_shorten_response, csh);
598 }
538 else 599 else
539 gns_resolver_shorten_name(zone_hash, name, NULL, 600 gns_resolver_shorten_name(zone, name, NULL,
540 &send_shorten_response, csh); 601 &send_shorten_response, csh);
541} 602}
542 603
@@ -682,6 +743,7 @@ static void handle_get_authority(void *cls,
682} 743}
683 744
684 745
746
685/** 747/**
686 * Reply to client with the result from our lookup. 748 * Reply to client with the result from our lookup.
687 * 749 *
@@ -719,6 +781,10 @@ send_lookup_response(void* cls,
719 781
720 GNUNET_free(rmsg); 782 GNUNET_free(rmsg);
721 GNUNET_free(clh->name); 783 GNUNET_free(clh->name);
784
785 if (NULL != clh->zone_key)
786 GNUNET_free(clh->zone_key);
787
722 GNUNET_free(clh); 788 GNUNET_free(clh);
723 789
724} 790}
@@ -743,6 +809,8 @@ handle_lookup(void *cls,
743 char name[MAX_DNS_NAME_LENGTH]; 809 char name[MAX_DNS_NAME_LENGTH];
744 struct ClientLookupHandle *clh; 810 struct ClientLookupHandle *clh;
745 char* nameptr = name; 811 char* nameptr = name;
812 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
813 struct GNUNET_CRYPTO_ShortHashCode zone;
746 814
747 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) 815 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
748 { 816 {
@@ -773,6 +841,7 @@ handle_lookup(void *cls,
773 strcpy(clh->name, name); 841 strcpy(clh->name, name);
774 clh->unique_id = sh_msg->id; 842 clh->unique_id = sh_msg->id;
775 clh->type = ntohl(sh_msg->type); 843 clh->type = ntohl(sh_msg->type);
844 clh->zone_key = NULL;
776 845
777 if (strlen (name) > MAX_DNS_NAME_LENGTH) { 846 if (strlen (name) > MAX_DNS_NAME_LENGTH) {
778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 847 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -781,17 +850,30 @@ handle_lookup(void *cls,
781 send_lookup_response(clh, 0, NULL); 850 send_lookup_response(clh, 0, NULL);
782 return; 851 return;
783 } 852 }
853
854 if (1 == ntohl(sh_msg->use_default_zone))
855 zone = zone_hash; //Default zone
856 else
857 zone = sh_msg->zone;
784 858
785 if (GNUNET_YES == auto_import_pkey) 859 if (GNUNET_YES == auto_import_pkey)
786 { 860 {
787 gns_resolver_lookup_record(zone_hash, clh->type, name, 861 if (1 == ntohl(sh_msg->use_default_zone))
788 zone_key, 862 key = zone_key;
863 else
864 {
865 key = lookup_private_key(&sh_msg->zone);
866 clh->zone_key = key;
867 }
868
869 gns_resolver_lookup_record(zone, clh->type, name,
870 key,
789 default_lookup_timeout, 871 default_lookup_timeout,
790 &send_lookup_response, clh); 872 &send_lookup_response, clh);
791 } 873 }
792 else 874 else
793 { 875 {
794 gns_resolver_lookup_record(zone_hash, clh->type, name, 876 gns_resolver_lookup_record(zone, clh->type, name,
795 NULL, 877 NULL,
796 default_lookup_timeout, 878 default_lookup_timeout,
797 &send_lookup_response, clh); 879 &send_lookup_response, clh);
@@ -826,6 +908,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
826 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} 908 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
827 }; 909 };
828 910
911 GNS_cfg = c;
912
829 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", 913 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
830 "ZONEKEY", &keyfile)) 914 "ZONEKEY", &keyfile))
831 { 915 {