aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-06-28 23:39:53 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-06-28 23:39:53 +0200
commit155205d663289081dad07764ccad3b4f48a423f1 (patch)
tree000ce7365d2f25fbf01471bb6db28eb1cefc8583 /src/gnsrecord
parent40b9351a334b6f1ef0a9d088394c278ea4908c96 (diff)
downloadgnunet-155205d663289081dad07764ccad3b4f48a423f1.tar.gz
gnunet-155205d663289081dad07764ccad3b4f48a423f1.zip
GNS: Update test vector generation for current spec
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/Makefile.am15
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c23
-rw-r--r--src/gnsrecord/test_gnsrecord_testvectors.c143
3 files changed, 79 insertions, 102 deletions
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 1cd446400..7bffa98e5 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -19,6 +19,7 @@ noinst_PROGRAMS = \
19check_PROGRAMS = \ 19check_PROGRAMS = \
20 test_gnsrecord_crypto \ 20 test_gnsrecord_crypto \
21 test_gnsrecord_serialization \ 21 test_gnsrecord_serialization \
22 test_gnsrecord_testvectors \
22 test_gnsrecord_block_expiration \ 23 test_gnsrecord_block_expiration \
23 perf_gnsrecord_crypto 24 perf_gnsrecord_crypto
24 25
@@ -86,13 +87,13 @@ libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \
86EXTRA_DIST = \ 87EXTRA_DIST = \
87 $(check_SCRIPTS) 88 $(check_SCRIPTS)
88 89
89#test_gnsrecord_testvectors_SOURCES = \ 90test_gnsrecord_testvectors_SOURCES = \
90# test_gnsrecord_testvectors.c 91 test_gnsrecord_testvectors.c
91#test_gnsrecord_testvectors_LDADD = \ 92test_gnsrecord_testvectors_LDADD = \
92# $(top_builddir)/src/testing/libgnunettesting.la \ 93 $(top_builddir)/src/testing/libgnunettesting.la \
93# $(top_builddir)/src/identity/libgnunetidentity.la \ 94 $(top_builddir)/src/identity/libgnunetidentity.la \
94# libgnunetgnsrecord.la \ 95 libgnunetgnsrecord.la \
95# $(top_builddir)/src/util/libgnunetutil.la 96 $(top_builddir)/src/util/libgnunetutil.la
96 97
97 98
98test_gnsrecord_serialization_SOURCES = \ 99test_gnsrecord_serialization_SOURCES = \
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index ef111b3bd..2bc31471e 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -94,10 +94,18 @@ print_bytes (void *buf,
94static void 94static void
95print_record (const struct GNUNET_GNSRECORD_Data *rd) 95print_record (const struct GNUNET_GNSRECORD_Data *rd)
96{ 96{
97 struct GNUNET_TIME_Relative rt;
98 struct GNUNET_TIME_Absolute at;
97 uint16_t flags = htons (rd->flags); 99 uint16_t flags = htons (rd->flags);
98 uint64_t abs_nbo = GNUNET_htonll (rd->expiration_time); 100 uint64_t abs_nbo = GNUNET_htonll (rd->expiration_time);
99 uint16_t size_nbo = htons (rd->data_size); 101 uint16_t size_nbo = htons (rd->data_size);
100 uint32_t type_nbo = htonl (rd->record_type); 102 uint32_t type_nbo = htonl (rd->record_type);
103 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
104 {
105 rt.rel_value_us = rd->expiration_time;
106 at = GNUNET_TIME_relative_to_absolute (rt);
107 abs_nbo = GNUNET_htonll (at.abs_value_us);
108 }
101 printf ("EXPIRATION:\n"); 109 printf ("EXPIRATION:\n");
102 print_bytes (&abs_nbo, sizeof (abs_nbo), 8); 110 print_bytes (&abs_nbo, sizeof (abs_nbo), 8);
103 printf ("\nDATA_SIZE:\n"); 111 printf ("\nDATA_SIZE:\n");
@@ -156,7 +164,8 @@ run_pkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char *label)
156 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub)); 164 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub));
157 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8); 165 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8);
158 GNUNET_STRINGS_data_to_string (&id_pub, 166 GNUNET_STRINGS_data_to_string (&id_pub,
159 GNUNET_IDENTITY_public_key_get_length (&id_pub), 167 GNUNET_IDENTITY_public_key_get_length (
168 &id_pub),
160 ztld, 169 ztld,
161 sizeof (ztld)); 170 sizeof (ztld));
162 printf ("\n"); 171 printf ("\n");
@@ -282,7 +291,8 @@ run_edkey (struct GNUNET_GNSRECORD_Data *rd, int rd_count, const char*label)
282 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub)); 291 GNUNET_assert (0 < GNUNET_IDENTITY_public_key_get_length (&id_pub));
283 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8); 292 print_bytes (&id_pub, GNUNET_IDENTITY_public_key_get_length (&id_pub), 8);
284 GNUNET_STRINGS_data_to_string (&id_pub, 293 GNUNET_STRINGS_data_to_string (&id_pub,
285 GNUNET_IDENTITY_public_key_get_length (&id_pub), 294 GNUNET_IDENTITY_public_key_get_length (
295 &id_pub),
286 ztld, 296 ztld,
287 sizeof (ztld)); 297 sizeof (ztld));
288 printf ("\n"); 298 printf ("\n");
@@ -381,7 +391,7 @@ run (void *cls,
381 struct GNUNET_GNSRECORD_Data rd[3]; 391 struct GNUNET_GNSRECORD_Data rd[3];
382 struct GNUNET_TIME_Absolute exp1; 392 struct GNUNET_TIME_Absolute exp1;
383 struct GNUNET_TIME_Absolute exp2; 393 struct GNUNET_TIME_Absolute exp2;
384 struct GNUNET_TIME_Relative exp3; 394 struct GNUNET_TIME_Absolute exp3;
385 size_t pkey_data_size; 395 size_t pkey_data_size;
386 size_t ip_data_size; 396 size_t ip_data_size;
387 char *pkey_data; 397 char *pkey_data;
@@ -394,7 +404,7 @@ run (void *cls,
394 &exp1); 404 &exp1);
395 GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01", 405 GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01",
396 &exp2); 406 &exp2);
397 GNUNET_STRINGS_fancy_time_to_relative ("100y", 407 GNUNET_STRINGS_fancy_time_to_absolute ("3333-04-21 06:07:09",
398 &exp3); 408 &exp3);
399 409
400 410
@@ -429,10 +439,9 @@ run (void *cls,
429 439
430 rd[2].data = "Hello World"; 440 rd[2].data = "Hello World";
431 rd[2].data_size = strlen (rd[2].data); 441 rd[2].data_size = strlen (rd[2].data);
432 rd[2].expiration_time = exp3.rel_value_us; 442 rd[2].expiration_time = exp3.abs_value_us;
433 rd[2].record_type = GNUNET_DNSPARSER_TYPE_TXT; 443 rd[2].record_type = GNUNET_DNSPARSER_TYPE_TXT;
434 rd[2].flags = GNUNET_GNSRECORD_RF_SUPPLEMENTAL 444 rd[2].flags = GNUNET_GNSRECORD_RF_SUPPLEMENTAL;
435 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
436 445
437 run_pkey (&rd_pkey, 1, "testdelegation"); 446 run_pkey (&rd_pkey, 1, "testdelegation");
438 run_pkey (rd, 3, "\u5929\u4e0b\u7121\u6575"); 447 run_pkey (rd, 3, "\u5929\u4e0b\u7121\u6575");
diff --git a/src/gnsrecord/test_gnsrecord_testvectors.c b/src/gnsrecord/test_gnsrecord_testvectors.c
index bb4922417..2b05c1b5d 100644
--- a/src/gnsrecord/test_gnsrecord_testvectors.c
+++ b/src/gnsrecord/test_gnsrecord_testvectors.c
@@ -1,42 +1,41 @@
1#include "platform.h" 1#include "platform.h"
2#include "gnunet_util_lib.h" 2#include "gnunet_util_lib.h"
3#include "gnunet_signatures.h"
4#include "gnunet_gns_service.h" 3#include "gnunet_gns_service.h"
5#include "gnunet_gnsrecord_lib.h" 4#include "gnunet_gnsrecord_lib.h"
6#include "gnunet_dnsparser_lib.h"
7#include "gnunet_testing_lib.h"
8#include <inttypes.h> 5#include <inttypes.h>
9 6
7struct GnsTv
8{
9 char *d;
10 char *zid;
11 int rrcount;
12 char *label;
13 char *q;
14 char *rdata;
15 char *bdata;
16 char *rrblock;
17};
18
19#define TVCOUNT 1
20
21struct GnsTv tvs[] = {
22 { .d = "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65\0",
23 .zid =
24 "000100143cf4b924032022f0dc50581453b85d93b047b63d446c5845cb48445ddb96688f\0",
25 .rrcount = 1,
26 .label = "7465737464656c65676174696f6e\0",
27 .q =
28 "ed76cefdb6a9d73a9e1f10d96717eba3fc89ebe1b37584f6b077c2912e2fc5f312cf74e1b4d4dfca5abaec736d72666f0faa2945217f3b1436aa4e27c14c9732\0",
29 .rdata =
30 "0008c06fb9281580002000010001000021e3b30ff93bc6d35ac8c6e0e13afdff794cb7b44bbbc748d259d0a0284dbe84\0",
31 .bdata =
32 "9cc455a1293319435993cb3d67179ec06ea8d8894e904a0c35e91c5c2ff2ed939cc2f8301231f44e592a4ac87e4998b94625c64af51686a2b36a2b2892d44f2d\0",
33 .rrblock =
34 "000000b0000100149bf233198c6d53bbdbac495cabd91049a684af3f4051bacab0dcf21c8cf27a1a44d240d07902f490b7c43ef00758abce8851c18c70ac6df97a88f79211cf875f784885ca3e349ec4ca892b9ff084c5358965b8e74a2315952d4c8c06521c2f0c0008c06fb92815809cc455a1293319435993cb3d67179ec06ea8d8894e904a0c35e91c5c2ff2ed939cc2f8301231f44e592a4ac87e4998b94625c64af51686a2b36a2b2892d44f2d\0"}
35};
10 36
11 37int
12static char *d = 38parsehex (char *src, char *dst, size_t dstlen, int invert)
13 "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98";
14
15
16static char *zid =
17 "00010000677c477d2d93097c85b195c6f96d84ff61f5982c2c4fe02d5a11fedfb0c2901f";
18
19#define RRCOUNT 2
20#define LABEL "namesystem"
21
22#define R0_EXPIRATION
23#define R0_DATA_SIZE 4
24#define R0_TYPE 1
25#define R0_FLAGS 0
26#define R0_DATA "01020304"
27
28/* Record #1*/
29#define R1_EXPIRATION 26147096139323793
30#define R1_DATA_SIZE 36
31#define R1_TYPE 65536
32#define R1_FLAGS 2
33#define R1_DATA \
34 "000100000e601be42eb57fb4697610cf3a3b18347b65a33f025b5b174abefb30807bfecf"
35
36#define R1_RRBLOCK \
37 "000100008e16da87203b5159c5538e9b765742e968c54af9afbc0890dc80205ad14c84e107b0c115fc0089aa38b9c7ab9cbe1d77040d282a51a2ad493f61f3495f02d8170fe473a55ec6bdf9a509ab1701ffc37ea3bb4cac4a672520986df96e67cc1a73000000940000000f0034e53be193799100e4837eb5d04f92903de4b5234e8ccac5736c9793379a59c33375fc8951aca2eb7aad067bf9af60bf26758646a17f5e5c3b6215f94079545b1c4d4f1b2ebb22c2b4dad44126817b6f001530d476401dd67ac0148554e806353da9e4298079f3e1b16942c48d90c4360c61238c40d9d52911aea52cc0037ac7160bb3cf5b2f4a722fd96b"
38
39int parsehex (char *src, char *dst, size_t dstlen, int invert)
40{ 39{
41 char *line = src; 40 char *line = src;
42 char *data = line; 41 char *data = line;
@@ -55,52 +54,14 @@ int parsehex (char *src, char *dst, size_t dstlen, int invert)
55 return data_len; 54 return data_len;
56} 55}
57 56
57
58void 58void
59res_checker (void *cls, 59res_checker (void *cls,
60 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) 60 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
61{ 61{
62 int r0_found = 0; 62 struct GnsTv *tv = cls;
63 int r1_found = 0; 63 GNUNET_assert (rd_count == tv->rrcount);
64 char r0_data[R0_DATA_SIZE]; 64 printf ("RRCOUNT good: %d\n", rd_count);
65 char r1_data[R1_DATA_SIZE];
66 parsehex (R0_DATA, (char*) r0_data, 0, 0);
67 parsehex (R1_DATA, (char*) r1_data, 0, 0);
68 GNUNET_assert (rd_count == RRCOUNT);
69 for (int i = 0; i < RRCOUNT; i++)
70 {
71 if (rd[i].record_type == R0_TYPE)
72 {
73 if (0 != memcmp (rd[i].data, r0_data, R0_DATA_SIZE))
74 {
75 printf ("R0 Data mismatch\n");
76 continue;
77 }
78 if (rd[i].expiration_time != R0_EXPIRATION)
79 {
80 printf ("R0 expiration mismatch\n");
81 continue;
82 }
83 r0_found = 1;
84 }
85 if (rd[i].record_type == R1_TYPE)
86 {
87 if (0 != memcmp (rd[i].data, r1_data, R1_DATA_SIZE))
88 {
89 printf ("R1 Data mismatch\n");
90 continue;
91 }
92 if (rd[i].expiration_time != R1_EXPIRATION)
93 {
94 printf ("R1 expiration mismatch\n");
95 continue;
96 }
97
98 r1_found = 1;
99 }
100
101 }
102 GNUNET_assert (r0_found);
103 GNUNET_assert (r1_found);
104} 65}
105 66
106 67
@@ -112,20 +73,26 @@ main ()
112 struct GNUNET_IDENTITY_PublicKey pub_parsed; 73 struct GNUNET_IDENTITY_PublicKey pub_parsed;
113 struct GNUNET_GNSRECORD_Block *rrblock; 74 struct GNUNET_GNSRECORD_Block *rrblock;
114 char *bdata; 75 char *bdata;
76 char label[128];
115 77
116 parsehex (d,(char*) &priv.ecdsa_key, sizeof (priv.ecdsa_key), 1); 78 for (int i = 0; i < TVCOUNT; i++)
117 priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 79 {
118 parsehex (zid,(char*) &pub_parsed, 0, 0); 80 memset (label, 0, sizeof (label));
119 GNUNET_IDENTITY_key_get_public (&priv, &pub); 81 parsehex (tvs[i].d,(char*) &priv.ecdsa_key, sizeof (priv.ecdsa_key), 1);
120 GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub))); 82 priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
121 rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2); 83 parsehex (tvs[i].zid,(char*) &pub_parsed, 0, 0);
122 parsehex (R1_RRBLOCK, (char*) rrblock, 0, 0); 84 priv.type = pub_parsed.type;
123 GNUNET_assert (GNUNET_YES 85 GNUNET_IDENTITY_key_get_public (&priv, &pub);
124 == GNUNET_GNSRECORD_is_critical (GNUNET_GNSRECORD_TYPE_PKEY)); 86 // GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub)));
125 GNUNET_GNSRECORD_block_decrypt (rrblock, 87 rrblock = GNUNET_malloc (strlen (tvs[i].rrblock));
126 &pub_parsed, 88 parsehex (tvs[i].rrblock, (char*) rrblock, 0, 0);
127 LABEL, 89 parsehex (tvs[i].label, (char*) label, 0, 0);
128 &res_checker, 90 printf ("Got label: %s\n", label);
129 NULL); 91 GNUNET_GNSRECORD_block_decrypt (rrblock,
92 &pub_parsed,
93 label,
94 &res_checker,
95 &tvs[i]);
96 }
130 return 0; 97 return 0;
131} 98}