diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-06-28 23:39:53 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-06-28 23:39:53 +0200 |
commit | 155205d663289081dad07764ccad3b4f48a423f1 (patch) | |
tree | 000ce7365d2f25fbf01471bb6db28eb1cefc8583 /src/gnsrecord/test_gnsrecord_testvectors.c | |
parent | 40b9351a334b6f1ef0a9d088394c278ea4908c96 (diff) | |
download | gnunet-155205d663289081dad07764ccad3b4f48a423f1.tar.gz gnunet-155205d663289081dad07764ccad3b4f48a423f1.zip |
GNS: Update test vector generation for current spec
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_testvectors.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_testvectors.c | 143 |
1 files changed, 55 insertions, 88 deletions
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 | ||
7 | struct 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 | |||
21 | struct 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 | 37 | int | |
12 | static char *d = | 38 | parsehex (char *src, char *dst, size_t dstlen, int invert) |
13 | "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; | ||
14 | |||
15 | |||
16 | static 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 | |||
39 | int 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 | |||
58 | void | 58 | void |
59 | res_checker (void *cls, | 59 | res_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 | } |