From 6799b1cdf043101c29b99f1ef4b60c70b6e0ca34 Mon Sep 17 00:00:00 2001 From: Federico Lucifredi Date: Sun, 20 Jan 2008 23:10:35 +0000 Subject: adding revised avahi_keytag(), takes an AvahiRecord. git-svn-id: file:///home/lennart/svn/public/avahi/branches/federico2@1733 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/domain-util.c | 39 +++++++++++++++++++++++++++++++++++++-- avahi-core/domain-util.h | 5 ++++- avahi-core/rr.h | 5 +++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/avahi-core/domain-util.c b/avahi-core/domain-util.c index 7f562db..627ce5d 100644 --- a/avahi-core/domain-util.c +++ b/avahi-core/domain-util.c @@ -240,8 +240,8 @@ uint8_t avahi_count_canonical_labels(const char* input){ } /* reference keytag generator from RFC 4034 */ -/* invoke with avahi_keytag(, ); */ -uint16_t avahi_keytag(uint8_t key[], uint16_t keysize){ +/* invoke with keytag(, ); */ +uint16_t keytag(uint8_t key[], uint16_t keysize){ uint32_t ac; int i; @@ -252,3 +252,38 @@ uint16_t avahi_keytag(uint8_t key[], uint16_t keysize){ return ac & 0xFFFF; } + +/*invoke with avahi_keytag(); */ +uint16_t avahi_keytag(AvahiRecord r){ + uint16_t result; + AvahiDNSPacket *tmp; + + if (r->key.type != AVAHI_DNS_TYPE_RRSIG) + return NULL; /* invalid RRTYPE to generate keytag on */ + + p = avahi_dns_packet_new_query(0); /* MTU */ + + if (!p) { /*OOM check */ + avahi_log_error("avahi_dns_packet_new_update() failed."); + assert(p); + } + + /* no TTL binding, leave record unaltered */ + result = avahi_dns_packet_append_record(tmp, key, 0, 0); + + if (!result) { + avahi_log_error("appending of rdata failed."); + assert(result); + } + + /* update RRSET we modified */ + avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ARCOUNT, 1); + + /* finally, generate keytag */ + /* first arg is rdata address, second arg is rdlength */ + result = keytag(AVAHI_DNS_PACKET_DATA(tmp), sizeof(uint16_t) + 2*sizeof(uint8_t) + AVAHI_DNSSEC_SHA1_KEYLENGTH); + + avahi_free(tmp); + + return result; +} \ No newline at end of file diff --git a/avahi-core/domain-util.h b/avahi-core/domain-util.h index 2e4cf3d..1e71426 100644 --- a/avahi-core/domain-util.h +++ b/avahi-core/domain-util.h @@ -48,8 +48,11 @@ unsigned char * avahi_c_to_canonical_string(const char* input); /** returns the number of labels in a canonical DNS domain */ uint8_t avahi_count_canonical_labels(const char* input); +/** returns keytag of a given DNSKEY record */ +uint16_t avahi_keytag(AvahiRecord r); + /* reference keytag generator from RFC 4034 */ -uint16_t avahi_keytag(uint8_t key[], uint16_t keysize) +uint16_t avahi_keytag(uint8_t key[], uint16_t keysize); AVAHI_C_DECL_END diff --git a/avahi-core/rr.h b/avahi-core/rr.h index 2437ef2..2df7ba1 100644 --- a/avahi-core/rr.h +++ b/avahi-core/rr.h @@ -54,7 +54,8 @@ enum { enum { AVAHI_DNSSEC_PROTO = 0x3, AVAHI_DNSSEC_VALIDITY = 30, - AVAHI_DNSSEC_TIME_DRIFT = 3600 + AVAHI_DNSSEC_TIME_DRIFT = 3600, + AVAHI_DNSSEC_SHA1_KEYLENGTH = 89 }; /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */ @@ -134,7 +135,7 @@ typedef struct AvahiRecord { uint32_t signature_expiration; uint32_t signature_inception; uint16_t key_tag; - char* signers_name; + char* signers_name; /*uncompressed label */ char* signature; } rrsig; /** data for rrsig record */ -- cgit