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