sig_24.c revision 7d32c065c7bb56f281651ae3dd2888f32ce4f1d9
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
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 * 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
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley /* $Id: sig_24.c,v 1.27 2000/02/03 23:43:06 halley Exp $ */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* RFC 2065 */
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromtext_sig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned char c;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* type covered */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews result = dns_rdatatype_fromtext(&covered, tsr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result != DNS_R_SUCCESS && result != DNS_R_NOTIMPLEMENTED) {
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence if (i < 0 || i > 65535)
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews if (*e != 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* algorithm */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(dns_secalg_fromtext(&c, &token.value.as_textregion));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* labels */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
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 /* signature expiration */
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 /* time signed */
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 /* 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 /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews 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));
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington return (isc_base64_tobuffer(lexer, target, -1));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssontotext_sig(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long ttl;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long when;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long exp;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned long foot;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* type covered */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* algorithm */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* labels */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* sig exp */
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* time signed */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* footprint */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&name, tctx->origin, &prefix);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(isc_base64_totext(&sr, tctx->width - 2,
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromwire_sig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * type covered: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * algorithm: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * original ttl: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * signature expiration: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * time signed: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * key footprint: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return(mem_tobuffer(target, sr.base, sr.length));
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewstowire_sig(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * type covered: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * algorithm: 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * original ttl: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * signature expiration: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * time signed: 4
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * key footprint: 2
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signer */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /* signature */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (mem_tobuffer(target, sr.base, sr.length));
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline int
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewscompare_sig(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
7c0539bea56022274da04263eb41fbb5b8835c38Mark Andrews result = dns_name_rdatacompare(&name1, &name2);
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyfromstruct_sig(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Type covered */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint16_tobuffer(sig->covered, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Algorithm */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint8_tobuffer(sig->algorithm, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint8_tobuffer(sig->labels, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Original TTL */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->originalttl, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Expire time */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->timeexpire, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Time signed */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint32_tobuffer(sig->timesigned, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(uint16_tobuffer(sig->keyid, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Signer name */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington RETERR(dns_compress_init(&cctx, -1, sig->mctx));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(dns_name_towire(&sig->signer, &cctx, target));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Signature */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington memcpy(tr.base, sig->signature, sig->siglen);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewstostruct_sig(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Type covered */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Algorithm */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Original TTL */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Expire time */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Time signed */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(dns_name_dup(&signer, mctx, &sig->signer));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, name_length(&sig->signer));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /* Signature */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington sig->signature = isc_mem_get(mctx, sig->siglen);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington memcpy(sig->signature, sr.base, sig->siglen);
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline void
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dns_rdata_generic_sig_t *sig = (dns_rdata_generic_sig_t *) source;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_mem_put(sig->mctx, sig->signature, sig->siglen);
d981ca645597116d227a48bf37cc5edc061c854dBob Halleyadditionaldata_sig(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleydigest_sig(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#endif /* RDATA_GENERIC_SIG_24_C */