diff options
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 131 |
1 files changed, 125 insertions, 6 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index d6b35544c..16a360bdc 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -81,10 +81,7 @@ print_record (const struct GNUNET_GNSRECORD_Data *rd) | |||
81 | * @param cfg configuration | 81 | * @param cfg configuration |
82 | */ | 82 | */ |
83 | static void | 83 | static void |
84 | run (void *cls, | 84 | run_pkey (void) |
85 | char *const *args, | ||
86 | const char *cfgfile, | ||
87 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
88 | { | 85 | { |
89 | struct GNUNET_GNSRECORD_Data rd[2]; | 86 | struct GNUNET_GNSRECORD_Data rd[2]; |
90 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | 87 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); |
@@ -104,8 +101,9 @@ run (void *cls, | |||
104 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 101 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
105 | GNUNET_IDENTITY_key_get_public (&id_priv, | 102 | GNUNET_IDENTITY_key_get_public (&id_priv, |
106 | &id_pub); | 103 | &id_pub); |
107 | fprintf (stdout, "Zone private key (d, little-endian, with ztype prepended):\n"); | 104 | fprintf (stdout, |
108 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); //FIXME length for privkey? | 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? | ||
109 | fprintf (stdout, "\n"); | 107 | fprintf (stdout, "\n"); |
110 | fprintf (stdout, "Zone identifier (zid):\n"); | 108 | fprintf (stdout, "Zone identifier (zid):\n"); |
111 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | 109 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); |
@@ -177,6 +175,127 @@ run (void *cls, | |||
177 | 175 | ||
178 | 176 | ||
179 | /** | 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 | /** | ||
180 | * The main function of the test vector generation tool. | 299 | * The main function of the test vector generation tool. |
181 | * | 300 | * |
182 | * @param argc number of arguments from the command line | 301 | * @param argc number of arguments from the command line |