sig_24.c revision 0e8cf9a887c70f96ac448b06c069d90b830215cc
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Copyright (C) 1999 Internet Software Consortium.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews *
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Permission to use, copy, modify, and distribute this software for any
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * purpose with or without fee is hereby granted, provided that the above
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * copyright notice and this permission notice appear in all copies.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews *
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * SOFTWARE.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews /* $Id: sig_24.c,v 1.7 1999/02/16 22:42:29 marka Exp $ */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* RFC 2065 */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#ifndef RDATA_GENERIC_SIG_24_H
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#define RDATA_GENERIC_SIG_24_H
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsfromtext_sig(dns_rdataclass_t class, dns_rdatatype_t type,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_lex_t *lexer, dns_name_t *origin,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_boolean_t downcase, isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_token_t token;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned char c;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdatatype_t covered;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_textregion_t *tsr;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews char *e;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_result_t result;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_t buffer;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews class = class; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews origin = origin; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews downcase = downcase; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* type covered */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews tsr = &token.value.as_textregion;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews result = dns_rdatatype_fromtext(&covered, tsr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result != DNS_R_SUCCESS && result != DNS_R_NOTIMPLEMENTED) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews covered = strtol(token.value.as_pointer, &e, 10);
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews if (*e != 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (result);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint16_tobuffer(covered, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* algorithm */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (token.value.as_ulong > 0xff)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (DNS_R_RANGE);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews c = token.value.as_ulong;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(mem_tobuffer(target, &c, 1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* labels */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (token.value.as_ulong > 0xff)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (DNS_R_RANGE);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews c = token.value.as_ulong;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(mem_tobuffer(target, &c, 1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* original ttl */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signature expiration */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(time_tobuffer(token.value.as_pointer, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* time signed */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(time_tobuffer(token.value.as_pointer, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* key footprint */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews buffer_fromregion(&buffer, &token.value.as_region,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews ISC_BUFFERTYPE_TEXT);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews origin = (origin != NULL) ? origin : dns_rootname;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* sig */
904294c0c952227f7778fd0ba2ccea08c097b872Mark Andrews return (base64_tobuffer(lexer, target, -1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewstotext_sig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_t sr;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews char buf[sizeof "4294967295"];
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdatatype_t covered;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long ttl;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long when;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long exp;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long foot;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t prefix;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_boolean_t sub;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata->type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews origin = origin; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata, &sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* type covered */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews covered = uint16_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_rdatatype_totext(covered, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* algorithm */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews sprintf(buf, "%u", sr.base[0]);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(buf, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* labels */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews sprintf(buf, "%u", sr.base[0]);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(buf, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* ttl */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews ttl = uint32_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 4);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews sprintf(buf, "%lu", ttl);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(buf, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* sig exp */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews exp = uint32_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 4);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(time_totext(exp, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* time signed */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews when = uint32_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 4);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(time_totext(when, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* footprint */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews foot = uint16_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews sprintf(buf, "%lu", ttl);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(buf, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&prefix, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_fromregion(&name, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_consume(&sr, name_length(&name));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews sub = name_prefix(&name, origin, &prefix);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_totext(&prefix, sub, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* sig */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (base64_totext(&sr, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsfromwire_sig(dns_rdataclass_t class, dns_rdatatype_t type,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *source, dns_decompress_t *dctx,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_boolean_t downcase, isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_t sr;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews class = class; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_active(source, &sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * type covered: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * algorithm: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * labels: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * original ttl: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * signature expiration: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * time signed: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * key footprint: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (sr.length < 18)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (DNS_R_UNEXPECTEDEND);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_forward(source, 18);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(mem_tobuffer(target, sr.base, 18));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* sig */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_active(source, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_buffer_forward(source, sr.length);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return(mem_tobuffer(target, sr.base, sr.length));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewstowire_sig(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_t sr;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata->type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata, &sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * type covered: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * algorithm: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * labels: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * original ttl: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * signature expiration: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * time signed: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * key footprint: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(mem_tobuffer(target, sr.base, 18));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 18);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_fromregion(&name, &sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, name_length(&name));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_towire(&name, cctx, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signature */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (mem_tobuffer(target, sr.base, sr.length));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic int
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewscompare_sig(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_t r1;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_t r2;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name1;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name2;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews int result;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata1->type == rdata2->type);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata1->class == rdata2->class);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata1->type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata1, &r1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata2, &r2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews INSIST(r1.length > 18);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews INSIST(r2.length > 18);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews r1.length = 18;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews r2.length = 18;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews result = compare_region(&r1, &r2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result != 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (result);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name1, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name2, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata1, &r1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdata_toregion(rdata2, &r2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&r1, 18);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&r2, 18);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_fromregion(&name1, &r1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_fromregion(&name2, &r2);
7c0539bea56022274da04263eb41fbb5b8835c38Mark Andrews result = dns_name_rdatacompare(&name1, &name2);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result != 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (result);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&r1, name_length(&name1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&r2, name_length(&name2));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (compare_region(&r1, &r2));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsfromstruct_sig(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews class = class; /*unused*/
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews source = source;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews target = target;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (DNS_R_NOTIMPLEMENTED);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic dns_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewstostruct_sig(dns_rdata_t *rdata, void *target) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata->type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews target = target;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (DNS_R_NOTIMPLEMENTED);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#endif /* RDATA_GENERIC_SIG_24_H */