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)
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; i<rd_count; i++)
{
- rd[i].record_type = ntohl(rb->type);
- 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;
}
}
GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash);
}
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No dup\n");
return GNUNET_BLOCK_EVALUATION_OK_MORE;
}
#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
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",
/* 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
"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,