diff options
Diffstat (limited to 'src/gnsrecord/gnunet-gnsrecord-tvg.c')
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 328 |
1 files changed, 0 insertions, 328 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c deleted file mode 100644 index 16a360bdc..000000000 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ /dev/null | |||
@@ -1,328 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/gnunet-gns-tvg.c | ||
23 | * @brief Generate test vectors for GNS. | ||
24 | * @author Martin Schanzenbach | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_signatures.h" | ||
29 | #include "gnunet_gns_service.h" | ||
30 | #include "gnunet_gnsrecord_lib.h" | ||
31 | #include "gnunet_dnsparser_lib.h" | ||
32 | #include "gnunet_testing_lib.h" | ||
33 | #include <inttypes.h> | ||
34 | |||
35 | #define TEST_RECORD_LABEL "test" | ||
36 | #define TEST_RECORD_A "1.2.3.4" | ||
37 | #define TEST_RRCOUNT 2 | ||
38 | |||
39 | static void | ||
40 | print_bytes (void *buf, | ||
41 | size_t buf_len, | ||
42 | int fold) | ||
43 | { | ||
44 | int i; | ||
45 | |||
46 | for (i = 0; i < buf_len; i++) | ||
47 | { | ||
48 | if ((0 != i) && (0 != fold) && (i % fold == 0)) | ||
49 | printf ("\n"); | ||
50 | printf ("%02x", ((unsigned char*) buf)[i]); | ||
51 | } | ||
52 | printf ("\n"); | ||
53 | } | ||
54 | |||
55 | |||
56 | static void | ||
57 | print_record (const struct GNUNET_GNSRECORD_Data *rd) | ||
58 | { | ||
59 | |||
60 | fprintf (stdout, | ||
61 | "EXPIRATION: %" PRIu64 "\n", rd->expiration_time); | ||
62 | fprintf (stdout, | ||
63 | "DATA_SIZE: %zu\n", rd->data_size); | ||
64 | fprintf (stdout, | ||
65 | "TYPE: %d\n", rd->record_type); | ||
66 | fprintf (stdout, | ||
67 | "FLAGS: %d\n", rd->flags); | ||
68 | fprintf (stdout, | ||
69 | "DATA:\n"); | ||
70 | print_bytes ((char*) rd->data, rd->data_size, 8); | ||
71 | fprintf (stdout, "\n"); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Main function that will be run. | ||
77 | * | ||
78 | * @param cls closure | ||
79 | * @param args remaining command-line arguments | ||
80 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
81 | * @param cfg configuration | ||
82 | */ | ||
83 | static void | ||
84 | run_pkey (void) | ||
85 | { | ||
86 | struct GNUNET_GNSRECORD_Data rd[2]; | ||
87 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | ||
88 | struct GNUNET_GNSRECORD_Block *rrblock; | ||
89 | char *bdata; | ||
90 | struct GNUNET_IDENTITY_PrivateKey id_priv; | ||
91 | struct GNUNET_IDENTITY_PublicKey id_pub; | ||
92 | struct GNUNET_IDENTITY_PrivateKey pkey_data_p; | ||
93 | struct GNUNET_IDENTITY_PublicKey pkey_data; | ||
94 | void *data; | ||
95 | size_t data_size; | ||
96 | char *rdata; | ||
97 | size_t rdata_size; | ||
98 | char ztld[128]; | ||
99 | |||
100 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
101 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | ||
102 | GNUNET_IDENTITY_key_get_public (&id_priv, | ||
103 | &id_pub); | ||
104 | fprintf (stdout, | ||
105 | "Zone private key (d, little-endian, with ztype prepended):\n"); | ||
106 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); // FIXME length for privkey? | ||
107 | fprintf (stdout, "\n"); | ||
108 | fprintf (stdout, "Zone identifier (zid):\n"); | ||
109 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | ||
110 | GNUNET_STRINGS_data_to_string (&id_pub, | ||
111 | GNUNET_IDENTITY_key_get_length (&id_pub), | ||
112 | ztld, | ||
113 | sizeof (ztld)); | ||
114 | fprintf (stdout, "\n"); | ||
115 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); | ||
116 | fprintf (stdout, "%s\n", ztld); | ||
117 | fprintf (stdout, "\n"); | ||
118 | |||
119 | pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
120 | GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p.ecdsa_key); | ||
121 | GNUNET_IDENTITY_key_get_public (&pkey_data_p, | ||
122 | &pkey_data); | ||
123 | fprintf (stdout, | ||
124 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); | ||
125 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); | ||
126 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value ( | ||
127 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | ||
128 | rd[0].data = data; | ||
129 | rd[0].data_size = data_size; | ||
130 | rd[0].expiration_time = exp_abs.abs_value_us; | ||
131 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; | ||
132 | fprintf (stdout, "Record #0\n"); | ||
133 | print_record (&rd[0]); | ||
134 | |||
135 | rd[1].data = &pkey_data; | ||
136 | rd[1].data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
137 | rd[1].expiration_time = exp_abs.abs_value_us; | ||
138 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
139 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
140 | fprintf (stdout, "Record #1\n"); | ||
141 | print_record (&rd[1]); | ||
142 | |||
143 | rdata_size = GNUNET_GNSRECORD_records_get_size (2, | ||
144 | rd); | ||
145 | rdata = GNUNET_malloc (rdata_size); | ||
146 | GNUNET_GNSRECORD_records_serialize (2, | ||
147 | rd, | ||
148 | rdata_size, | ||
149 | rdata); | ||
150 | fprintf (stdout, "RDATA:\n"); | ||
151 | print_bytes (rdata, rdata_size, 8); | ||
152 | fprintf (stdout, "\n"); | ||
153 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, | ||
154 | exp_abs, | ||
155 | TEST_RECORD_LABEL, | ||
156 | rd, | ||
157 | TEST_RRCOUNT); | ||
158 | size_t bdata_size = ntohl (rrblock->ecdsa_block.purpose.size) | ||
159 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
160 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
161 | size_t ecblock_size = ntohl (rrblock->ecdsa_block.purpose.size) | ||
162 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
163 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
164 | size_t block_size = ecblock_size + sizeof (uint32_t); | ||
165 | |||
166 | bdata = (char*) &(&rrblock->ecdsa_block)[1]; | ||
167 | fprintf (stdout, "BDATA:\n"); | ||
168 | print_bytes (bdata, bdata_size, 8); | ||
169 | fprintf (stdout, "\n"); | ||
170 | fprintf (stdout, "RRBLOCK:\n"); | ||
171 | print_bytes (rrblock, block_size, 8); | ||
172 | fprintf (stdout, "\n"); | ||
173 | GNUNET_free (rdata); | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Main function that will be run. | ||
179 | * | ||
180 | * @param cls closure | ||
181 | * @param args remaining command-line arguments | ||
182 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
183 | * @param cfg configuration | ||
184 | */ | ||
185 | static void | ||
186 | run_edkey (void) | ||
187 | { | ||
188 | struct GNUNET_GNSRECORD_Data rd[2]; | ||
189 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | ||
190 | struct GNUNET_GNSRECORD_Block *rrblock; | ||
191 | char *bdata; | ||
192 | struct GNUNET_IDENTITY_PrivateKey id_priv; | ||
193 | struct GNUNET_IDENTITY_PublicKey id_pub; | ||
194 | struct GNUNET_IDENTITY_PrivateKey pkey_data_p; | ||
195 | struct GNUNET_IDENTITY_PublicKey pkey_data; | ||
196 | void *data; | ||
197 | size_t data_size; | ||
198 | char *rdata; | ||
199 | size_t rdata_size; | ||
200 | char ztld[128]; | ||
201 | |||
202 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); | ||
203 | GNUNET_CRYPTO_eddsa_key_create (&id_priv.eddsa_key); | ||
204 | GNUNET_IDENTITY_key_get_public (&id_priv, | ||
205 | &id_pub); | ||
206 | fprintf (stdout, | ||
207 | "Zone private key (d, little-endian, with ztype prepended):\n"); | ||
208 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); // FIXME length for privkey? | ||
209 | fprintf (stdout, "\n"); | ||
210 | fprintf (stdout, "Zone identifier (zid):\n"); | ||
211 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | ||
212 | GNUNET_STRINGS_data_to_string (&id_pub, | ||
213 | GNUNET_IDENTITY_key_get_length (&id_pub), | ||
214 | ztld, | ||
215 | sizeof (ztld)); | ||
216 | fprintf (stdout, "\n"); | ||
217 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); | ||
218 | fprintf (stdout, "%s\n", ztld); | ||
219 | fprintf (stdout, "\n"); | ||
220 | |||
221 | pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY); | ||
222 | GNUNET_CRYPTO_eddsa_key_create (&pkey_data_p.eddsa_key); | ||
223 | GNUNET_IDENTITY_key_get_public (&pkey_data_p, | ||
224 | &pkey_data); | ||
225 | fprintf (stdout, | ||
226 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); | ||
227 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); | ||
228 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value ( | ||
229 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | ||
230 | rd[0].data = data; | ||
231 | rd[0].data_size = data_size; | ||
232 | rd[0].expiration_time = exp_abs.abs_value_us; | ||
233 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; | ||
234 | fprintf (stdout, "Record #0\n"); | ||
235 | print_record (&rd[0]); | ||
236 | |||
237 | rd[1].data = &pkey_data; | ||
238 | rd[1].data_size = sizeof (struct GNUNET_CRYPTO_EddsaPublicKey); | ||
239 | rd[1].expiration_time = exp_abs.abs_value_us; | ||
240 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_EDKEY; | ||
241 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
242 | fprintf (stdout, "Record #1\n"); | ||
243 | print_record (&rd[1]); | ||
244 | |||
245 | rdata_size = GNUNET_GNSRECORD_records_get_size (2, | ||
246 | rd); | ||
247 | rdata = GNUNET_malloc (rdata_size); | ||
248 | GNUNET_GNSRECORD_records_serialize (2, | ||
249 | rd, | ||
250 | rdata_size, | ||
251 | rdata); | ||
252 | fprintf (stdout, "RDATA:\n"); | ||
253 | print_bytes (rdata, rdata_size, 8); | ||
254 | fprintf (stdout, "\n"); | ||
255 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, | ||
256 | exp_abs, | ||
257 | TEST_RECORD_LABEL, | ||
258 | rd, | ||
259 | TEST_RRCOUNT); | ||
260 | size_t bdata_size = ntohl (rrblock->eddsa_block.purpose.size) | ||
261 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
262 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
263 | size_t ecblock_size = ntohl (rrblock->eddsa_block.purpose.size) | ||
264 | + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) | ||
265 | + sizeof(struct GNUNET_CRYPTO_EddsaSignature); | ||
266 | size_t block_size = ecblock_size + sizeof (uint32_t); | ||
267 | |||
268 | bdata = (char*) &(&rrblock->eddsa_block)[1]; | ||
269 | fprintf (stdout, "BDATA:\n"); | ||
270 | print_bytes (bdata, bdata_size, 8); | ||
271 | fprintf (stdout, "\n"); | ||
272 | fprintf (stdout, "RRBLOCK:\n"); | ||
273 | print_bytes (rrblock, block_size, 8); | ||
274 | fprintf (stdout, "\n"); | ||
275 | GNUNET_free (rdata); | ||
276 | } | ||
277 | |||
278 | |||
279 | /** | ||
280 | * Main function that will be run. | ||
281 | * | ||
282 | * @param cls closure | ||
283 | * @param args remaining command-line arguments | ||
284 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
285 | * @param cfg configuration | ||
286 | */ | ||
287 | static void | ||
288 | run (void *cls, | ||
289 | char *const *args, | ||
290 | const char *cfgfile, | ||
291 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
292 | { | ||
293 | run_pkey(); | ||
294 | run_edkey(); | ||
295 | } | ||
296 | |||
297 | |||
298 | /** | ||
299 | * The main function of the test vector generation tool. | ||
300 | * | ||
301 | * @param argc number of arguments from the command line | ||
302 | * @param argv command line arguments | ||
303 | * @return 0 ok, 1 on error | ||
304 | */ | ||
305 | int | ||
306 | main (int argc, | ||
307 | char *const *argv) | ||
308 | { | ||
309 | const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
310 | GNUNET_GETOPT_OPTION_END | ||
311 | }; | ||
312 | |||
313 | GNUNET_assert (GNUNET_OK == | ||
314 | GNUNET_log_setup ("gnunet-gns-tvg", | ||
315 | "INFO", | ||
316 | NULL)); | ||
317 | if (GNUNET_OK != | ||
318 | GNUNET_PROGRAM_run (argc, argv, | ||
319 | "gnunet-gns-tvg", | ||
320 | "Generate test vectors for GNS", | ||
321 | options, | ||
322 | &run, NULL)) | ||
323 | return 1; | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | |||
328 | /* end of gnunet-gns-tvg.c */ | ||