sig_24.c revision 1bb227b988b8170cbb1a2fcf43b19a3ec57423ad
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff *
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.
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff *
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
1bb227b988b8170cbb1a2fcf43b19a3ec57423adMark Andrews/* $Id: sig_24.c,v 1.40 2000/05/19 02:03:56 marka Exp $ */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson/* Reviewed: Fri Mar 17 09:05:02 PST 2000 by gson */
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson/* RFC 2535 */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#ifndef RDATA_GENERIC_SIG_24_C
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#define RDATA_GENERIC_SIG_24_C
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#define RRTYPE_SIG_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromtext_sig(dns_rdataclass_t rdclass, 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;
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence long i;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_rdatatype_t covered;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews char *e;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_t name;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_t buffer;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_uint32_t time_signed, time_expire;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(rdclass);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Type covered.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson result = dns_rdatatype_fromtext(&covered, &token.value.as_textregion);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) {
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence i = strtol(token.value.as_pointer, &e, 10);
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence if (i < 0 || i > 65535)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews if (*e != 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (result);
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence covered = (dns_rdatatype_t)i;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint16_tobuffer(covered, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Algorithm.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(dns_secalg_fromtext(&c, &token.value.as_textregion));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(mem_tobuffer(target, &c, 1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Labels.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (token.value.as_ulong > 0xff)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
ea8651059209b96fa005e06a0b9b33ae5a8eacd4David Lawrence c = (unsigned char)token.value.as_ulong;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(mem_tobuffer(target, &c, 1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Original ttl.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signature expiration.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_time32_fromtext(token.value.as_pointer, &time_expire));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(uint32_tobuffer(time_expire, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Time signed.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_time32_fromtext(token.value.as_pointer, &time_signed));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(uint32_tobuffer(time_signed, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Key footprint.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signer.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence buffer_fromregion(&buffer, &token.value.as_region);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews origin = (origin != NULL) ? origin : dns_rootname;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Sig.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington return (isc_base64_tobuffer(lexer, target, -1));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssontotext_sig(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_t *target)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson{
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 dns_rdata_toregion(rdata, &sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Type covered.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Algorithm.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Labels.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Ttl.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Sig exp.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews exp = uint32_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 4);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_time32_totext(exp, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson RETERR(str_totext(" (", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Time signed.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews when = uint32_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 4);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_time32_totext(when, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Footprint.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews foot = uint16_fromregion(&sr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_region_consume(&sr, 2);
b5da378f2987a115491c291d062252f3152d8db8Brian Wellington sprintf(buf, "%lu", foot);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(buf, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(str_totext(" ", target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signer.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&name, tctx->origin, &prefix);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_totext(&prefix, sub, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Sig.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(isc_base64_totext(&sr, tctx->width - 2,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson tctx->linebreak, target));
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson RETERR(str_totext(" )", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromwire_sig(dns_rdataclass_t rdclass, 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);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(rdclass);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(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)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_forward(source, 18);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(mem_tobuffer(target, sr.base, 18));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signer.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_name_init(&name, NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Sig.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_buffer_forward(source, sr.length);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson return (mem_tobuffer(target, sr.base, sr.length));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_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
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signer.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
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
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signature.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (mem_tobuffer(target, sr.base, sr.length));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline 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;
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson int order;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata1->type == rdata2->type);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata1->rdclass == rdata2->rdclass);
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;
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson order = compare_region(&r1, &r2);
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson if (order != 0)
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson return (order);
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);
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson order = dns_name_rdatacompare(&name1, &name2);
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson if (order != 0)
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson return (order);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson
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
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromstruct_sig(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_t tr;
b8dd48ecf83142f6ee7238cbd68fec455e527fc8Mark Andrews dns_rdata_sig_t *sig;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(type == 24);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(rdclass);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson sig = (dns_rdata_sig_t *)source;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Type covered.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint16_tobuffer(sig->covered, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Algorithm.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint8_tobuffer(sig->algorithm, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Labels.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint8_tobuffer(sig->labels, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Original TTL.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->originalttl, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Expire time.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->timeexpire, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Time signed.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->timesigned, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Key ID.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint16_tobuffer(sig->keyid, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signer name.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson RETERR(name_tobuffer(&sig->signer, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signature.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (sig->siglen > 0) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (tr.length < sig->siglen)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington memcpy(tr.base, sig->signature, sig->siglen);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_buffer_add(target, sig->siglen);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewstostruct_sig(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_t sr;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_rdata_sig_t *sig = target;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_name_t signer;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(rdata->type == 24);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews REQUIRE(target != NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->common.rdclass = rdata->rdclass;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->common.rdtype = rdata->type;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ISC_LINK_INIT(&sig->common, link);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_rdata_toregion(rdata, &sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Type covered.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->covered = uint16_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 2);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Algorithm.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->algorithm = uint8_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 1);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Labels.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->labels = uint8_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 1);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Original TTL.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->originalttl = uint32_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 4);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Expire time.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->timeexpire = uint32_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 4);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Time signed.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->timesigned = uint32_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 4);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Key ID.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->keyid = uint16_fromregion(&sr);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_region_consume(&sr, 2);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_name_init(&signer, NULL);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_name_fromregion(&signer, &sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_init(&sig->signer, NULL);
1bb227b988b8170cbb1a2fcf43b19a3ec57423adMark Andrews RETERR(name_duporclone(&signer, mctx, &sig->signer));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, name_length(&sig->signer));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Signature.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
b5da378f2987a115491c291d062252f3152d8db8Brian Wellington sig->siglen = sr.length;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (sig->siglen > 0) {
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews sig->signature = mem_maybedup(mctx, sr.base, sig->siglen);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (sig->signature == NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews goto cleanup;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews } else
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews sig->signature = NULL;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews sig->mctx = mctx;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews cleanup:
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (mctx != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_name_free(&sig->signer, mctx);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return (ISC_R_NOMEMORY);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline void
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsfreestruct_sig(void *source) {
b8dd48ecf83142f6ee7238cbd68fec455e527fc8Mark Andrews dns_rdata_sig_t *sig = (dns_rdata_sig_t *) source;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(source != NULL);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington REQUIRE(sig->common.rdtype == 24);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (sig->mctx == NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_free(&sig->signer, sig->mctx);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson if (sig->signature != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_mem_free(sig->mctx, sig->signature);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews sig->mctx = NULL;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyadditionaldata_sig(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley void *arg)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley{
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata->type == 24);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(add);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(arg);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleydigest_sig(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley REQUIRE(rdata->type == 24);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(digest);
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson UNUSED(arg);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOTIMPLEMENTED);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley}
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleystatic inline dns_rdatatype_t
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleycovers_sig(dns_rdata_t *rdata) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_rdatatype_t type;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_t r;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley REQUIRE(rdata->type == 24);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_rdata_toregion(rdata, &r);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley type = uint16_fromregion(&r);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley return (type);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley}
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#endif /* RDATA_GENERIC_SIG_24_C */