aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-29 13:04:16 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-29 13:04:16 +0000
commitdd64a1b6f257887bb3b7d4b44d2c117ff3592b7c (patch)
tree7622c9e337069df5ed99c2f60b83c90ce94efa5c /src
parent58b0c3ab02e3212465ca16d987313111d27952b3 (diff)
downloadgnunet-dd64a1b6f257887bb3b7d4b44d2c117ff3592b7c.tar.gz
gnunet-dd64a1b6f257887bb3b7d4b44d2c117ff3592b7c.zip
- adding sig purpose and test for lookup up
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_signatures.h6
-rw-r--r--src/namestore/gnunet-service-namestore.c28
-rw-r--r--src/namestore/test_namestore_api_lookup.c94
3 files changed, 102 insertions, 26 deletions
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 580282d82..ee105c62a 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -115,6 +115,12 @@ extern "C"
115 */ 115 */
116#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14 116#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14
117 117
118
119/**
120 * Signature of a gnunet naming system record block
121 */
122#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15
123
118#if 0 /* keep Emacsens' auto-indent happy */ 124#if 0 /* keep Emacsens' auto-indent happy */
119{ 125{
120#endif 126#endif
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index fe9165764..1fbf108d2 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -366,8 +366,6 @@ static void handle_lookup_name (void *cls,
366 lnc.record_type = type; 366 lnc.record_type = type;
367 res = GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, name, 0, &handle_lookup_name_it, &lnc); 367 res = GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, name, 0, &handle_lookup_name_it, &lnc);
368 368
369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE RESULTS: %u\n" , res);
370
371 GNUNET_SERVER_receive_done (client, GNUNET_OK); 369 GNUNET_SERVER_receive_done (client, GNUNET_OK);
372} 370}
373 371
@@ -432,6 +430,14 @@ static void handle_record_put (void *cls,
432 430
433 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1]; 431 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1];
434 name = (char *) &zone_key[1]; 432 name = (char *) &zone_key[1];
433
434 if (name[name_len -1] != '\0')
435 {
436 GNUNET_break_op (0);
437 GNUNET_SERVER_receive_done (client, GNUNET_OK);
438 return;
439 }
440
435 expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); 441 expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
436 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature; 442 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature;
437 rd_ser = &name[name_len]; 443 rd_ser = &name[name_len];
@@ -516,7 +522,14 @@ static void handle_record_create (void *cls,
516 GNUNET_SERVER_receive_done (client, GNUNET_OK); 522 GNUNET_SERVER_receive_done (client, GNUNET_OK);
517 return; 523 return;
518 } 524 }
519 525/*
526 if (name[name_len -1] != '\0')
527 {
528 GNUNET_break_op (0);
529 GNUNET_SERVER_receive_done (client, GNUNET_OK);
530 return;
531 }
532*/
520 /* DO WORK HERE */ 533 /* DO WORK HERE */
521 534
522 /* Send response */ 535 /* Send response */
@@ -584,7 +597,14 @@ static void handle_record_remove (void *cls,
584 GNUNET_SERVER_receive_done (client, GNUNET_OK); 597 GNUNET_SERVER_receive_done (client, GNUNET_OK);
585 return; 598 return;
586 } 599 }
587 600/*
601 if (name[name_len -1] != '\0')
602 {
603 GNUNET_break_op (0);
604 GNUNET_SERVER_receive_done (client, GNUNET_OK);
605 return;
606 }
607 */
588 /* DO WORK HERE */ 608 /* DO WORK HERE */
589 609
590 /* Send response */ 610 /* Send response */
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c
index fafe5f218..d20a1cdaf 100644
--- a/src/namestore/test_namestore_api_lookup.c
+++ b/src/namestore/test_namestore_api_lookup.c
@@ -24,6 +24,8 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
27#include "namestore.h"
28#include "gnunet_signatures.h"
27 29
28#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
29 31
@@ -41,10 +43,12 @@ static struct GNUNET_OS_Process *arm;
41 43
42static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; 44static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
43static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 45static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
44static GNUNET_HashCode zone; 46struct GNUNET_CRYPTO_RsaSignature s_signature;
45static char *name; 47static GNUNET_HashCode s_zone;
48struct GNUNET_NAMESTORE_RecordData *s_rd;
49static char *s_name;
50
46 51
47struct GNUNET_NAMESTORE_RecordData *rd;
48 52
49static int res; 53static int res;
50 54
@@ -107,6 +111,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
107 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 111 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
108 } 112 }
109 113
114 int c;
115 for (c = 0; c < RECORDS; c++)
116 GNUNET_free_non_null((void *) s_rd[c].data);
117 GNUNET_free (s_rd);
118
110 if (privkey != NULL) 119 if (privkey != NULL)
111 GNUNET_CRYPTO_rsa_key_free (privkey); 120 GNUNET_CRYPTO_rsa_key_free (privkey);
112 privkey = NULL; 121 privkey = NULL;
@@ -128,9 +137,43 @@ void name_lookup_proc (void *cls,
128 const struct GNUNET_CRYPTO_RsaSignature *signature) 137 const struct GNUNET_CRYPTO_RsaSignature *signature)
129{ 138{
130 static int found = GNUNET_NO; 139 static int found = GNUNET_NO;
140 int failed = GNUNET_NO;
141 int c;
131 142
132 if (n != NULL) 143 if (n != NULL)
133 { 144 {
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
146 if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
147 {
148 GNUNET_break (0);
149 failed = GNUNET_YES;
150 }
151
152 if (0 != memcmp (signature, &s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
153 {
154 GNUNET_break (0);
155 failed = GNUNET_YES;
156 }
157
158 if (0 != strcmp(n, s_name))
159 {
160 GNUNET_break (0);
161 failed = GNUNET_YES;
162 }
163
164 if (RECORDS != rd_count)
165 {
166 GNUNET_break (0);
167 failed = GNUNET_YES;
168 }
169
170 for (c = 0; c < RECORDS; c++)
171 {
172 GNUNET_break (rd[c].expiration.abs_value == s_rd[c].expiration.abs_value);
173 GNUNET_break (rd[c].record_type == TEST_RECORD_TYPE);
174 GNUNET_break (rd[c].data_size == TEST_RECORD_DATALEN);
175 GNUNET_break (0 == memcmp (rd[c].data, s_rd[c].data, TEST_RECORD_DATALEN));
176 }
134 found = GNUNET_YES; 177 found = GNUNET_YES;
135 res = 0; 178 res = 0;
136 } 179 }
@@ -138,12 +181,11 @@ void name_lookup_proc (void *cls,
138 { 181 {
139 if (found != GNUNET_YES) 182 if (found != GNUNET_YES)
140 { 183 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", name); 184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name);
142 res = 1; 185 res = 1;
143 } 186 }
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", name); 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name);
145 } 188 }
146
147 GNUNET_SCHEDULER_add_now(&end, NULL); 189 GNUNET_SCHEDULER_add_now(&end, NULL);
148} 190}
149 191
@@ -156,7 +198,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
156 if (success == GNUNET_OK) 198 if (success == GNUNET_OK)
157 { 199 {
158 res = 0; 200 res = 0;
159 GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); 201 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_proc, NULL);
160 } 202 }
161 else 203 else
162 { 204 {
@@ -190,6 +232,8 @@ run (void *cls, char *const *args, const char *cfgfile,
190 const struct GNUNET_CONFIGURATION_Handle *cfg) 232 const struct GNUNET_CONFIGURATION_Handle *cfg)
191{ 233{
192 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 234 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
235 char * rd_ser;
236 size_t rd_ser_len;
193 237
194 /* load privat key */ 238 /* load privat key */
195 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); 239 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
@@ -197,10 +241,23 @@ run (void *cls, char *const *args, const char *cfgfile,
197 /* get public key */ 241 /* get public key */
198 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 242 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
199 243
200 /* create random zone hash */ 244 /* create record */
201 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); 245 s_name = "dummy.dummy.gnunet";
246 s_rd = create_record (RECORDS);
247 rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, RECORDS, s_rd);
248
249 /* sign */
250 struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + rd_ser_len);
251 sig_purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)+ rd_ser_len);
252 sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
253 memcpy (&sig_purpose[1], rd_ser, rd_ser_len);
254 GNUNET_CRYPTO_rsa_sign (privkey, sig_purpose, &s_signature);
202 255
203 struct GNUNET_CRYPTO_RsaSignature signature; 256 GNUNET_free (rd_ser);
257 GNUNET_free (sig_purpose);
258
259 /* create random zone hash */
260 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
204 261
205 start_arm (cfgfile); 262 start_arm (cfgfile);
206 GNUNET_assert (arm != NULL); 263 GNUNET_assert (arm != NULL);
@@ -208,21 +265,14 @@ run (void *cls, char *const *args, const char *cfgfile,
208 nsh = GNUNET_NAMESTORE_connect (cfg); 265 nsh = GNUNET_NAMESTORE_connect (cfg);
209 GNUNET_break (NULL != nsh); 266 GNUNET_break (NULL != nsh);
210 267
211 /* create record */
212 name = "dummy.dummy.gnunet";
213 rd = create_record (RECORDS);
214 268
215 GNUNET_break (rd != NULL);
216 GNUNET_break (name != NULL);
217 269
218 GNUNET_NAMESTORE_record_put (nsh, &pubkey, name, 270 GNUNET_break (s_rd != NULL);
219 GNUNET_TIME_absolute_get_forever(), 271 GNUNET_break (s_name != NULL);
220 RECORDS, rd, &signature, put_cont, name);
221 272
222 int c; 273 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
223 for (c = 0; c < RECORDS; c++) 274 GNUNET_TIME_absolute_get_forever(),
224 GNUNET_free_non_null((void *) rd[c].data); 275 RECORDS, s_rd, &s_signature, put_cont, s_name);
225 GNUNET_free (rd);
226 276
227} 277}
228 278