diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-06 21:59:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-06 21:59:17 +0000 |
commit | 5640bd261ae9578a9e1e4db1634ea8bec84337b3 (patch) | |
tree | 560debef1cf6530060be36efc4fd1809a0d60826 /src/gnsrecord | |
parent | 7918527acf021ad8753ead08334d6a6ac71084c4 (diff) | |
download | gnunet-5640bd261ae9578a9e1e4db1634ea8bec84337b3.tar.gz gnunet-5640bd261ae9578a9e1e4db1634ea8bec84337b3.zip |
-adding CERT support to DNS plugin
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/plugin_gnsrecord_dns.c | 120 |
1 files changed, 119 insertions, 1 deletions
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c index 3c508ae7e..42cf5e3ec 100644 --- a/src/gnsrecord/plugin_gnsrecord_dns.c +++ b/src/gnsrecord/plugin_gnsrecord_dns.c | |||
@@ -140,6 +140,38 @@ dns_value_to_string (void *cls, | |||
140 | } | 140 | } |
141 | return ptr; | 141 | return ptr; |
142 | } | 142 | } |
143 | case GNUNET_DNSPARSER_TYPE_CERT: | ||
144 | { | ||
145 | struct GNUNET_DNSPARSER_CertRecord *cert; | ||
146 | size_t off; | ||
147 | char *base64; | ||
148 | int len; | ||
149 | |||
150 | off = 0; | ||
151 | cert = GNUNET_DNSPARSER_parse_cert (data, | ||
152 | data_size, | ||
153 | &off); | ||
154 | if ( (NULL == cert) || | ||
155 | (off != data_size) ) | ||
156 | { | ||
157 | GNUNET_break_op (0); | ||
158 | GNUNET_DNSPARSER_free_cert (cert); | ||
159 | return NULL; | ||
160 | } | ||
161 | len = GNUNET_STRINGS_base64_encode (cert->certificate_data, | ||
162 | cert->certificate_size, | ||
163 | &base64); | ||
164 | GNUNET_asprintf (&result, | ||
165 | "%u %u %u %.*s", | ||
166 | cert->cert_type, | ||
167 | cert->cert_tag, | ||
168 | cert->algorithm, | ||
169 | len, | ||
170 | base64); | ||
171 | GNUNET_free (base64); | ||
172 | GNUNET_DNSPARSER_free_cert (cert); | ||
173 | return result; | ||
174 | } | ||
143 | case GNUNET_DNSPARSER_TYPE_MX: | 175 | case GNUNET_DNSPARSER_TYPE_MX: |
144 | { | 176 | { |
145 | struct GNUNET_DNSPARSER_MxRecord *mx; | 177 | struct GNUNET_DNSPARSER_MxRecord *mx; |
@@ -153,7 +185,7 @@ dns_value_to_string (void *cls, | |||
153 | (off != data_size) ) | 185 | (off != data_size) ) |
154 | { | 186 | { |
155 | GNUNET_break_op (0); | 187 | GNUNET_break_op (0); |
156 | GNUNET_free_non_null (mx); | 188 | GNUNET_DNSPARSER_free_mx (mx); |
157 | return NULL; | 189 | return NULL; |
158 | } | 190 | } |
159 | GNUNET_asprintf (&result, | 191 | GNUNET_asprintf (&result, |
@@ -310,6 +342,92 @@ dns_string_to_value (void *cls, | |||
310 | memcpy (*data, cnamebuf, off); | 342 | memcpy (*data, cnamebuf, off); |
311 | return GNUNET_OK; | 343 | return GNUNET_OK; |
312 | } | 344 | } |
345 | case GNUNET_DNSPARSER_TYPE_CERT: | ||
346 | { | ||
347 | char *sdup; | ||
348 | const char *typep; | ||
349 | const char *keyp; | ||
350 | const char *algp; | ||
351 | const char *certp; | ||
352 | unsigned int type; | ||
353 | unsigned int key; | ||
354 | unsigned int alg; | ||
355 | size_t cert_size; | ||
356 | char *cert_data; | ||
357 | struct GNUNET_DNSPARSER_CertRecord cert; | ||
358 | |||
359 | sdup = GNUNET_strdup (s); | ||
360 | typep = strtok (sdup, " "); | ||
361 | if ( (NULL == typep) || | ||
362 | (1 != sscanf (typep, | ||
363 | "%u", | ||
364 | &type)) || | ||
365 | (type > UINT16_MAX) ) | ||
366 | { | ||
367 | GNUNET_free (sdup); | ||
368 | return GNUNET_SYSERR; | ||
369 | } | ||
370 | keyp = strtok (NULL, " "); | ||
371 | if ( (NULL == keyp) || | ||
372 | (1 != sscanf (keyp, | ||
373 | "%u", | ||
374 | &key)) || | ||
375 | (key > UINT16_MAX) ) | ||
376 | { | ||
377 | GNUNET_free (sdup); | ||
378 | return GNUNET_SYSERR; | ||
379 | } | ||
380 | algp = strtok (NULL, " "); | ||
381 | if ( (NULL == algp) || | ||
382 | (1 != sscanf (algp, | ||
383 | "%u", | ||
384 | &alg)) || | ||
385 | (alg > UINT8_MAX) ) | ||
386 | { | ||
387 | GNUNET_free (sdup); | ||
388 | return GNUNET_SYSERR; | ||
389 | } | ||
390 | certp = strtok (NULL, " "); | ||
391 | if ( (NULL == certp) || | ||
392 | (0 == strlen (certp) ) ) | ||
393 | { | ||
394 | GNUNET_free (sdup); | ||
395 | return GNUNET_SYSERR; | ||
396 | } | ||
397 | cert_size = GNUNET_STRINGS_base64_decode (certp, | ||
398 | strlen (certp), | ||
399 | &cert_data); | ||
400 | GNUNET_free (sdup); | ||
401 | cert.cert_type = type; | ||
402 | cert.cert_tag = key; | ||
403 | cert.algorithm = alg; | ||
404 | cert.certificate_size = cert_size; | ||
405 | cert.certificate_data = cert_data; | ||
406 | { | ||
407 | char certbuf[cert_size + sizeof (struct GNUNET_TUN_DnsCertRecord)]; | ||
408 | size_t off; | ||
409 | |||
410 | off = 0; | ||
411 | if (GNUNET_OK != | ||
412 | GNUNET_DNSPARSER_builder_add_cert (certbuf, | ||
413 | sizeof (certbuf), | ||
414 | &off, | ||
415 | &cert)) | ||
416 | { | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
418 | _("Failed to serialize CERT record with %u bytes\n"), | ||
419 | (unsigned int) cert_size); | ||
420 | GNUNET_free (cert_data); | ||
421 | return GNUNET_SYSERR; | ||
422 | } | ||
423 | GNUNET_free (cert_data); | ||
424 | *data_size = off; | ||
425 | *data = GNUNET_malloc (off); | ||
426 | memcpy (*data, certbuf, off); | ||
427 | } | ||
428 | GNUNET_free (cert_data); | ||
429 | return GNUNET_OK; | ||
430 | } | ||
313 | case GNUNET_DNSPARSER_TYPE_SOA: | 431 | case GNUNET_DNSPARSER_TYPE_SOA: |
314 | { | 432 | { |
315 | struct GNUNET_DNSPARSER_SoaRecord soa; | 433 | struct GNUNET_DNSPARSER_SoaRecord soa; |