a4c337067f47c838ec2ed2266e02dad3de978f38
[oweals/gnunet.git] / src / gns / test_gns_pseu_shorten.c
1 /*
2      This file is part of GNUnet.
3      (C) 2012,2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file gns/test_gns_pseu_shorten.c
22  * @brief base testcase for testing on the fly pseu import and shorten
23  * @author Martin Schanzenbach
24  */
25 #include "platform.h"
26 #include "gnunet_testing_lib.h"
27 #include "gnunet_core_service.h"
28 #include "block_gns.h"
29 #include "gnunet_signatures.h"
30 #include "gnunet_namestore_service.h"
31 #include "../namestore/namestore.h"
32 #include "gnunet_dnsparser_lib.h"
33 #include "gnunet_dht_service.h"
34 #include "gnunet_gns_service.h"
35
36 /* Timeout for entire testcase */
37 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
38
39 /* test records to resolve */
40 #define TEST_DOMAIN "www.alicewonderland.bobbuilder.gnu"
41 #define TEST_IP "127.0.0.1"
42 #define TEST_RECORD_NAME "www"
43
44 #define TEST_PRIVATE_ZONE "private"
45 #define TEST_SHORTEN_ZONE "short"
46 #define TEST_AUTHORITY_BOB "bobbuilder"
47 #define TEST_AUTHORITY_ALICE "alicewonderland"
48 #define TEST_PSEU_ALICE "carol"
49 #define TEST_EXPECTED_RESULT "www.carol.short.private.gnu"
50
51 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
52
53 #define KEYFILE_SHORTEN = "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey"
54 #define KEYFILE_PRIVATE = "zonefiles/OEFL7A4VEF1B40QLEMTG5D8G1CN6EN16QUSG5R2DT71GRJN34LSG.zkey"
55
56 /* Globals */
57
58 /* Task handle to use to schedule test failure */
59 static GNUNET_SCHEDULER_TaskIdentifier die_task;
60
61 /* Global return value (0 for success, anything else for failure) */
62 static int ok;
63
64 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
65
66 static struct GNUNET_GNS_Handle *gns_handle;
67
68 static struct GNUNET_DHT_Handle *dht_handle;
69
70 static const struct GNUNET_CONFIGURATION_Handle *cfg;
71
72 static struct GNUNET_CRYPTO_EccPublicSignKey alice_pkey;
73 static struct GNUNET_CRYPTO_EccPublicSignKey bob_pkey;
74 static struct GNUNET_CRYPTO_EccPublicSignKey our_pkey;
75 static struct GNUNET_CRYPTO_EccPublicSignKey priv_pkey;
76 static struct GNUNET_CRYPTO_EccPublicSignKey short_pkey;
77 static struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
78 static struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
79 static struct GNUNET_CRYPTO_EccPrivateKey *our_key;
80 static struct GNUNET_CRYPTO_EccPrivateKey *priv_key;
81 static struct GNUNET_CRYPTO_EccPrivateKey *short_key;
82 static struct GNUNET_CRYPTO_ShortHashCode alice_hash;
83 static struct GNUNET_CRYPTO_ShortHashCode bob_hash;
84 static struct GNUNET_CRYPTO_ShortHashCode our_zone;
85 static struct GNUNET_CRYPTO_ShortHashCode priv_zone;
86 static struct GNUNET_CRYPTO_ShortHashCode short_zone;
87
88
89 /**
90  * Check if the get_handle is being used, if so stop the request.  Either
91  * way, schedule the end_badly_cont function which actually shuts down the
92  * test.
93  */
94 static void
95 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 {
97   die_task = GNUNET_SCHEDULER_NO_TASK;
98   if (NULL != gns_handle)
99   {
100     GNUNET_GNS_disconnect(gns_handle);
101     gns_handle = NULL;
102   }
103
104   if (NULL != namestore_handle)
105   {
106     GNUNET_NAMESTORE_disconnect (namestore_handle);
107     namestore_handle = NULL;
108   }
109
110   if (NULL != dht_handle)
111   {
112     GNUNET_DHT_disconnect (dht_handle);
113     dht_handle = NULL;
114   }
115
116   GNUNET_break (0);
117   GNUNET_SCHEDULER_shutdown ();
118   ok = 1;
119 }
120
121
122 static void
123 end_badly_now ()
124 {
125   GNUNET_SCHEDULER_cancel (die_task);
126   die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
127 }
128
129
130 static void
131 shutdown_task (void *cls,
132                const struct GNUNET_SCHEDULER_TaskContext *tc)
133 {
134   GNUNET_GNS_disconnect(gns_handle);
135   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
136   GNUNET_SCHEDULER_shutdown ();
137 }
138
139 /**
140  * Called when gns shorten finishes
141  */
142 static void
143 process_shorten_result (void* cls, const char* sname)
144 {
145
146   if (GNUNET_SCHEDULER_NO_TASK != die_task)
147   {
148       GNUNET_SCHEDULER_cancel (die_task);
149       die_task = GNUNET_SCHEDULER_NO_TASK;
150   }
151
152   if (NULL != dht_handle)
153   {
154     GNUNET_DHT_disconnect (dht_handle);
155     dht_handle = NULL;
156   }
157
158   if (sname == NULL)
159   {
160     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
161                 "shorten test failed!\n");
162     ok = 1;
163   }
164   else
165   {
166     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167                 "%s shortened to %s\n", (char*)cls, sname);
168     if (0 != strcmp(sname, TEST_EXPECTED_RESULT))
169     {
170       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
171                   "shorten test failed! (wanted: %s got: %s)\n",
172                   TEST_EXPECTED_RESULT, sname);
173       ok = 1;
174     }
175
176     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shorten test succeeded!\n");
177   }
178   GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
179 }
180
181
182 static void
183 on_lookup_result (void *cls, uint32_t rd_count,
184                   const struct GNUNET_NAMESTORE_RecordData *rd)
185 {
186   struct in_addr a;
187   int i;
188   char* addr;
189
190   if (rd_count == 0)
191   {
192     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
193                 "Lookup failed, rp_filtering?\n");
194     ok = 2;
195   }
196   else
197   {
198     ok = 1;
199     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
200     for (i=0; i<rd_count; i++)
201     {
202       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
203       if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
204       {
205         memcpy(&a, rd[i].data, sizeof(a));
206         addr = inet_ntoa(a);
207         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
208         if (0 == strcmp(addr, TEST_IP))
209         {
210           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
211                     "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
212           ok = 0;
213         }
214       }
215       else
216       {
217         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
218       }
219     }
220   }
221   GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
222                            &priv_zone,
223                            &short_zone,
224                            &our_zone,
225                            &process_shorten_result,
226                            TEST_DOMAIN);
227 }
228
229
230 /**
231  * Function scheduled to be run on the successful start of services
232  * tries to look up the dns record for TEST_DOMAIN
233  */
234 static void
235 commence_testing (void *cls, int success)
236 {
237   GNUNET_free(our_key);
238   GNUNET_free(bob_key);
239   GNUNET_free(alice_key);
240   GNUNET_NAMESTORE_disconnect (namestore_handle);
241   namestore_handle = NULL;
242   gns_handle = GNUNET_GNS_connect(cfg);
243   if (NULL == gns_handle)
244   {
245     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246                 "Failed to connect to GNS!\n");
247   }
248   GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN,
249                           &our_zone,
250                           GNUNET_DNSPARSER_TYPE_A,
251                           GNUNET_NO,
252                           short_key,
253                           &on_lookup_result, TEST_DOMAIN);
254 }
255
256
257 static void
258 put_pseu_dht (void *cls, int success)
259 {
260   struct GNSNameRecordBlock *nrb;
261   struct GNUNET_CRYPTO_ShortHashCode name_hash;
262   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
263   struct GNUNET_HashCode xor_hash;
264   struct GNUNET_HashCode name_hash_double;
265   struct GNUNET_HashCode zone_hash_double;
266   uint32_t rd_payload_length;
267   char* nrb_data = NULL;
268   struct GNUNET_CRYPTO_EccSignature *sig;
269   struct GNUNET_NAMESTORE_RecordData rd;
270
271   memset (&rd, 0, sizeof (struct GNUNET_NAMESTORE_RecordData));
272   rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
273   rd.data_size = strlen(TEST_PSEU_ALICE)+1;
274   rd.data = TEST_PSEU_ALICE;
275   rd.record_type = GNUNET_NAMESTORE_TYPE_PSEU;
276   rd.flags = 0;
277
278   sig = GNUNET_NAMESTORE_create_signature(alice_key,
279                                            GNUNET_TIME_UNIT_FOREVER_ABS,
280                                            GNUNET_GNS_MASTERZONE_STR,
281                                            &rd, 1);
282
283   GNUNET_assert (NULL != sig);
284
285   GNUNET_break (GNUNET_OK == GNUNET_NAMESTORE_verify_signature (&alice_pkey,
286                                                                  GNUNET_TIME_UNIT_FOREVER_ABS,
287                                                                  GNUNET_GNS_MASTERZONE_STR,
288                                                                  1,
289                                                                  &rd,
290                                                                  sig));
291   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
292   nrb = GNUNET_malloc(rd_payload_length + strlen(GNUNET_GNS_MASTERZONE_STR) + 1
293                       + sizeof(struct GNSNameRecordBlock));
294   nrb->signature = *sig;
295   nrb->public_key = alice_pkey;
296   nrb->rd_count = htonl(1);
297   memset(&nrb[1], 0, strlen(GNUNET_GNS_MASTERZONE_STR) + 1);
298   strcpy((char*)&nrb[1], GNUNET_GNS_MASTERZONE_STR);
299   nrb_data = (char*)&nrb[1];
300   nrb_data += strlen(GNUNET_GNS_MASTERZONE_STR) + 1;
301
302   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
303                                                 &rd,
304                                                 rd_payload_length,
305                                                 nrb_data))
306   {
307     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
308     ok = 3;
309     GNUNET_free(our_key);
310     GNUNET_free(bob_key);
311     GNUNET_free(alice_key);
312     GNUNET_free(sig);
313     GNUNET_free (nrb);
314     end_badly_now ();
315     return;
316   }
317   GNUNET_CRYPTO_short_hash(GNUNET_GNS_MASTERZONE_STR, strlen(GNUNET_GNS_MASTERZONE_STR), &name_hash);
318   GNUNET_CRYPTO_short_hash(&alice_pkey,
319                      sizeof(struct GNUNET_CRYPTO_EccPublicSignKey),
320                      &zone_hash);
321
322   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
323   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
324   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
325
326   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
327     strlen(GNUNET_GNS_MASTERZONE_STR) + 1;
328
329   GNUNET_DHT_put (dht_handle, &xor_hash,
330                   0,
331                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
332                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
333                   rd_payload_length,
334                   (char*)nrb,
335                   GNUNET_TIME_UNIT_FOREVER_ABS,
336                   DHT_OPERATION_TIMEOUT,
337                   &commence_testing,
338                   NULL);
339
340   GNUNET_free(sig);
341   GNUNET_free (nrb);
342 }
343
344
345 static void
346 put_www_dht (void *cls, int success)
347 {
348   struct GNSNameRecordBlock *nrb;
349   struct GNUNET_CRYPTO_ShortHashCode name_hash;
350   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
351   struct GNUNET_HashCode xor_hash;
352   struct GNUNET_HashCode name_hash_double;
353   struct GNUNET_HashCode zone_hash_double;
354   uint32_t rd_payload_length;
355   char* nrb_data = NULL;
356   struct GNUNET_CRYPTO_EccSignature *sig;
357   struct GNUNET_NAMESTORE_RecordData rd;
358   char* ip = TEST_IP;
359   struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
360
361   rd.expiration_time = UINT64_MAX;
362   GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
363   rd.data_size = sizeof(struct in_addr);
364   rd.data = web;
365   rd.record_type = GNUNET_DNSPARSER_TYPE_A;
366   rd.flags = GNUNET_NAMESTORE_RF_NONE;
367
368   sig = GNUNET_NAMESTORE_create_signature(alice_key,
369                                           GNUNET_TIME_UNIT_FOREVER_ABS,
370                                           TEST_RECORD_NAME,
371                                           &rd, 1);
372
373   GNUNET_break (GNUNET_OK == GNUNET_NAMESTORE_verify_signature (&alice_pkey,
374                                                                  GNUNET_TIME_UNIT_FOREVER_ABS,
375                                                                  TEST_RECORD_NAME,
376                                                                  1,
377                                                                  &rd,
378                                                                  sig));
379   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
380   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1
381                       + sizeof(struct GNSNameRecordBlock));
382   nrb->signature = *sig;
383   nrb->public_key = alice_pkey;
384   nrb->rd_count = htonl(1);
385   memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
386   strcpy((char*)&nrb[1], TEST_RECORD_NAME);
387   nrb_data = (char*)&nrb[1];
388   nrb_data += strlen(TEST_RECORD_NAME) + 1;
389
390   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
391                                                 &rd,
392                                                 rd_payload_length,
393                                                 nrb_data))
394   {
395     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
396     ok = 3;
397     GNUNET_free(our_key);
398     GNUNET_free(bob_key);
399     GNUNET_free(alice_key);
400     GNUNET_free (sig);
401     GNUNET_free(web);
402     GNUNET_free (nrb);
403     end_badly_now();
404     return;
405   }
406   GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
407   GNUNET_CRYPTO_short_hash(&alice_pkey,
408                      sizeof(struct GNUNET_CRYPTO_EccPublicSignKey),
409                      &zone_hash);
410   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
411   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
412   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
413
414   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
415     strlen(TEST_RECORD_NAME) + 1;
416
417   GNUNET_DHT_put (dht_handle, &xor_hash,
418                   0,
419                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
420                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
421                   rd_payload_length,
422                   (char*)nrb,
423                   GNUNET_TIME_UNIT_FOREVER_ABS,
424                   DHT_OPERATION_TIMEOUT,
425                   &put_pseu_dht,
426                   NULL);
427   GNUNET_free (sig);
428   GNUNET_free (web);
429   GNUNET_free (nrb);
430 }
431
432
433 static void
434 put_pkey_dht (void *cls, int32_t success, const char *emsg)
435 {
436   struct GNSNameRecordBlock *nrb;
437   struct GNUNET_CRYPTO_ShortHashCode name_hash;
438   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
439   struct GNUNET_HashCode xor_hash;
440   struct GNUNET_HashCode name_hash_double;
441   struct GNUNET_HashCode zone_hash_double;
442   uint32_t rd_payload_length;
443   char* nrb_data = NULL;
444   struct GNUNET_CRYPTO_EccSignature *sig;
445   struct GNUNET_NAMESTORE_RecordData rd;
446
447   rd.expiration_time = UINT64_MAX;
448   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
449   rd.data = &alice_hash;
450   rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
451   rd.flags = GNUNET_NAMESTORE_RF_NONE;
452
453   sig = GNUNET_NAMESTORE_create_signature (bob_key,
454                                            GNUNET_TIME_UNIT_FOREVER_ABS,
455                                            TEST_AUTHORITY_ALICE,
456                                            &rd,
457                                            1);
458
459   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
460   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_AUTHORITY_ALICE) + 1
461                       + sizeof(struct GNSNameRecordBlock));
462   nrb->signature = *sig;
463   nrb->public_key = bob_pkey;
464   nrb->rd_count = htonl(1);
465   memset(&nrb[1], 0, strlen(TEST_AUTHORITY_ALICE) + 1);
466   strcpy((char*)&nrb[1], TEST_AUTHORITY_ALICE);
467   nrb_data = (char*)&nrb[1];
468   nrb_data += strlen(TEST_AUTHORITY_ALICE) + 1;
469
470   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
471                                                 &rd,
472                                                 rd_payload_length,
473                                                 nrb_data))
474   {
475     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
476     ok = 3;
477
478     GNUNET_free (our_key);
479     GNUNET_free (bob_key);
480     GNUNET_free (alice_key);
481     GNUNET_free (sig);
482     GNUNET_free (nrb);
483     end_badly_now ();
484     return;
485   }
486
487
488   GNUNET_CRYPTO_short_hash (TEST_AUTHORITY_ALICE,
489                             strlen (TEST_AUTHORITY_ALICE), &name_hash);
490   GNUNET_CRYPTO_short_hash (&bob_pkey,
491                             sizeof(struct GNUNET_CRYPTO_EccPublicSignKey),
492                             &zone_hash);
493   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
494   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
495   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
496
497   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
498     strlen(TEST_AUTHORITY_ALICE) + 1;
499   GNUNET_DHT_put (dht_handle, &xor_hash,
500                   0,
501                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
502                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
503                   rd_payload_length,
504                   (char*)nrb,
505                   GNUNET_TIME_UNIT_FOREVER_ABS,
506                   DHT_OPERATION_TIMEOUT,
507                   &put_www_dht,
508                   NULL);
509   GNUNET_free (sig);
510   GNUNET_free (nrb);
511 }
512
513
514 static void
515 fin_init_zone (void *cls, int32_t success, const char *emsg)
516 {
517   struct GNUNET_NAMESTORE_RecordData rd;
518   rd.expiration_time = UINT64_MAX;
519   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
520   rd.data = &bob_hash;
521   rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
522   rd.flags = GNUNET_NAMESTORE_RF_NONE;
523
524   GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
525                                             our_key,
526                                             TEST_AUTHORITY_BOB,
527                                             1, &rd,
528                                             &put_pkey_dht,
529                                             NULL);
530 }
531
532
533 static void
534 cont_init_zone (void *cls, int32_t success, const char *emsg)
535 {
536
537   struct GNUNET_NAMESTORE_RecordData rd;
538
539   rd.expiration_time = UINT64_MAX;
540   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
541   rd.data = &short_zone;
542   rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
543   rd.flags = GNUNET_NAMESTORE_RF_NONE;
544
545   GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
546                                             priv_key,
547                                             TEST_SHORTEN_ZONE,
548                                             1, &rd,
549                                             &fin_init_zone,
550                                             NULL);
551 }
552
553
554 static void
555 do_check (void *cls,
556           const struct GNUNET_CONFIGURATION_Handle *ccfg,
557           struct GNUNET_TESTING_Peer *peer)
558 {
559   char *private_keyfile;
560   char *shorten_keyfile;
561   char *our_keyfile;
562   struct GNUNET_NAMESTORE_RecordData rd;
563
564   cfg = ccfg;
565   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
566
567   /* put records into namestore */
568   namestore_handle = GNUNET_NAMESTORE_connect(cfg);
569   if (NULL == namestore_handle)
570   {
571     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
572     end_badly_now();
573     return;
574   }
575
576   /* dht */
577   dht_handle = GNUNET_DHT_connect(cfg, 1);
578   if (NULL == dht_handle)
579   {
580     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n");
581     end_badly_now();
582     return;
583   }
584
585   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
586                                                             "ZONEKEY",
587                                                             &our_keyfile))
588   {
589     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
590     end_badly_now();
591     GNUNET_free (our_keyfile);
592     return;
593   }
594
595   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
596                                                             "SHORTEN_ZONEKEY",
597                                                             &shorten_keyfile))
598   {
599     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
600                "Failed to get shorten zone key from cfg\n");
601     end_badly_now();
602     GNUNET_free (our_keyfile);
603     GNUNET_free (shorten_keyfile);
604     return;
605   }
606
607   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
608                                                             "PRIVATE_ZONEKEY",
609                                                             &private_keyfile))
610   {
611     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
612                "Failed to get private zone key from cfg\n");
613     end_badly_now();
614     GNUNET_free (our_keyfile);
615     GNUNET_free (shorten_keyfile);
616     GNUNET_free (private_keyfile);
617     return;
618   }
619   our_key = GNUNET_CRYPTO_ecc_key_create_from_file (our_keyfile);
620   priv_key = GNUNET_CRYPTO_ecc_key_create_from_file (private_keyfile);
621   short_key = GNUNET_CRYPTO_ecc_key_create_from_file (shorten_keyfile);
622   bob_key = GNUNET_CRYPTO_ecc_key_create ();
623   alice_key = GNUNET_CRYPTO_ecc_key_create ();
624
625   GNUNET_free (our_keyfile);
626   GNUNET_free (shorten_keyfile);
627   GNUNET_free (private_keyfile);
628
629   GNUNET_CRYPTO_ecc_key_get_public_for_signature (our_key, &our_pkey);
630   GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv_key, &priv_pkey);
631   GNUNET_CRYPTO_ecc_key_get_public_for_signature (short_key, &short_pkey);
632   GNUNET_CRYPTO_ecc_key_get_public_for_signature (bob_key, &bob_pkey);
633   GNUNET_CRYPTO_ecc_key_get_public_for_signature (alice_key, &alice_pkey);
634   GNUNET_CRYPTO_short_hash (&bob_pkey, sizeof(bob_pkey), &bob_hash);
635   GNUNET_CRYPTO_short_hash (&alice_pkey, sizeof(alice_pkey), &alice_hash);
636   GNUNET_CRYPTO_short_hash (&our_pkey, sizeof(our_pkey), &our_zone);
637   GNUNET_CRYPTO_short_hash (&priv_pkey, sizeof(priv_pkey), &priv_zone);
638   GNUNET_CRYPTO_short_hash (&short_pkey, sizeof(short_pkey), &short_zone);
639
640   rd.expiration_time = UINT64_MAX;
641   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
642   rd.data = &priv_zone;
643   rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
644   rd.flags = GNUNET_NAMESTORE_RF_NONE;
645
646   GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
647                                             our_key,
648                                             TEST_PRIVATE_ZONE,
649                                             1, &rd,
650                                             &cont_init_zone,
651                                             NULL);
652 }
653
654
655 int
656 main (int argc, char *argv[])
657 {
658   ok = 1;
659   GNUNET_log_setup ("test-gns-pseu-shorten",
660                     "WARNING",
661                     NULL);
662   GNUNET_TESTING_peer_run ("test-gns-pseu-shorten", "test_gns_simple_lookup.conf", &do_check, NULL);
663   return ok;
664 }
665
666 /* end of test_gns_pseu_shorten.c */