aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/Makefile.am18
-rw-r--r--src/gnsrecord/gnsrecord.c21
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c58
-rw-r--r--src/gnsrecord/gnsrecord_misc.c250
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c226
-rw-r--r--src/gnsrecord/perf_gnsrecord_crypto.c6
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c7
-rw-r--r--src/gnsrecord/test_gnsrecord_block_expiration.c6
-rw-r--r--src/gnsrecord/test_gnsrecord_testvectors.c33
9 files changed, 423 insertions, 202 deletions
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 4308d9c1a..e2538b1a2 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -20,7 +20,6 @@ check_PROGRAMS = \
20 test_gnsrecord_crypto \ 20 test_gnsrecord_crypto \
21 test_gnsrecord_serialization \ 21 test_gnsrecord_serialization \
22 test_gnsrecord_block_expiration \ 22 test_gnsrecord_block_expiration \
23 test_gnsrecord_testvectors \
24 perf_gnsrecord_crypto 23 perf_gnsrecord_crypto
25 24
26if ENABLE_TEST_RUN 25if ENABLE_TEST_RUN
@@ -35,7 +34,8 @@ lib_LTLIBRARIES = \
35 libgnunetgnsrecordjson.la 34 libgnunetgnsrecordjson.la
36 35
37gnunet_gnsrecord_tvg_SOURCES = \ 36gnunet_gnsrecord_tvg_SOURCES = \
38 gnunet-gnsrecord-tvg.c 37 gnunet-gnsrecord-tvg.c \
38 gnsrecord_crypto.h
39gnunet_gnsrecord_tvg_LDADD = \ 39gnunet_gnsrecord_tvg_LDADD = \
40 $(top_builddir)/src/util/libgnunetutil.la \ 40 $(top_builddir)/src/util/libgnunetutil.la \
41 $(top_builddir)/src/identity/libgnunetidentity.la \ 41 $(top_builddir)/src/identity/libgnunetidentity.la \
@@ -86,13 +86,13 @@ libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \
86EXTRA_DIST = \ 86EXTRA_DIST = \
87 $(check_SCRIPTS) 87 $(check_SCRIPTS)
88 88
89test_gnsrecord_testvectors_SOURCES = \ 89#test_gnsrecord_testvectors_SOURCES = \
90 test_gnsrecord_testvectors.c 90# test_gnsrecord_testvectors.c
91test_gnsrecord_testvectors_LDADD = \ 91#test_gnsrecord_testvectors_LDADD = \
92 $(top_builddir)/src/testing/libgnunettesting.la \ 92# $(top_builddir)/src/testing/libgnunettesting.la \
93 $(top_builddir)/src/identity/libgnunetidentity.la \ 93# $(top_builddir)/src/identity/libgnunetidentity.la \
94 libgnunetgnsrecord.la \ 94# libgnunetgnsrecord.la \
95 $(top_builddir)/src/util/libgnunetutil.la 95# $(top_builddir)/src/util/libgnunetutil.la
96 96
97 97
98test_gnsrecord_serialization_SOURCES = \ 98test_gnsrecord_serialization_SOURCES = \
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
index e9994a868..52c480ef6 100644
--- a/src/gnsrecord/gnsrecord.c
+++ b/src/gnsrecord/gnsrecord.c
@@ -260,4 +260,25 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type)
260} 260}
261 261
262 262
263enum GNUNET_GenericReturnValue
264GNUNET_GNSRECORD_is_critical (uint32_t type)
265{
266 struct Plugin *plugin;
267
268 if (GNUNET_GNSRECORD_TYPE_ANY == type)
269 return GNUNET_NO;
270 init ();
271 for (unsigned int i = 0; i < num_plugins; i++)
272 {
273 plugin = gns_plugins[i];
274 if (NULL == plugin->api->is_critical)
275 continue;
276 if (GNUNET_NO == plugin->api->is_critical (plugin->api->cls, type))
277 continue;
278 return GNUNET_YES;
279 }
280 return GNUNET_NO;
281}
282
283
263/* end of gnsrecord.c */ 284/* end of gnsrecord.c */
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index 890ddb011..ff92911de 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -223,7 +223,6 @@ block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
223 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; 223 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
224 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH]; 224 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
225 struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)]; 225 struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)];
226 uint32_t rd_count_nbo;
227 struct GNUNET_TIME_Absolute now; 226 struct GNUNET_TIME_Absolute now;
228 227
229 if (payload_len < 0) 228 if (payload_len < 0)
@@ -254,7 +253,6 @@ block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
254 /* serialize */ 253 /* serialize */
255 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + payload_len); 254 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + payload_len);
256 (*block)->size = htonl(sizeof (struct GNUNET_GNSRECORD_Block) + payload_len); 255 (*block)->size = htonl(sizeof (struct GNUNET_GNSRECORD_Block) + payload_len);
257 rd_count_nbo = htonl (rd_count);
258 { 256 {
259 char payload[payload_len]; 257 char payload[payload_len];
260 258
@@ -282,12 +280,12 @@ block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
282 label, 280 label,
283 ecblock->expiration_time.abs_value_us__, 281 ecblock->expiration_time.abs_value_us__,
284 pkey); 282 pkey);
285 GNUNET_break (payload_len == 283 GNUNET_assert (payload_len ==
286 ecdsa_symmetric_encrypt (payload, 284 ecdsa_symmetric_encrypt (payload,
287 payload_len, 285 payload_len,
288 skey, 286 skey,
289 ctr, 287 ctr,
290 &ecblock[1])); 288 &ecblock[1]));
291 GNUNET_memcpy (&gnr_block[1], &ecblock[1], payload_len); 289 GNUNET_memcpy (&gnr_block[1], &ecblock[1], payload_len);
292 } 290 }
293 if (GNUNET_OK != 291 if (GNUNET_OK !=
@@ -298,8 +296,10 @@ block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
298 GNUNET_break (0); 296 GNUNET_break (0);
299 GNUNET_free (*block); 297 GNUNET_free (*block);
300 GNUNET_free (dkey); 298 GNUNET_free (dkey);
299 GNUNET_free (gnr_block);
301 return GNUNET_SYSERR; 300 return GNUNET_SYSERR;
302 } 301 }
302 GNUNET_free (gnr_block);
303 GNUNET_free (dkey); 303 GNUNET_free (dkey);
304 return GNUNET_OK; 304 return GNUNET_OK;
305} 305}
@@ -348,7 +348,6 @@ block_create_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key,
348 unsigned char nonce[crypto_secretbox_NONCEBYTES]; 348 unsigned char nonce[crypto_secretbox_NONCEBYTES];
349 unsigned char skey[crypto_secretbox_KEYBYTES]; 349 unsigned char skey[crypto_secretbox_KEYBYTES];
350 struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)]; 350 struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)];
351 uint32_t rd_count_nbo;
352 struct GNUNET_TIME_Absolute now; 351 struct GNUNET_TIME_Absolute now;
353 352
354 if (payload_len < 0) 353 if (payload_len < 0)
@@ -381,7 +380,6 @@ block_create_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key,
381 + payload_len + crypto_secretbox_MACBYTES); 380 + payload_len + crypto_secretbox_MACBYTES);
382 (*block)->size = htonl(sizeof (struct GNUNET_GNSRECORD_Block) 381 (*block)->size = htonl(sizeof (struct GNUNET_GNSRECORD_Block)
383 + payload_len + crypto_secretbox_MACBYTES); 382 + payload_len + crypto_secretbox_MACBYTES);
384 rd_count_nbo = htonl (rd_count);
385 { 383 {
386 char payload[payload_len]; 384 char payload[payload_len];
387 385
@@ -415,12 +413,12 @@ block_create_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key,
415 label, 413 label,
416 edblock->expiration_time.abs_value_us__, 414 edblock->expiration_time.abs_value_us__,
417 pkey); 415 pkey);
418 GNUNET_break (GNUNET_OK == 416 GNUNET_assert (GNUNET_OK ==
419 eddsa_symmetric_encrypt (payload, 417 eddsa_symmetric_encrypt (payload,
420 payload_len, 418 payload_len,
421 skey, 419 skey,
422 nonce, 420 nonce,
423 &edblock[1])); 421 &edblock[1]));
424 GNUNET_memcpy (&gnr_block[1], &edblock[1], 422 GNUNET_memcpy (&gnr_block[1], &edblock[1],
425 payload_len + crypto_secretbox_MACBYTES); 423 payload_len + crypto_secretbox_MACBYTES);
426 424
@@ -438,7 +436,7 @@ GNUNET_GNSRECORD_block_calculate_size (const struct
438 unsigned int rd_count) 436 unsigned int rd_count)
439{ 437{
440 struct GNUNET_IDENTITY_PublicKey pkey; 438 struct GNUNET_IDENTITY_PublicKey pkey;
441 ssize_t res; 439 ssize_t res = -1;
442 440
443 GNUNET_IDENTITY_key_get_public (key, 441 GNUNET_IDENTITY_key_get_public (key,
444 &pkey); 442 &pkey);
@@ -453,7 +451,7 @@ GNUNET_GNSRECORD_block_calculate_size (const struct
453 default: 451 default:
454 GNUNET_assert (0); 452 GNUNET_assert (0);
455 } 453 }
456 return -1; 454 return res;
457 455
458} 456}
459 457
@@ -593,8 +591,9 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
593 purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len); 591 purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
594 purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len); 592 purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
595 purp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); 593 purp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
596 GNUNET_memcpy (&purp[1], &block[1], payload_len); 594 GNUNET_memcpy (&purp[1],
597 595 &block[1],
596 payload_len);
598 switch (ntohl (block->type)) 597 switch (ntohl (block->type))
599 { 598 {
600 case GNUNET_GNSRECORD_TYPE_PKEY: 599 case GNUNET_GNSRECORD_TYPE_PKEY:
@@ -650,10 +649,10 @@ block_decrypt_ecdsa (const struct GNUNET_GNSRECORD_Block *block,
650 char payload[payload_len]; 649 char payload[payload_len];
651 unsigned int rd_count; 650 unsigned int rd_count;
652 651
653 GNUNET_break (payload_len == 652 GNUNET_assert (payload_len ==
654 ecdsa_symmetric_decrypt (&block[1], payload_len, 653 ecdsa_symmetric_decrypt (&block[1], payload_len,
655 key, ctr, 654 key, ctr,
656 payload)); 655 payload));
657 rd_count = GNUNET_GNSRECORD_records_deserialize_get_size (payload_len, 656 rd_count = GNUNET_GNSRECORD_records_deserialize_get_size (payload_len,
658 payload); 657 payload);
659 if (rd_count > 2048) 658 if (rd_count > 2048)
@@ -754,7 +753,6 @@ block_decrypt_eddsa (const struct GNUNET_GNSRECORD_Block *block,
754 GNUNET_GNSRECORD_RecordCallback proc, 753 GNUNET_GNSRECORD_RecordCallback proc,
755 void *proc_cls) 754 void *proc_cls)
756{ 755{
757 const struct GNUNET_GNSRECORD_EddsaBlock *edblock = &block->eddsa_block;
758 size_t payload_len = ntohl (block->size) - sizeof (struct 756 size_t payload_len = ntohl (block->size) - sizeof (struct
759 GNUNET_GNSRECORD_Block); 757 GNUNET_GNSRECORD_Block);
760 unsigned char nonce[crypto_secretbox_NONCEBYTES]; 758 unsigned char nonce[crypto_secretbox_NONCEBYTES];
@@ -776,10 +774,10 @@ block_decrypt_eddsa (const struct GNUNET_GNSRECORD_Block *block,
776 char payload[payload_len]; 774 char payload[payload_len];
777 unsigned int rd_count; 775 unsigned int rd_count;
778 776
779 GNUNET_break (GNUNET_OK == 777 GNUNET_assert (GNUNET_OK ==
780 eddsa_symmetric_decrypt (&block[1], payload_len, 778 eddsa_symmetric_decrypt (&block[1], payload_len,
781 key, nonce, 779 key, nonce,
782 payload)); 780 payload));
783 payload_len -= crypto_secretbox_MACBYTES; 781 payload_len -= crypto_secretbox_MACBYTES;
784 rd_count = GNUNET_GNSRECORD_records_deserialize_get_size (payload_len, 782 rd_count = GNUNET_GNSRECORD_records_deserialize_get_size (payload_len,
785 payload); 783 payload);
@@ -909,7 +907,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
909 proc_cls); 907 proc_cls);
910 break; 908 break;
911 default: 909 default:
912 return GNUNET_SYSERR; 910 res = GNUNET_SYSERR;
913 } 911 }
914 GNUNET_free (norm_label); 912 GNUNET_free (norm_label);
915 return res; 913 return res;
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 61604c730..54d8fb860 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -38,23 +38,26 @@
38#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
39 39
40char * 40char *
41GNUNET_GNSRECORD_string_to_lowercase (const char *src) 41GNUNET_GNSRECORD_string_normalize (const char *src)
42{ 42{
43 char *res; 43 /*FIXME: We may want to follow RFC5890/RFC5891 */
44 44 return GNUNET_STRINGS_utf8_normalize (src);
45 res = GNUNET_strdup (src);
46 GNUNET_STRINGS_utf8_tolower (src, res);
47 return res;
48} 45}
49 46
50char * 47enum GNUNET_GenericReturnValue
51GNUNET_GNSRECORD_string_normalize (const char *src) 48GNUNET_GNSRECORD_label_check (const char*label, char **emsg)
52{ 49{
53 char *res; 50 if (NULL == label)
54 res = GNUNET_strdup (src); 51 {
55 GNUNET_STRINGS_utf8_tolower (src, res); 52 *emsg = GNUNET_strdup (_ ("Label is NULL which is not allowed\n"));
56 GNUNET_STRINGS_utf8_normalize (src, res); 53 return GNUNET_NO;
57 return res; 54 }
55 if (0 != strchr (label, '.'))
56 {
57 *emsg = GNUNET_strdup (_ ("Label contains `.' which is not allowed\n"));
58 return GNUNET_NO;
59 }
60 return GNUNET_OK;
58} 61}
59 62
60/** 63/**
@@ -144,19 +147,11 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
144} 147}
145 148
146 149
147/**
148 * Returns the expiration time of the given block of records. The block
149 * expiration time is the expiration time of the record with smallest
150 * expiration time.
151 *
152 * @param rd_count number of records given in @a rd
153 * @param rd array of records
154 * @return absolute expiration time
155 */
156struct GNUNET_TIME_Absolute 150struct GNUNET_TIME_Absolute
157GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, 151GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
158 const struct 152 const struct
159 GNUNET_GNSRECORD_Data *rd) 153 GNUNET_GNSRECORD_Data *rd,
154 struct GNUNET_TIME_Absolute min)
160{ 155{
161 struct GNUNET_TIME_Absolute expire; 156 struct GNUNET_TIME_Absolute expire;
162 struct GNUNET_TIME_Absolute at; 157 struct GNUNET_TIME_Absolute at;
@@ -164,8 +159,8 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
164 struct GNUNET_TIME_Absolute at_shadow; 159 struct GNUNET_TIME_Absolute at_shadow;
165 struct GNUNET_TIME_Relative rt_shadow; 160 struct GNUNET_TIME_Relative rt_shadow;
166 161
167 if (NULL == rd) 162 if (0 == rd_count)
168 return GNUNET_TIME_UNIT_ZERO_ABS; 163 return GNUNET_TIME_absolute_max (GNUNET_TIME_UNIT_ZERO_ABS, min);
169 expire = GNUNET_TIME_UNIT_FOREVER_ABS; 164 expire = GNUNET_TIME_UNIT_FOREVER_ABS;
170 for (unsigned int c = 0; c < rd_count; c++) 165 for (unsigned int c = 0; c < rd_count; c++)
171 { 166 {
@@ -202,6 +197,7 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
202 expire = GNUNET_TIME_absolute_min (at, 197 expire = GNUNET_TIME_absolute_min (at,
203 expire); 198 expire);
204 } 199 }
200 expire = GNUNET_TIME_absolute_max (expire, min);
205 LOG (GNUNET_ERROR_TYPE_DEBUG, 201 LOG (GNUNET_ERROR_TYPE_DEBUG,
206 "Determined expiration time for block with %u records to be %s\n", 202 "Determined expiration time for block with %u records to be %s\n",
207 rd_count, 203 rd_count,
@@ -284,12 +280,24 @@ GNUNET_GNSRECORD_identity_from_data (const char *data,
284{ 280{
285 if (GNUNET_NO == GNUNET_GNSRECORD_is_zonekey_type (type)) 281 if (GNUNET_NO == GNUNET_GNSRECORD_is_zonekey_type (type))
286 return GNUNET_SYSERR; 282 return GNUNET_SYSERR;
287 if (data_size > sizeof (struct GNUNET_IDENTITY_PublicKey)) 283 switch (type)
288 return GNUNET_SYSERR; 284 {
289 return (GNUNET_IDENTITY_read_key_from_buffer (key, data, data_size) == 285 case GNUNET_GNSRECORD_TYPE_PKEY:
290 data_size? 286 if (data_size > sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
291 GNUNET_OK : 287 return GNUNET_SYSERR;
292 GNUNET_SYSERR); 288 memcpy (&key->ecdsa_key, data, data_size);
289 break;
290 case GNUNET_GNSRECORD_TYPE_EDKEY:
291 if (data_size > sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
292 return GNUNET_SYSERR;
293 memcpy (&key->eddsa_key, data, data_size);
294 break;
295 default:
296 return GNUNET_NO;
297 }
298 key->type = htonl (type);
299
300 return GNUNET_YES;
293} 301}
294 302
295 303
@@ -302,16 +310,11 @@ GNUNET_GNSRECORD_data_from_identity (const struct
302{ 310{
303 char *tmp; 311 char *tmp;
304 *type = ntohl (key->type); 312 *type = ntohl (key->type);
305 *data_size = GNUNET_IDENTITY_key_get_length (key); 313 *data_size = GNUNET_IDENTITY_key_get_length (key) - sizeof (key->type);
306 if (0 == *data_size) 314 if (0 == *data_size)
307 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
308 tmp = GNUNET_malloc (*data_size); 316 tmp = GNUNET_malloc (*data_size);
309 if (GNUNET_IDENTITY_write_key_to_buffer (key, tmp, *data_size) 317 memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
310 != *data_size) {
311 GNUNET_free (tmp);
312 *data_size = 0;
313 return GNUNET_SYSERR;
314 }
315 *data = tmp; 318 *data = tmp;
316 return GNUNET_OK; 319 return GNUNET_OK;
317} 320}
@@ -406,5 +409,176 @@ GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd,
406 409
407} 410}
408 411
412enum GNUNET_GenericReturnValue
413GNUNET_GNSRECORD_normalize_record_set (const char *label,
414 const struct
415 GNUNET_GNSRECORD_Data *rd,
416 unsigned int rd_count,
417 struct GNUNET_GNSRECORD_Data *
418 rd_public,
419 unsigned int *rd_count_public,
420 struct GNUNET_TIME_Absolute *expiry,
421 int include_private,
422 char **emsg)
423{
424 struct GNUNET_TIME_Absolute now;
425 struct GNUNET_TIME_Absolute minimum_expiration;
426 int have_zone_delegation = GNUNET_NO;
427 int have_gns2dns = GNUNET_NO;
428 int have_other = GNUNET_NO;
429 int have_redirect = GNUNET_NO;
430 int have_empty_label = (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, label));
431 unsigned int rd_count_tmp;
432
433 minimum_expiration = GNUNET_TIME_UNIT_ZERO_ABS;
434 now = GNUNET_TIME_absolute_get ();
435 rd_count_tmp = 0;
436 for (unsigned int i = 0; i < rd_count; i++)
437 {
438 /* Ignore the tombstone. For maintenance only. Remember expiration time. */
439 if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
440 {
441 minimum_expiration.abs_value_us = rd[i].expiration_time;
442 continue;
443 }
444 /* No NICK records unless empty label */
445 if (have_empty_label &&
446 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
447 continue;
448
449 /**
450 * Check for delegation and redirect consistency.
451 * Note that we check for consistency BEFORE we filter for
452 * private records ON PURPOSE.
453 * We also want consistent record sets in our local zone(s).
454 * The only exception is the tombstone (above) which we ignore
455 * for the consistency check(s).
456 * FIXME: What about shadow records? Should we ignore them?
457 */
458 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
459 {
460 /* No delegation records under empty label*/
461 if (have_empty_label)
462 {
463 *emsg = GNUNET_strdup (_ (
464 "Zone delegation record not allowed in apex."));
465 return GNUNET_SYSERR;
466 }
467 if ((GNUNET_YES == have_other) ||
468 (GNUNET_YES == have_redirect) ||
469 (GNUNET_YES == have_gns2dns))
470 {
471 *emsg = GNUNET_strdup (_ (
472 "Zone delegation record set contains mutually exclusive records."));
473 return GNUNET_SYSERR;
474 }
475 have_zone_delegation = GNUNET_YES;
476 }
477 else if (GNUNET_GNSRECORD_TYPE_REDIRECT == rd[i].record_type)
478 {
479 if (GNUNET_YES == have_redirect)
480 {
481 *emsg = GNUNET_strdup (_ (
482 "Multiple REDIRECT records."));
483 return GNUNET_SYSERR;
484
485 }
486 if ((GNUNET_YES == have_other) ||
487 (GNUNET_YES == have_zone_delegation) ||
488 (GNUNET_YES == have_gns2dns))
489 {
490 *emsg = GNUNET_strdup (_ (
491 "Redirection record set conains mutually exclusive records."));
492 return GNUNET_SYSERR;
493 }
494 /* No redirection records under empty label*/
495 if (have_empty_label)
496 {
497 *emsg = GNUNET_strdup (_ (
498 "Redirection records not allowed in apex."));
499 return GNUNET_SYSERR;
500 }
501 have_redirect = GNUNET_YES;
502 }
503 else if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rd[i].record_type)
504 {
505 /* No gns2dns records under empty label*/
506 if (have_empty_label)
507 {
508 *emsg = GNUNET_strdup (_ (
509 "Redirection records not allowed in apex.."));
510 return GNUNET_SYSERR;
511 }
512 if ((GNUNET_YES == have_other) ||
513 (GNUNET_YES == have_redirect) ||
514 (GNUNET_YES == have_zone_delegation))
515 {
516 *emsg = GNUNET_strdup (_ (
517 "Redirection record set conains mutually exclusive records."));
518 return GNUNET_SYSERR;
519 }
520 have_gns2dns = GNUNET_YES;
521 }
522 else
523 {
524 /* Some other record.
525 * Not allowed for zone delegations or redirections */
526 if ((GNUNET_YES == have_zone_delegation) ||
527 (GNUNET_YES == have_redirect) ||
528 (GNUNET_YES == have_gns2dns))
529 {
530 *emsg = GNUNET_strdup (_ (
531 "Mutually exclusive records."));
532 return GNUNET_SYSERR;
533 }
534 have_other = GNUNET_YES;
535 }
536
537 /* Ignore private records for public record set */
538
539 if ((GNUNET_NO == include_private) &&
540 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
541 continue;
542 /* Skip expired records */
543 if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
544 (rd[i].expiration_time < now.abs_value_us))
545 continue; /* record already expired, skip it */
546 rd_public[rd_count_tmp] = rd[i];
547 /* Make sure critical record types are marked as such */
548 if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
549 rd_public[rd_count_tmp].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
550 rd_count_tmp++;
551 }
552
553 *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_count_tmp,
554 rd_public,
555 minimum_expiration);
556 *rd_count_public = rd_count_tmp;
557 return GNUNET_OK;
558}
559
560enum GNUNET_GenericReturnValue
561GNUNET_GNSRECORD_convert_records_for_export (const char *label,
562 const struct
563 GNUNET_GNSRECORD_Data *rd,
564 unsigned int rd_count,
565 struct GNUNET_GNSRECORD_Data *
566 rd_public,
567 unsigned int *rd_count_public,
568 struct GNUNET_TIME_Absolute *expiry,
569 char **emsg)
570{
571 return GNUNET_GNSRECORD_normalize_record_set (label,
572 rd,
573 rd_count,
574 rd_public,
575 rd_count_public,
576 expiry,
577 GNUNET_NO,
578 emsg);
579
580}
581
582
409 583
410/* end of gnsrecord_misc.c */ 584/* end of gnsrecord_misc.c */
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index f9b83e48b..87de32066 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -33,9 +33,6 @@
33#include <inttypes.h> 33#include <inttypes.h>
34#include "gnsrecord_crypto.h" 34#include "gnsrecord_crypto.h"
35 35
36#define TEST_RECORD_LABEL "test"
37#define TEST_RECORD_A "1.2.3.4"
38#define TEST_RRCOUNT 2
39 36
40static char *d_pkey = 37static char *d_pkey =
41 "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; 38 "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98";
@@ -43,7 +40,9 @@ static char *d_pkey =
43static char *d_edkey = 40static char *d_edkey =
44 "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65"; 41 "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65";
45 42
46int parsehex (char *src, char *dst, size_t dstlen, int invert) 43
44static int
45parsehex (char *src, char *dst, size_t dstlen, int invert)
47{ 46{
48 char *line = src; 47 char *line = src;
49 char *data = line; 48 char *data = line;
@@ -83,6 +82,7 @@ print_bytes_ (void *buf,
83 printf ("\n"); 82 printf ("\n");
84} 83}
85 84
85
86static void 86static void
87print_bytes (void *buf, 87print_bytes (void *buf,
88 size_t buf_len, 88 size_t buf_len,
@@ -95,7 +95,7 @@ print_bytes (void *buf,
95static void 95static void
96print_record (const struct GNUNET_GNSRECORD_Data *rd) 96print_record (const struct GNUNET_GNSRECORD_Data *rd)
97{ 97{
98 98 uint16_t flags = htons (rd->flags);
99 fprintf (stdout, 99 fprintf (stdout,
100 "EXPIRATION: %" PRIu64 "\n", rd->expiration_time); 100 "EXPIRATION: %" PRIu64 "\n", rd->expiration_time);
101 fprintf (stdout, 101 fprintf (stdout,
@@ -103,7 +103,9 @@ print_record (const struct GNUNET_GNSRECORD_Data *rd)
103 fprintf (stdout, 103 fprintf (stdout,
104 "TYPE: %d\n", rd->record_type); 104 "TYPE: %d\n", rd->record_type);
105 fprintf (stdout, 105 fprintf (stdout,
106 "FLAGS: %d\n", rd->flags); 106 "FLAGS: ");
107 print_bytes ((void*) &flags, sizeof (flags), 8);
108 printf ("\n");
107 fprintf (stdout, 109 fprintf (stdout,
108 "DATA:\n"); 110 "DATA:\n");
109 print_bytes ((char*) rd->data, rd->data_size, 8); 111 print_bytes ((char*) rd->data, rd->data_size, 8);
@@ -120,15 +122,9 @@ print_record (const struct GNUNET_GNSRECORD_Data *rd)
120 * @param cfg configuration 122 * @param cfg configuration
121 */ 123 */
122static void 124static void
123run_pkey (void) 125run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
124{ 126{
125 struct GNUNET_GNSRECORD_Data rd[2];
126 struct GNUNET_TIME_Absolute expire; 127 struct GNUNET_TIME_Absolute expire;
127 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
128 struct GNUNET_TIME_Absolute exp1;
129 struct GNUNET_TIME_Absolute exp2;
130 struct GNUNET_TIME_Relative delta1;
131 struct GNUNET_TIME_Relative delta2;
132 struct GNUNET_GNSRECORD_Block *rrblock; 128 struct GNUNET_GNSRECORD_Block *rrblock;
133 char *bdata; 129 char *bdata;
134 struct GNUNET_IDENTITY_PrivateKey id_priv; 130 struct GNUNET_IDENTITY_PrivateKey id_priv;
@@ -136,24 +132,12 @@ run_pkey (void)
136 struct GNUNET_IDENTITY_PrivateKey pkey_data_p; 132 struct GNUNET_IDENTITY_PrivateKey pkey_data_p;
137 struct GNUNET_IDENTITY_PublicKey pkey_data; 133 struct GNUNET_IDENTITY_PublicKey pkey_data;
138 struct GNUNET_HashCode query; 134 struct GNUNET_HashCode query;
139 void *data;
140 size_t data_size;
141 char *rdata; 135 char *rdata;
142 size_t rdata_size; 136 size_t rdata_size;
143 uint32_t rd_count_nbo;
144 char ztld[128]; 137 char ztld[128];
145 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; 138 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
146 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH]; 139 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
147 140
148 /*
149 * Make two different expiration times
150 */
151 GNUNET_STRINGS_fancy_time_to_absolute ("2048-01-23 10:51:34",
152 &exp1);
153 GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01",
154 &exp2);
155
156
157 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 141 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
158 GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); 142 GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key);
159 parsehex (d_pkey, 143 parsehex (d_pkey,
@@ -168,13 +152,14 @@ run_pkey (void)
168 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1); 152 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1);
169 fprintf (stdout, "\n"); 153 fprintf (stdout, "\n");
170 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 154 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
155 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub));
171 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 156 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
172 GNUNET_STRINGS_data_to_string (&id_pub, 157 GNUNET_STRINGS_data_to_string (&id_pub,
173 GNUNET_IDENTITY_key_get_length (&id_pub), 158 GNUNET_IDENTITY_key_get_length (&id_pub),
174 ztld, 159 ztld,
175 sizeof (ztld)); 160 sizeof (ztld));
176 fprintf (stdout, "\n"); 161 fprintf (stdout, "\n");
177 fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); 162 fprintf (stdout, "zTLD:\n");
178 fprintf (stdout, "%s\n", ztld); 163 fprintf (stdout, "%s\n", ztld);
179 fprintf (stdout, "\n"); 164 fprintf (stdout, "\n");
180 165
@@ -183,39 +168,31 @@ run_pkey (void)
183 GNUNET_IDENTITY_key_get_public (&pkey_data_p, 168 GNUNET_IDENTITY_key_get_public (&pkey_data_p,
184 &pkey_data); 169 &pkey_data);
185 fprintf (stdout, 170 fprintf (stdout,
186 "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); 171 "Label: %s\nRRCOUNT: %d\n\n", label, rd_count);
187 memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2);
188 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (
189 GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
190 rd[0].data = data;
191 rd[0].data_size = data_size;
192 rd[0].expiration_time = exp1.abs_value_us;
193 rd[0].record_type = GNUNET_DNSPARSER_TYPE_A;
194 fprintf (stdout, "Record #0\n");
195 print_record (&rd[0]);
196 172
197 rd[1].data = "Some nick"; 173 for (int i = 0; i < rd_count; i++)
198 rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); 174 {
199 rd[1].expiration_time = exp2.abs_value_us; 175 fprintf (stdout, "Record #%d\n", i);
200 rd[1].record_type = GNUNET_GNSRECORD_TYPE_NICK; 176 print_record (&rd[i]);
201 rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; 177 }
202 fprintf (stdout, "Record #1\n");
203 print_record (&rd[1]);
204 178
205 rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, 179 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count,
206 rd); 180 rd);
207 rdata = GNUNET_malloc (rdata_size); 181 rdata = GNUNET_malloc (rdata_size);
208 GNUNET_GNSRECORD_records_serialize (2, 182 GNUNET_GNSRECORD_records_serialize (rd_count,
209 rd, 183 rd,
210 rdata_size, 184 (size_t) rdata_size,
211 rdata); 185 rdata);
212 fprintf (stdout, "RDATA:\n"); 186 fprintf (stdout, "RDATA:\n");
213 print_bytes (rdata, rdata_size, 8); 187 print_bytes (rdata,
188 (size_t) rdata_size,
189 8);
214 fprintf (stdout, "\n"); 190 fprintf (stdout, "\n");
215 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd); 191 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_count, rd,
192 GNUNET_TIME_UNIT_ZERO_ABS);
216 GNR_derive_block_aes_key (ctr, 193 GNR_derive_block_aes_key (ctr,
217 skey, 194 skey,
218 TEST_RECORD_LABEL, 195 label,
219 GNUNET_TIME_absolute_hton ( 196 GNUNET_TIME_absolute_hton (
220 expire).abs_value_us__, 197 expire).abs_value_us__,
221 &id_pub.ecdsa_key); 198 &id_pub.ecdsa_key);
@@ -227,25 +204,26 @@ run_pkey (void)
227 print_bytes (skey, sizeof (skey), 8); 204 print_bytes (skey, sizeof (skey), 8);
228 fprintf (stdout, "\n"); 205 fprintf (stdout, "\n");
229 GNUNET_GNSRECORD_query_from_public_key (&id_pub, 206 GNUNET_GNSRECORD_query_from_public_key (&id_pub,
230 TEST_RECORD_LABEL, 207 label,
231 &query); 208 &query);
232 fprintf (stdout, "Storage key (q):\n"); 209 fprintf (stdout, "Storage key (q):\n");
233 print_bytes (&query, sizeof (query), 8); 210 print_bytes (&query, sizeof (query), 8);
234 fprintf (stdout, "\n"); 211 fprintf (stdout, "\n");
235 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv, 212 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv,
236 expire, 213 expire,
237 TEST_RECORD_LABEL, 214 label,
238 rd, 215 rd,
239 TEST_RRCOUNT, 216 rd_count,
240 &rrblock)); 217 &rrblock));
241 size_t bdata_size = ntohl(rrblock->size) - sizeof (struct GNUNET_GNSRECORD_Block); 218 size_t bdata_size = ntohl (rrblock->size) - sizeof (struct
219 GNUNET_GNSRECORD_Block);
242 220
243 bdata = (char*) &(&rrblock->ecdsa_block)[1]; 221 bdata = (char*) &(&rrblock->ecdsa_block)[1];
244 fprintf (stdout, "BDATA:\n"); 222 fprintf (stdout, "BDATA:\n");
245 print_bytes (bdata, bdata_size, 8); 223 print_bytes (bdata, bdata_size, 8);
246 fprintf (stdout, "\n"); 224 fprintf (stdout, "\n");
247 fprintf (stdout, "RRBLOCK:\n"); 225 fprintf (stdout, "RRBLOCK:\n");
248 print_bytes (rrblock, ntohl(rrblock->size), 8); 226 print_bytes (rrblock, ntohl (rrblock->size), 8);
249 fprintf (stdout, "\n"); 227 fprintf (stdout, "\n");
250 GNUNET_free (rdata); 228 GNUNET_free (rdata);
251} 229}
@@ -260,15 +238,9 @@ run_pkey (void)
260 * @param cfg configuration 238 * @param cfg configuration
261 */ 239 */
262static void 240static void
263run_edkey (void) 241run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
264{ 242{
265 struct GNUNET_GNSRECORD_Data rd[2];
266 struct GNUNET_TIME_Absolute expire; 243 struct GNUNET_TIME_Absolute expire;
267 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
268 struct GNUNET_TIME_Absolute exp1;
269 struct GNUNET_TIME_Absolute exp2;
270 struct GNUNET_TIME_Relative delta1;
271 struct GNUNET_TIME_Relative delta2;
272 struct GNUNET_GNSRECORD_Block *rrblock; 244 struct GNUNET_GNSRECORD_Block *rrblock;
273 char *bdata; 245 char *bdata;
274 struct GNUNET_IDENTITY_PrivateKey id_priv; 246 struct GNUNET_IDENTITY_PrivateKey id_priv;
@@ -276,23 +248,13 @@ run_edkey (void)
276 struct GNUNET_IDENTITY_PrivateKey pkey_data_p; 248 struct GNUNET_IDENTITY_PrivateKey pkey_data_p;
277 struct GNUNET_IDENTITY_PublicKey pkey_data; 249 struct GNUNET_IDENTITY_PublicKey pkey_data;
278 struct GNUNET_HashCode query; 250 struct GNUNET_HashCode query;
279 void *data;
280 size_t data_size;
281 char *rdata; 251 char *rdata;
282 size_t rdata_size; 252 size_t rdata_size;
283 uint32_t rd_count_nbo; 253
284 char ztld[128]; 254 char ztld[128];
285 unsigned char nonce[crypto_secretbox_NONCEBYTES]; 255 unsigned char nonce[crypto_secretbox_NONCEBYTES];
286 unsigned char skey[crypto_secretbox_KEYBYTES]; 256 unsigned char skey[crypto_secretbox_KEYBYTES];
287 257
288 /*
289 * Make two different expiration times
290 */
291 GNUNET_STRINGS_fancy_time_to_absolute ("%2048-01-23 10:51:34",
292 &exp1);
293 GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01",
294 &exp2);
295
296 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 258 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
297 GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); 259 GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key);
298 GNUNET_IDENTITY_key_get_public (&id_priv, 260 GNUNET_IDENTITY_key_get_public (&id_priv,
@@ -311,13 +273,14 @@ run_edkey (void)
311 GNUNET_CRYPTO_EddsaPrivateKey), 8); 273 GNUNET_CRYPTO_EddsaPrivateKey), 8);
312 fprintf (stdout, "\n"); 274 fprintf (stdout, "\n");
313 fprintf (stdout, "Zone identifier (ztype|zkey):\n"); 275 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
276 GNUNET_assert (0 < GNUNET_IDENTITY_key_get_length (&id_pub));
314 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 277 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
315 GNUNET_STRINGS_data_to_string (&id_pub, 278 GNUNET_STRINGS_data_to_string (&id_pub,
316 GNUNET_IDENTITY_key_get_length (&id_pub), 279 GNUNET_IDENTITY_key_get_length (&id_pub),
317 ztld, 280 ztld,
318 sizeof (ztld)); 281 sizeof (ztld));
319 fprintf (stdout, "\n"); 282 fprintf (stdout, "\n");
320 fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); 283 fprintf (stdout, "zTLD:\n");
321 fprintf (stdout, "%s\n", ztld); 284 fprintf (stdout, "%s\n", ztld);
322 fprintf (stdout, "\n"); 285 fprintf (stdout, "\n");
323 286
@@ -326,40 +289,33 @@ run_edkey (void)
326 GNUNET_IDENTITY_key_get_public (&pkey_data_p, 289 GNUNET_IDENTITY_key_get_public (&pkey_data_p,
327 &pkey_data); 290 &pkey_data);
328 fprintf (stdout, 291 fprintf (stdout,
329 "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); 292 "Label: %s\nRRCOUNT: %d\n\n", label, rd_count);
330 memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2);
331 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (
332 GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
333 rd[0].data = data;
334 rd[0].data_size = data_size;
335 rd[0].expiration_time = exp1.abs_value_us;
336 rd[0].record_type = GNUNET_DNSPARSER_TYPE_A;
337 fprintf (stdout, "Record #0\n");
338 print_record (&rd[0]);
339 293
340 rd[1].data = "My Nick"; 294 for (int i = 0; i < rd_count; i++)
341 rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); 295 {
342 rd[1].expiration_time = exp2.abs_value_us; 296 fprintf (stdout, "Record #%d\n", i);
343 rd[1].record_type = GNUNET_GNSRECORD_TYPE_NICK; 297 print_record (&rd[i]);
344 rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; 298 }
345 fprintf (stdout, "Record #1\n");
346 print_record (&rd[1]);
347 299
348 rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, 300 rdata_size = GNUNET_GNSRECORD_records_get_size (rd_count,
349 rd); 301 rd);
350 expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, 302 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_count,
351 rd); 303 rd,
352 rdata = GNUNET_malloc (rdata_size); 304 GNUNET_TIME_UNIT_ZERO_ABS);
353 GNUNET_GNSRECORD_records_serialize (2, 305 GNUNET_assert (0 < rdata_size);
306 rdata = GNUNET_malloc ((size_t) rdata_size);
307 GNUNET_GNSRECORD_records_serialize (rd_count,
354 rd, 308 rd,
355 rdata_size, 309 (size_t) rdata_size,
356 rdata); 310 rdata);
357 fprintf (stdout, "RDATA:\n"); 311 fprintf (stdout, "RDATA:\n");
358 print_bytes (rdata, rdata_size, 8); 312 print_bytes (rdata,
313 (size_t) rdata_size,
314 8);
359 fprintf (stdout, "\n"); 315 fprintf (stdout, "\n");
360 GNR_derive_block_xsalsa_key (nonce, 316 GNR_derive_block_xsalsa_key (nonce,
361 skey, 317 skey,
362 TEST_RECORD_LABEL, 318 label,
363 GNUNET_TIME_absolute_hton ( 319 GNUNET_TIME_absolute_hton (
364 expire).abs_value_us__, 320 expire).abs_value_us__,
365 &id_pub.eddsa_key); 321 &id_pub.eddsa_key);
@@ -370,7 +326,7 @@ run_edkey (void)
370 print_bytes (skey, sizeof (skey), 8); 326 print_bytes (skey, sizeof (skey), 8);
371 fprintf (stdout, "\n"); 327 fprintf (stdout, "\n");
372 GNUNET_GNSRECORD_query_from_public_key (&id_pub, 328 GNUNET_GNSRECORD_query_from_public_key (&id_pub,
373 TEST_RECORD_LABEL, 329 label,
374 &query); 330 &query);
375 fprintf (stdout, "Storage key (q):\n"); 331 fprintf (stdout, "Storage key (q):\n");
376 print_bytes (&query, sizeof (query), 8); 332 print_bytes (&query, sizeof (query), 8);
@@ -378,18 +334,19 @@ run_edkey (void)
378 334
379 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv, 335 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (&id_priv,
380 expire, 336 expire,
381 TEST_RECORD_LABEL, 337 label,
382 rd, 338 rd,
383 TEST_RRCOUNT, 339 rd_count,
384 &rrblock)); 340 &rrblock));
385 size_t bdata_size = ntohl(rrblock->size) - sizeof (struct GNUNET_GNSRECORD_Block); 341 size_t bdata_size = ntohl (rrblock->size) - sizeof (struct
342 GNUNET_GNSRECORD_Block);
386 343
387 bdata = (char*) &(&rrblock->eddsa_block)[1]; 344 bdata = (char*) &(&rrblock->eddsa_block)[1];
388 fprintf (stdout, "BDATA:\n"); 345 fprintf (stdout, "BDATA:\n");
389 print_bytes (bdata, bdata_size, 8); 346 print_bytes (bdata, bdata_size, 8);
390 fprintf (stdout, "\n"); 347 fprintf (stdout, "\n");
391 fprintf (stdout, "RRBLOCK:\n"); 348 fprintf (stdout, "RRBLOCK:\n");
392 print_bytes (rrblock, ntohl(rrblock->size), 8); 349 print_bytes (rrblock, ntohl (rrblock->size), 8);
393 fprintf (stdout, "\n"); 350 fprintf (stdout, "\n");
394 GNUNET_free (rdata); 351 GNUNET_free (rdata);
395} 352}
@@ -409,8 +366,67 @@ run (void *cls,
409 const char *cfgfile, 366 const char *cfgfile,
410 const struct GNUNET_CONFIGURATION_Handle *cfg) 367 const struct GNUNET_CONFIGURATION_Handle *cfg)
411{ 368{
412 run_pkey (); 369 struct GNUNET_GNSRECORD_Data rd_pkey;
413 run_edkey (); 370 struct GNUNET_GNSRECORD_Data rd[3];
371 struct GNUNET_TIME_Absolute exp1;
372 struct GNUNET_TIME_Absolute exp2;
373 struct GNUNET_TIME_Relative exp3;
374 size_t pkey_data_size;
375 size_t ip_data_size;
376 char *pkey_data;
377 char *ip_data;
378
379 /*
380 * Make different expiration times
381 */
382 GNUNET_STRINGS_fancy_time_to_absolute ("2048-01-23 10:51:34",
383 &exp1);
384 GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01",
385 &exp2);
386 GNUNET_STRINGS_fancy_time_to_relative ("100y",
387 &exp3);
388
389
390 memset (&rd_pkey, 0, sizeof (struct GNUNET_GNSRECORD_Data));
391 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (
392 GNUNET_GNSRECORD_TYPE_PKEY,
393 "000G0011WESGZY9VRV9NNJ66W3GKNZFZF56BFD2BQF3MHMJST2G2GKDYGG",
394 (void**) &pkey_data,
395 &pkey_data_size));
396 rd_pkey.data = pkey_data;
397 rd_pkey.data_size = pkey_data_size;
398 rd_pkey.expiration_time = exp1.abs_value_us;
399 rd_pkey.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
400 rd_pkey.flags = GNUNET_GNSRECORD_RF_CRITICAL;
401 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (
402 GNUNET_DNSPARSER_TYPE_AAAA,
403 "::dead:beef",
404 (void**) &ip_data,
405 &ip_data_size));
406
407 rd[0].data = ip_data;
408 rd[0].data_size = ip_data_size;
409 rd[0].expiration_time = exp1.abs_value_us;
410 rd[0].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
411 rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
412
413 rd[1].data = "\u611b\u79f0";
414 rd[1].data_size = strlen (rd[1].data);
415 rd[1].expiration_time = exp2.abs_value_us;
416 rd[1].record_type = GNUNET_GNSRECORD_TYPE_NICK;
417 rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE;
418
419 rd[2].data = "Hello World";
420 rd[2].data_size = strlen (rd[2].data);
421 rd[2].expiration_time = exp3.rel_value_us;
422 rd[2].record_type = GNUNET_DNSPARSER_TYPE_TXT;
423 rd[2].flags = GNUNET_GNSRECORD_RF_SUPPLEMENTAL
424 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
425
426 run_pkey (&rd_pkey, 1, "testdelegation");
427 run_pkey (rd, 3, "namesystem");
428 run_edkey (&rd_pkey, 1, "testdelegation");
429 run_edkey (rd, 3, "namesystem");
414} 430}
415 431
416 432
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c
index d9a3c20cf..6b5f84235 100644
--- a/src/gnsrecord/perf_gnsrecord_crypto.c
+++ b/src/gnsrecord/perf_gnsrecord_crypto.c
@@ -90,12 +90,12 @@ run (void *cls,
90 start_time = GNUNET_TIME_absolute_get (); 90 start_time = GNUNET_TIME_absolute_get ();
91 for (unsigned int i = 0; i < ROUNDS; i++) 91 for (unsigned int i = 0; i < ROUNDS; i++)
92 { 92 {
93 GNUNET_assert (NULL != (block = 93 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (&privkey,
94 GNUNET_GNSRECORD_block_create2 (&privkey,
95 expire, 94 expire,
96 s_name, 95 s_name,
97 s_rd, 96 s_rd,
98 RECORDS))); 97 RECORDS,
98 &block));
99 GNUNET_GNSRECORD_query_from_private_key (&privkey, 99 GNUNET_GNSRECORD_query_from_private_key (&privkey,
100 s_name, 100 s_name,
101 &query); 101 &query);
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index 123c59905..649133cd1 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -773,6 +773,12 @@ dns_number_to_typename (void *cls, uint32_t type)
773} 773}
774 774
775 775
776static enum GNUNET_GenericReturnValue
777dns_is_critical (void *cls, uint32_t type)
778{
779 return GNUNET_NO;
780}
781
776/** 782/**
777 * Entry point for the plugin. 783 * Entry point for the plugin.
778 * 784 *
@@ -789,6 +795,7 @@ libgnunet_plugin_gnsrecord_dns_init (void *cls)
789 api->string_to_value = &dns_string_to_value; 795 api->string_to_value = &dns_string_to_value;
790 api->typename_to_number = &dns_typename_to_number; 796 api->typename_to_number = &dns_typename_to_number;
791 api->number_to_typename = &dns_number_to_typename; 797 api->number_to_typename = &dns_number_to_typename;
798 api->is_critical = &dns_is_critical;
792 return api; 799 return api;
793} 800}
794 801
diff --git a/src/gnsrecord/test_gnsrecord_block_expiration.c b/src/gnsrecord/test_gnsrecord_block_expiration.c
index b53d7d7e8..d14ce3914 100644
--- a/src/gnsrecord/test_gnsrecord_block_expiration.c
+++ b/src/gnsrecord/test_gnsrecord_block_expiration.c
@@ -72,7 +72,8 @@ run (void *cls, char *const *args, const char *cfgfile,
72 72
73 GNUNET_assert (expiration_abs.abs_value_us == 73 GNUNET_assert (expiration_abs.abs_value_us ==
74 GNUNET_GNSRECORD_record_get_expiration_time (2, 74 GNUNET_GNSRECORD_record_get_expiration_time (2,
75 rd).abs_value_us); 75 rd,
76 GNUNET_TIME_UNIT_ZERO_ABS).abs_value_us);
76 77
77 rd[1].expiration_time = expiration_abs_shadow.abs_value_us; 78 rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
78 rd[1].record_type = TEST_RECORD_TYPE; 79 rd[1].record_type = TEST_RECORD_TYPE;
@@ -83,7 +84,8 @@ run (void *cls, char *const *args, const char *cfgfile,
83 84
84 GNUNET_assert (expiration_abs_shadow.abs_value_us == 85 GNUNET_assert (expiration_abs_shadow.abs_value_us ==
85 GNUNET_GNSRECORD_record_get_expiration_time (2, 86 GNUNET_GNSRECORD_record_get_expiration_time (2,
86 rd).abs_value_us); 87 rd,
88 GNUNET_TIME_UNIT_ZERO_ABS).abs_value_us);
87 res = 0; 89 res = 0;
88} 90}
89 91
diff --git a/src/gnsrecord/test_gnsrecord_testvectors.c b/src/gnsrecord/test_gnsrecord_testvectors.c
index 153c56261..bb4922417 100644
--- a/src/gnsrecord/test_gnsrecord_testvectors.c
+++ b/src/gnsrecord/test_gnsrecord_testvectors.c
@@ -10,16 +10,16 @@
10 10
11 11
12static char *d = 12static char *d =
13"50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; 13 "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98";
14 14
15 15
16static char *zid = 16static char *zid =
17"00010000677c477d2d93097c85b195c6f96d84ff61f5982c2c4fe02d5a11fedfb0c2901f"; 17 "00010000677c477d2d93097c85b195c6f96d84ff61f5982c2c4fe02d5a11fedfb0c2901f";
18 18
19#define RRCOUNT 2 19#define RRCOUNT 2
20#define LABEL "test" 20#define LABEL "namesystem"
21 21
22#define R0_EXPIRATION 14888744139323793 22#define R0_EXPIRATION
23#define R0_DATA_SIZE 4 23#define R0_DATA_SIZE 4
24#define R0_TYPE 1 24#define R0_TYPE 1
25#define R0_FLAGS 0 25#define R0_FLAGS 0
@@ -31,12 +31,12 @@ static char *zid =
31#define R1_TYPE 65536 31#define R1_TYPE 65536
32#define R1_FLAGS 2 32#define R1_FLAGS 2
33#define R1_DATA \ 33#define R1_DATA \
34"000100000e601be42eb57fb4697610cf3a3b18347b65a33f025b5b174abefb30807bfecf" 34 "000100000e601be42eb57fb4697610cf3a3b18347b65a33f025b5b174abefb30807bfecf"
35 35
36#define R1_RRBLOCK \ 36#define R1_RRBLOCK \
37"000100008e16da87203b5159c5538e9b765742e968c54af9afbc0890dc80205ad14c84e107b0c115fc0089aa38b9c7ab9cbe1d77040d282a51a2ad493f61f3495f02d8170fe473a55ec6bdf9a509ab1701ffc37ea3bb4cac4a672520986df96e67cc1a73000000940000000f0034e53be193799100e4837eb5d04f92903de4b5234e8ccac5736c9793379a59c33375fc8951aca2eb7aad067bf9af60bf26758646a17f5e5c3b6215f94079545b1c4d4f1b2ebb22c2b4dad44126817b6f001530d476401dd67ac0148554e806353da9e4298079f3e1b16942c48d90c4360c61238c40d9d52911aea52cc0037ac7160bb3cf5b2f4a722fd96b" 37 "000100008e16da87203b5159c5538e9b765742e968c54af9afbc0890dc80205ad14c84e107b0c115fc0089aa38b9c7ab9cbe1d77040d282a51a2ad493f61f3495f02d8170fe473a55ec6bdf9a509ab1701ffc37ea3bb4cac4a672520986df96e67cc1a73000000940000000f0034e53be193799100e4837eb5d04f92903de4b5234e8ccac5736c9793379a59c33375fc8951aca2eb7aad067bf9af60bf26758646a17f5e5c3b6215f94079545b1c4d4f1b2ebb22c2b4dad44126817b6f001530d476401dd67ac0148554e806353da9e4298079f3e1b16942c48d90c4360c61238c40d9d52911aea52cc0037ac7160bb3cf5b2f4a722fd96b"
38 38
39int parsehex(char *src, char *dst, size_t dstlen, int invert) 39int parsehex (char *src, char *dst, size_t dstlen, int invert)
40{ 40{
41 char *line = src; 41 char *line = src;
42 char *data = line; 42 char *data = line;
@@ -44,7 +44,8 @@ int parsehex(char *src, char *dst, size_t dstlen, int invert)
44 int read_byte; 44 int read_byte;
45 int data_len = 0; 45 int data_len = 0;
46 46
47 while (sscanf(data, " %02x%n", &read_byte, &off) == 1) { 47 while (sscanf (data, " %02x%n", &read_byte, &off) == 1)
48 {
48 if (invert) 49 if (invert)
49 dst[dstlen - 1 - data_len++] = read_byte; 50 dst[dstlen - 1 - data_len++] = read_byte;
50 else 51 else
@@ -62,8 +63,8 @@ res_checker (void *cls,
62 int r1_found = 0; 63 int r1_found = 0;
63 char r0_data[R0_DATA_SIZE]; 64 char r0_data[R0_DATA_SIZE];
64 char r1_data[R1_DATA_SIZE]; 65 char r1_data[R1_DATA_SIZE];
65 parsehex(R0_DATA, (char*)r0_data, 0, 0); 66 parsehex (R0_DATA, (char*) r0_data, 0, 0);
66 parsehex(R1_DATA, (char*)r1_data, 0, 0); 67 parsehex (R1_DATA, (char*) r1_data, 0, 0);
67 GNUNET_assert (rd_count == RRCOUNT); 68 GNUNET_assert (rd_count == RRCOUNT);
68 for (int i = 0; i < RRCOUNT; i++) 69 for (int i = 0; i < RRCOUNT; i++)
69 { 70 {
@@ -104,7 +105,7 @@ res_checker (void *cls,
104 105
105 106
106int 107int
107main() 108main ()
108{ 109{
109 struct GNUNET_IDENTITY_PrivateKey priv; 110 struct GNUNET_IDENTITY_PrivateKey priv;
110 struct GNUNET_IDENTITY_PublicKey pub; 111 struct GNUNET_IDENTITY_PublicKey pub;
@@ -112,13 +113,15 @@ main()
112 struct GNUNET_GNSRECORD_Block *rrblock; 113 struct GNUNET_GNSRECORD_Block *rrblock;
113 char *bdata; 114 char *bdata;
114 115
115 parsehex(d,(char*)&priv.ecdsa_key, sizeof (priv.ecdsa_key), 1); 116 parsehex (d,(char*) &priv.ecdsa_key, sizeof (priv.ecdsa_key), 1);
116 priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 117 priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
117 parsehex(zid,(char*)&pub_parsed, 0, 0); 118 parsehex (zid,(char*) &pub_parsed, 0, 0);
118 GNUNET_IDENTITY_key_get_public(&priv, &pub); 119 GNUNET_IDENTITY_key_get_public (&priv, &pub);
119 GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub))); 120 GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub)));
120 rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2); 121 rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2);
121 parsehex(R1_RRBLOCK, (char*)rrblock, 0, 0); 122 parsehex (R1_RRBLOCK, (char*) rrblock, 0, 0);
123 GNUNET_assert (GNUNET_YES
124 == GNUNET_GNSRECORD_is_critical (GNUNET_GNSRECORD_TYPE_PKEY));
122 GNUNET_GNSRECORD_block_decrypt (rrblock, 125 GNUNET_GNSRECORD_block_decrypt (rrblock,
123 &pub_parsed, 126 &pub_parsed,
124 LABEL, 127 LABEL,