From 80270d3107822eebfdbdb3eaeb03be6f63d7c9da Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 1 Mar 2012 14:57:15 +0000 Subject: [PATCH] -modified test --- src/gns/Makefile.am | 4 +- src/gns/plugin_block_gns.c | 59 ++++++++++---------- src/gns/test_gns_twopeer.c | 110 +++++++++++++++++++++++++++++++------ 3 files changed, 127 insertions(+), 46 deletions(-) diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 0aa615737..773a735a0 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -38,9 +38,11 @@ test_gns_twopeer_SOURCES = \ test_gns_twopeer.c test_gns_twopeer_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/testing/libgnunettesting.la test_gns_twopeer_DEPENDENCIES = \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(top_builddir)/src/testing/libgnunettesting.la #gnunet_gns_lookup_SOURCES = \ @@ -62,7 +64,7 @@ gnunet_service_gns_LDADD = \ $(top_builddir)/src/dns/libgnunetdns.la \ $(top_builddir)/src/dns/libgnunetdnsparser.la \ $(top_builddir)/src/dht/libgnunetdht.la \ - $(top_builddir)/src/gns/libgnunetnamestore.la \ + $(top_builddir)/src/namestore/libgnunetnamestore.la \ $(GN_LIBINTL) gnunet_service_gns_DEPENDENCIES = \ $(top_builddir)/src/tun/libgnunettun.la \ diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index e1677b35b..d1d8d4d6b 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -69,8 +69,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, GNUNET_HashCode mhash; GNUNET_HashCode chash; struct GNSNameRecordBlock *nrb; - struct GNSRecordBlock *rb; uint32_t rd_count; + char* rd_data = NULL; + int rd_len; unsigned int record_match; if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) @@ -94,53 +95,56 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, record_match = 0; rd_count = ntohl(nrb->rd_count); + rd_data = (char*)&nrb[1]; + rd_data += strlen(name) + 1; + rd_len = reply_block_size - (strlen(name) + 1 + + sizeof(struct GNSNameRecordBlock)); { struct GNUNET_NAMESTORE_RecordData rd[rd_count]; unsigned int i; uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); - - rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); + + if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_len, + rd_data, + rd_count, + rd)) + { + return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; + } + for (i=0; itype); - rd[i].expiration = - GNUNET_TIME_absolute_ntoh(rb->expiration); - rd[i].data_size = ntohl(rb->data_length); - rd[i].flags = ntohl(rb->flags); - rd[i].data = (char*)&rb[1]; - rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size); - - if (xquery_size == 0) - continue; + if (xquery_size < sizeof(uint32_t)) + continue; if (rd[i].record_type == record_xquery) - record_match++; + record_match++; } - } - /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, - name, - rd_count, - rd, - NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Signature invalid\n"); - return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; - }*/ + if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, + name, + rd_count, + rd, + NULL)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); + return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; + } + } //No record matches query if ((xquery_size > 0) && (record_match == 0)) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Records match\n"); - //FIXME do bf check before or after crypto?? + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n"); + if (NULL != bf) { GNUNET_CRYPTO_hash(reply_block, reply_block_size, &chash); GNUNET_BLOCK_mingle_hash(&chash, bf_mutator, &mhash); if (NULL != *bf) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Check BF\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check BF\n"); if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(*bf, &mhash)) return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; } @@ -150,7 +154,6 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, } GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash); } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No dup\n"); return GNUNET_BLOCK_EVALUATION_OK_MORE; } diff --git a/src/gns/test_gns_twopeer.c b/src/gns/test_gns_twopeer.c index 3bd36fb17..8ebb9611b 100644 --- a/src/gns/test_gns_twopeer.c +++ b/src/gns/test_gns_twopeer.c @@ -42,12 +42,15 @@ #include "gnunet_dht_service.h" #include "block_dns.h" #include "gnunet_signatures.h" +#include "gnunet_namestore_service.h" +#include "gnunet_dnsparser_lib.h" +#include "gnunet_gns_service.h" /* DEFINES */ #define VERBOSE GNUNET_YES /* Timeout for entire testcase */ -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80) /* If number of peers not in config file, use this number */ #define DEFAULT_NUM_PEERS 2 @@ -349,6 +352,12 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + struct GNUNET_NAMESTORE_Handle* namestore_handle; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey, bob_pkey; + struct GNUNET_CRYPTO_RsaPrivateKey *alice_key, *bob_key; + char* bob_keyfile; + char* alice_keyfile; + /* Get path from configuration file */ if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", @@ -366,26 +375,12 @@ run (void *cls, char *const *args, const char *cfgfile, /* Set peers_left so we know when all peers started */ peers_left = num_peers; - - /* Set up a task to end testing if peer start fails */ - die_task = - GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, - "didn't start all daemons in reasonable amount of time!!!"); - - alice_online = 0; - bob_online = 0; - expected_connections = 1; - - /* Start alice */ - d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, - NULL, NULL, NULL, &alice_started, NULL); /* Somebody care to explain? */ uint16_t port = 6000; uint32_t upnum = 23; uint32_t fdnum = 42; - /** * Modify some config options for bob * namely swap keys and disable dns hijacking @@ -400,8 +395,89 @@ run (void *cls, char *const *args, const char *cfgfile, "NO"); GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "ZONEKEY", "/tmp/bobkey"); - GNUNET_CONFIGURATION_set_value_string (cfg2, "gns", "TRUSTED", - "alice:/tmp/alicekey"); + + /* put records into namestore */ + namestore_handle = GNUNET_NAMESTORE_connect(cfg); + if (NULL == namestore_handle) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); + ok = -1; + return; + } + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns", + "ZONEKEY", + &alice_keyfile)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get alice's key from cfg\n"); + ok = -1; + return; + } + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg2, "gns", + "ZONEKEY", + &bob_keyfile)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get bob's key from cfg\n"); + ok = -1; + return; + } + + alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); + bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (bob_keyfile); + + GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); + GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); + + struct GNUNET_NAMESTORE_RecordData rd; + rd.data = &bob_pkey; + rd.expiration = GNUNET_TIME_absolute_get_forever (); + rd.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); + rd.record_type = GNUNET_GNS_RECORD_PKEY; + + GNUNET_NAMESTORE_record_create (namestore_handle, + alice_key, + "bob", + &rd, + NULL, + NULL); + + rd.data = &alice_pkey; + GNUNET_NAMESTORE_record_create (namestore_handle, + bob_key, + "alice", + &rd, + NULL, + NULL); + + char* ip = "127.0.0.1"; + struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); + GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); + + rd.data_size = sizeof(struct in_addr); + rd.data = web; + rd.record_type = GNUNET_DNSPARSER_TYPE_A; + + GNUNET_NAMESTORE_record_create (namestore_handle, + bob_key, + "www", + &rd, + NULL, + NULL); + + /* Set up a task to end testing if peer start fails */ + die_task = + GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, + "didn't start all daemons in reasonable amount of time!!!"); + + alice_online = 0; + bob_online = 0; + expected_connections = 1; + + /* Start alice */ + d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, + NULL, NULL, NULL, &alice_started, NULL); + //Start bob d2 = GNUNET_TESTING_daemon_start(cfg2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, -- 2.25.1