diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-24 15:36:28 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-24 15:36:28 +0000 |
commit | 425613b68d5e8f66dd3462bf6b47c64b3534ee96 (patch) | |
tree | 4295e408ba57db9d31b5b53336aaa59c5544be19 /src/gns/gnunet-service-gns.c | |
parent | c0b7351895b024abfc75f36f7da3834fade1f48b (diff) | |
download | gnunet-425613b68d5e8f66dd3462bf6b47c64b3534ee96.tar.gz gnunet-425613b68d5e8f66dd3462bf6b47c64b3534ee96.zip |
-can finally resolve alice.gnunet as well as www.bob.gnunet (no signatures)
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 134 |
1 files changed, 95 insertions, 39 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 21791a6fa..563c9d851 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -89,6 +89,8 @@ struct GNUNET_GNS_PendingQuery | |||
89 | * may be able to resolve | 89 | * may be able to resolve |
90 | */ | 90 | */ |
91 | int authority_found; | 91 | int authority_found; |
92 | |||
93 | struct GNUNET_DNSPARSER_Packet *p; | ||
92 | }; | 94 | }; |
93 | 95 | ||
94 | 96 | ||
@@ -212,6 +214,7 @@ process_authority_dht_result(void* cls, | |||
212 | uint16_t namelen; | 214 | uint16_t namelen; |
213 | char* name = NULL; | 215 | char* name = NULL; |
214 | struct GNUNET_CRYPTO_RsaSignature *signature; | 216 | struct GNUNET_CRYPTO_RsaSignature *signature; |
217 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; | ||
215 | int i; | 218 | int i; |
216 | char* pos; | 219 | char* pos; |
217 | GNUNET_HashCode zone, name_hash; | 220 | GNUNET_HashCode zone, name_hash; |
@@ -260,21 +263,25 @@ process_authority_dht_result(void* cls, | |||
260 | 263 | ||
261 | } | 264 | } |
262 | 265 | ||
263 | if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature)) | 266 | if ((((char*)data)-pos) < |
267 | (sizeof(struct GNUNET_CRYPTO_RsaSignature) + | ||
268 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
264 | { | 269 | { |
265 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 270 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
266 | "Cannot parse signature in DHT response. Corrupted or Missing"); | 271 | "Cannot parse signature/key in DHT response. Corrupted or Missing"); |
267 | return; | 272 | return; |
268 | } | 273 | } |
269 | 274 | ||
270 | signature = (struct GNUNET_CRYPTO_RsaSignature*)pos; | 275 | signature = (struct GNUNET_CRYPTO_RsaSignature*)pos; |
271 | 276 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignature); | |
277 | |||
278 | public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos; | ||
272 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | 279 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); |
273 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | 280 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); |
274 | 281 | ||
275 | //Save to namestore | 282 | //Save to namestore |
276 | GNUNET_NAMESTORE_record_put (namestore_handle, | 283 | GNUNET_NAMESTORE_record_put (namestore_handle, |
277 | &zone, | 284 | public_key, |
278 | name, | 285 | name, |
279 | exp, | 286 | exp, |
280 | num_records, | 287 | num_records, |
@@ -365,6 +372,7 @@ process_name_dht_result(void* cls, | |||
365 | uint16_t namelen; | 372 | uint16_t namelen; |
366 | char* name = NULL; | 373 | char* name = NULL; |
367 | struct GNUNET_CRYPTO_RsaSignature *signature; | 374 | struct GNUNET_CRYPTO_RsaSignature *signature; |
375 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; | ||
368 | int i; | 376 | int i; |
369 | char* pos; | 377 | char* pos; |
370 | GNUNET_HashCode zone, name_hash; | 378 | GNUNET_HashCode zone, name_hash; |
@@ -413,21 +421,26 @@ process_name_dht_result(void* cls, | |||
413 | 421 | ||
414 | } | 422 | } |
415 | 423 | ||
416 | if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature)) | 424 | if ((((char*)data)-pos) < |
425 | (sizeof(struct GNUNET_CRYPTO_RsaSignature) + | ||
426 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
417 | { | 427 | { |
418 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 428 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
419 | "Cannot parse signature in DHT response. Corrupted or Missing"); | 429 | "Cannot parse signature/key in DHT response. Corrupted or Missing"); |
420 | return; | 430 | return; |
421 | } | 431 | } |
422 | 432 | ||
423 | signature = (struct GNUNET_CRYPTO_RsaSignature*)pos; | 433 | signature = (struct GNUNET_CRYPTO_RsaSignature*)pos; |
434 | pos += sizeof(struct GNUNET_CRYPTO_RsaSignature); | ||
435 | |||
436 | public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos; | ||
424 | 437 | ||
425 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | 438 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); |
426 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | 439 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); |
427 | 440 | ||
428 | //Save to namestore | 441 | //Save to namestore |
429 | GNUNET_NAMESTORE_record_put (namestore_handle, | 442 | GNUNET_NAMESTORE_record_put (namestore_handle, |
430 | &zone, | 443 | public_key, |
431 | name, | 444 | name, |
432 | exp, | 445 | exp, |
433 | num_records, | 446 | num_records, |
@@ -571,15 +584,19 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer, uint32_t rd_count, | |||
571 | size_t len; | 584 | size_t len; |
572 | int ret; | 585 | int ret; |
573 | char *buf; | 586 | char *buf; |
574 | struct GNUNET_DNSPARSER_Packet packet; | 587 | struct GNUNET_DNSPARSER_Packet *packet = answer->p; |
575 | struct GNUNET_DNSPARSER_Record answer_records[answer->num_records]; | 588 | struct GNUNET_DNSPARSER_Record answer_records[answer->num_records]; |
576 | packet.answers = answer_records; | 589 | packet->answers = answer_records; |
577 | 590 | ||
578 | len = sizeof(struct GNUNET_DNSPARSER_Record*); | 591 | len = sizeof(struct GNUNET_DNSPARSER_Record*); |
579 | for (i=0; i < rd_count; i++) | 592 | for (i=0; i < rd_count; i++) |
580 | { | 593 | { |
581 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 594 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
582 | "Adding type %d to DNS response\n", rd[i].record_type); | 595 | "Adding type %d to DNS response\n", rd[i].record_type); |
596 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Name: %s\n", answer->name); | ||
597 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "OName: %s\n", answer->original_name); | ||
598 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record %d/%d\n", i+1, rd_count); | ||
599 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record len %d\n", rd[i].data_size); | ||
583 | answer_records[i].name = answer->original_name; //FIXME yes? | 600 | answer_records[i].name = answer->original_name; //FIXME yes? |
584 | answer_records[i].type = rd[i].record_type; | 601 | answer_records[i].type = rd[i].record_type; |
585 | answer_records[i].data.raw.data_len = rd[i].data_size; | 602 | answer_records[i].data.raw.data_len = rd[i].data_size; |
@@ -588,26 +605,40 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer, uint32_t rd_count, | |||
588 | answer_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn | 605 | answer_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn |
589 | //GNUNET_free(i->record); DO this later! | 606 | //GNUNET_free(i->record); DO this later! |
590 | } | 607 | } |
591 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n"); | 608 | |
592 | /* FIXME how to handle auth, additional etc */ | 609 | /** |
593 | packet.num_answers = answer->num_records; | 610 | * FIXME how to handle auth, additional etc |
594 | packet.num_authority_records = answer->num_authority_records; | 611 | * PKEY might be auth, != name,record_type additional |
612 | **/ | ||
613 | packet->num_queries = 0; | ||
614 | packet->num_additional_records = 0; | ||
615 | packet->num_answers = rd_count; //answer->num_records; | ||
616 | //packet.num_authority_records = 0;//answer->num_authority_records; | ||
595 | 617 | ||
596 | dnsflags.authoritative_answer = 1; | 618 | dnsflags.authoritative_answer = 1; |
619 | dnsflags.message_truncated = 0; | ||
620 | dnsflags.recursion_desired = 0; | ||
621 | dnsflags.authenticated_data = 0; | ||
622 | dnsflags.checking_disabled = 1; | ||
623 | dnsflags.zero = 0; | ||
624 | dnsflags.recursion_available = 0; | ||
597 | dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY; | 625 | dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY; |
598 | dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure | 626 | if (rd == NULL) |
627 | dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR; | ||
628 | else | ||
629 | dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; | ||
599 | dnsflags.query_or_response = 1; | 630 | dnsflags.query_or_response = 1; |
600 | packet.flags = dnsflags; | 631 | packet->flags = dnsflags; |
601 | 632 | ||
602 | packet.id = answer->id; | ||
603 | |||
604 | //FIXME this is silently discarded | 633 | //FIXME this is silently discarded |
605 | ret = GNUNET_DNSPARSER_pack (&packet, | 634 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
635 | "Building DNS response\n"); | ||
636 | ret = GNUNET_DNSPARSER_pack (packet, | ||
606 | 1024, /* FIXME magic from dns redirector */ | 637 | 1024, /* FIXME magic from dns redirector */ |
607 | &buf, | 638 | &buf, |
608 | &len); | 639 | &len); |
609 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 640 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
610 | "Built DNS response! (ret=%d)\n", ret); | 641 | "Built DNS response! (ret=%d,len=%d)\n", ret, len); |
611 | if (ret == GNUNET_OK) | 642 | if (ret == GNUNET_OK) |
612 | { | 643 | { |
613 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 644 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -669,7 +700,7 @@ process_authoritative_result(void* cls, | |||
669 | * -> DHT Phase unless data is recent | 700 | * -> DHT Phase unless data is recent |
670 | */ | 701 | */ |
671 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 702 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
672 | "Namestore lookup terminated. without results\n"); | 703 | "Namestore lookup for %s terminated without results\n", name); |
673 | 704 | ||
674 | /** | 705 | /** |
675 | * if this is not our zone we cannot rely on the namestore to be | 706 | * if this is not our zone we cannot rely on the namestore to be |
@@ -851,6 +882,7 @@ resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone) | |||
851 | */ | 882 | */ |
852 | void | 883 | void |
853 | start_resolution(struct GNUNET_DNS_RequestHandle *rh, | 884 | start_resolution(struct GNUNET_DNS_RequestHandle *rh, |
885 | struct GNUNET_DNSPARSER_Packet *p, | ||
854 | char* name, uint16_t id, uint16_t type) | 886 | char* name, uint16_t id, uint16_t type) |
855 | { | 887 | { |
856 | struct GNUNET_GNS_PendingQuery *query; | 888 | struct GNUNET_GNS_PendingQuery *query; |
@@ -860,6 +892,7 @@ start_resolution(struct GNUNET_DNS_RequestHandle *rh, | |||
860 | query = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery)); | 892 | query = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery)); |
861 | query->id = id; | 893 | query->id = id; |
862 | query->original_name = name; //Full name of original query | 894 | query->original_name = name; //Full name of original query |
895 | query->p = p; | ||
863 | 896 | ||
864 | //FIXME do not forget to free!! | 897 | //FIXME do not forget to free!! |
865 | query->name = GNUNET_malloc(strlen(name)-strlen(gnunet_tld) + 1); | 898 | query->name = GNUNET_malloc(strlen(name)-strlen(gnunet_tld) + 1); |
@@ -924,7 +957,7 @@ handle_dns_request(void *cls, | |||
924 | 957 | ||
925 | if (0 == strcmp(tldoffset, gnunet_tld)) | 958 | if (0 == strcmp(tldoffset, gnunet_tld)) |
926 | { | 959 | { |
927 | start_resolution(rh, p->queries[i].name, p->id, p->queries[i].type); | 960 | start_resolution(rh, p, p->queries[i].name, p->id, p->queries[i].type); |
928 | } | 961 | } |
929 | else | 962 | else |
930 | { | 963 | { |
@@ -948,38 +981,61 @@ put_some_records(void) | |||
948 | /* put a few records into namestore */ | 981 | /* put a few records into namestore */ |
949 | char* ipA = "1.2.3.4"; | 982 | char* ipA = "1.2.3.4"; |
950 | char* ipB = "5.6.7.8"; | 983 | char* ipB = "5.6.7.8"; |
984 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key = GNUNET_CRYPTO_rsa_key_create (); struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob; | ||
985 | bob = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
986 | |||
987 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, bob); | ||
988 | |||
989 | GNUNET_HashCode *bob_zone = GNUNET_malloc(sizeof(GNUNET_HashCode)); | ||
990 | |||
991 | GNUNET_CRYPTO_hash(bob, GNUNET_CRYPTO_RSA_KEY_LENGTH, bob_zone); | ||
992 | |||
951 | struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); | 993 | struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); |
952 | struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr)); | 994 | struct in_addr *bob_web = GNUNET_malloc(sizeof(struct in_addr)); |
953 | struct GNUNET_NAMESTORE_RecordData *rda; | 995 | struct GNUNET_NAMESTORE_RecordData rda; |
954 | struct GNUNET_NAMESTORE_RecordData *rdb; | 996 | struct GNUNET_NAMESTORE_RecordData rdb; |
997 | struct GNUNET_NAMESTORE_RecordData rdb_web; | ||
955 | 998 | ||
956 | rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData)); | ||
957 | rdb = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData)); | ||
958 | |||
959 | GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); | 999 | GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); |
960 | GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob)); | 1000 | GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob_web)); |
961 | 1001 | ||
962 | rda->data_size = sizeof(struct in_addr); | 1002 | rda.data_size = sizeof(struct in_addr); |
963 | rdb->data_size = sizeof(struct in_addr); | 1003 | rdb_web.data_size = sizeof(struct in_addr); |
964 | rda->data = alice; | 1004 | rdb.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); |
965 | rdb->data = bob; | 1005 | rda.data = alice; |
966 | rda->record_type = GNUNET_GNS_RECORD_TYPE_A; | 1006 | rdb.data = bob; |
967 | rdb->record_type = GNUNET_GNS_RECORD_TYPE_A; | 1007 | rdb_web.data = bob_web; |
968 | rda->expiration = GNUNET_TIME_absolute_get_forever (); | 1008 | rda.record_type = GNUNET_GNS_RECORD_TYPE_A; |
969 | rdb->expiration = GNUNET_TIME_absolute_get_forever (); | 1009 | rdb_web.record_type = GNUNET_GNS_RECORD_TYPE_A; |
1010 | rdb.record_type = GNUNET_GNS_RECORD_PKEY; | ||
1011 | rdb_web.expiration = GNUNET_TIME_absolute_get_forever (); | ||
1012 | rda.expiration = GNUNET_TIME_absolute_get_forever (); | ||
1013 | rdb.expiration = GNUNET_TIME_absolute_get_forever (); | ||
970 | 1014 | ||
1015 | //alice.gnunet A IN 1.2.3.4 | ||
971 | GNUNET_NAMESTORE_record_create (namestore_handle, | 1016 | GNUNET_NAMESTORE_record_create (namestore_handle, |
972 | zone_key, | 1017 | zone_key, |
973 | "alice", | 1018 | "alice", |
974 | rda, | 1019 | &rda, |
975 | NULL, | 1020 | NULL, |
976 | NULL); | 1021 | NULL); |
1022 | |||
1023 | //www.bob.gnunet A IN 5.6.7.8 | ||
977 | GNUNET_NAMESTORE_record_create (namestore_handle, | 1024 | GNUNET_NAMESTORE_record_create (namestore_handle, |
978 | zone_key, | 1025 | zone_key, |
979 | "bob", | 1026 | "bob", |
980 | rdb, | 1027 | &rdb, |
981 | NULL, | 1028 | NULL, |
982 | NULL); | 1029 | NULL); |
1030 | GNUNET_NAMESTORE_record_put(namestore_handle, | ||
1031 | bob, | ||
1032 | "www", | ||
1033 | GNUNET_TIME_absolute_get_forever (), | ||
1034 | 1, | ||
1035 | &rdb_web, | ||
1036 | NULL, //Signature | ||
1037 | NULL, //Cont | ||
1038 | NULL); //cls | ||
983 | } | 1039 | } |
984 | 1040 | ||
985 | void | 1041 | void |