1999-02-01 20:19:22 -05:00
|
|
|
/*
|
2001-01-09 17:01:04 -05:00
|
|
|
* Copyright (C) 1999-2001 Internet Software Consortium.
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
1999-02-01 20:19:22 -05:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
2000-07-27 05:55:03 -04:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-02-01 20:19:22 -05:00
|
|
|
*/
|
|
|
|
|
|
2003-09-10 20:18:18 -04:00
|
|
|
/* $Id: cert_37.c,v 1.40.2.1.2.2 2003/09/11 00:18:09 marka Exp $ */
|
2000-03-15 21:15:52 -05:00
|
|
|
|
|
|
|
|
/* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-03-15 20:43:42 -05:00
|
|
|
/* RFC 2538 */
|
1999-02-01 20:19:22 -05:00
|
|
|
|
1999-05-04 20:19:04 -04:00
|
|
|
#ifndef RDATA_GENERIC_CERT_37_C
|
|
|
|
|
#define RDATA_GENERIC_CERT_37_C
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-04-06 23:54:52 -04:00
|
|
|
#define RRTYPE_CERT_ATTRIBUTES (0)
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
fromtext_cert(ARGS_FROMTEXT) {
|
1999-02-01 20:19:22 -05:00
|
|
|
isc_token_t token;
|
1999-02-04 19:05:46 -05:00
|
|
|
dns_secalg_t secalg;
|
|
|
|
|
dns_cert_t cert;
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
REQUIRE(type == 37);
|
|
|
|
|
|
2001-03-16 17:53:20 -05:00
|
|
|
UNUSED(type);
|
2000-03-15 20:43:42 -05:00
|
|
|
UNUSED(rdclass);
|
|
|
|
|
UNUSED(origin);
|
|
|
|
|
UNUSED(downcase);
|
2001-07-15 23:06:53 -04:00
|
|
|
UNUSED(callbacks);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Cert type.
|
|
|
|
|
*/
|
2000-11-07 20:56:15 -05:00
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
|
|
|
|
|
ISC_FALSE));
|
2001-03-06 17:11:18 -05:00
|
|
|
RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
|
1999-02-04 19:05:46 -05:00
|
|
|
RETERR(uint16_tobuffer(cert, target));
|
2000-07-31 21:33:37 -04:00
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Key tag.
|
|
|
|
|
*/
|
2000-11-07 20:56:15 -05:00
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
|
|
|
|
|
ISC_FALSE));
|
2003-07-23 02:57:59 -04:00
|
|
|
if (token.value.as_ulong > 0xffffU)
|
2001-03-06 17:11:18 -05:00
|
|
|
RETTOK(ISC_R_RANGE);
|
1999-02-01 20:19:22 -05:00
|
|
|
RETERR(uint16_tobuffer(token.value.as_ulong, target));
|
|
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Algorithm.
|
|
|
|
|
*/
|
2000-11-07 20:56:15 -05:00
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
|
|
|
|
|
ISC_FALSE));
|
2001-03-06 17:11:18 -05:00
|
|
|
RETTOK(dns_secalg_fromtext(&secalg, &token.value.as_textregion));
|
1999-02-04 19:05:46 -05:00
|
|
|
RETERR(mem_tobuffer(target, &secalg, 1));
|
1999-02-01 20:19:22 -05:00
|
|
|
|
1999-05-18 13:46:59 -04:00
|
|
|
return (isc_base64_tobuffer(lexer, target, -1));
|
1999-02-01 20:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
totext_cert(ARGS_TOTEXT) {
|
1999-02-01 20:19:22 -05:00
|
|
|
isc_region_t sr;
|
2003-09-10 20:18:18 -04:00
|
|
|
char buf[sizeof("64000 ")];
|
1999-02-01 20:19:22 -05:00
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == 37);
|
2000-10-25 01:44:10 -04:00
|
|
|
REQUIRE(rdata->length != 0);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-03-15 20:43:42 -05:00
|
|
|
UNUSED(tctx);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &sr);
|
|
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Type.
|
|
|
|
|
*/
|
1999-02-01 20:19:22 -05:00
|
|
|
n = uint16_fromregion(&sr);
|
|
|
|
|
isc_region_consume(&sr, 2);
|
1999-10-08 17:22:27 -04:00
|
|
|
RETERR(dns_cert_totext((dns_cert_t)n, target));
|
1999-02-01 20:19:22 -05:00
|
|
|
RETERR(str_totext(" ", target));
|
|
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Key tag.
|
|
|
|
|
*/
|
1999-02-01 20:19:22 -05:00
|
|
|
n = uint16_fromregion(&sr);
|
|
|
|
|
isc_region_consume(&sr, 2);
|
1999-02-16 17:42:33 -05:00
|
|
|
sprintf(buf, "%u ", n);
|
1999-02-01 20:19:22 -05:00
|
|
|
RETERR(str_totext(buf, target));
|
|
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Algorithm.
|
|
|
|
|
*/
|
1999-02-04 19:05:46 -05:00
|
|
|
RETERR(dns_secalg_totext(sr.base[0], target));
|
|
|
|
|
isc_region_consume(&sr, 1);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-05-15 17:14:38 -04:00
|
|
|
/*
|
|
|
|
|
* Cert.
|
|
|
|
|
*/
|
1999-06-08 16:41:31 -04:00
|
|
|
if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
|
|
|
|
|
RETERR(str_totext(" (", target));
|
1999-06-08 06:35:23 -04:00
|
|
|
RETERR(str_totext(tctx->linebreak, target));
|
2000-03-15 20:43:42 -05:00
|
|
|
RETERR(isc_base64_totext(&sr, tctx->width - 2,
|
1999-06-08 06:35:23 -04:00
|
|
|
tctx->linebreak, target));
|
1999-06-08 16:41:31 -04:00
|
|
|
if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
|
|
|
|
|
RETERR(str_totext(" )", target));
|
2000-04-06 18:03:35 -04:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-02-01 20:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
fromwire_cert(ARGS_FROMWIRE) {
|
1999-02-01 20:19:22 -05:00
|
|
|
isc_region_t sr;
|
|
|
|
|
|
|
|
|
|
REQUIRE(type == 37);
|
2000-07-31 21:33:37 -04:00
|
|
|
|
2001-03-16 17:53:20 -05:00
|
|
|
UNUSED(type);
|
2000-03-15 20:43:42 -05:00
|
|
|
UNUSED(rdclass);
|
|
|
|
|
UNUSED(dctx);
|
|
|
|
|
UNUSED(downcase);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_activeregion(source, &sr);
|
1999-02-01 20:19:22 -05:00
|
|
|
if (sr.length < 5)
|
2000-04-06 18:03:35 -04:00
|
|
|
return (ISC_R_UNEXPECTEDEND);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
isc_buffer_forward(source, sr.length);
|
|
|
|
|
return (mem_tobuffer(target, sr.base, sr.length));
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
towire_cert(ARGS_TOWIRE) {
|
1999-02-01 20:19:22 -05:00
|
|
|
isc_region_t sr;
|
|
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == 37);
|
2000-10-25 01:44:10 -04:00
|
|
|
REQUIRE(rdata->length != 0);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-03-15 20:43:42 -05:00
|
|
|
UNUSED(cctx);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &sr);
|
|
|
|
|
return (mem_tobuffer(target, sr.base, sr.length));
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-11 21:32:42 -04:00
|
|
|
static inline int
|
2000-06-01 14:26:56 -04:00
|
|
|
compare_cert(ARGS_COMPARE) {
|
1999-02-01 20:19:22 -05:00
|
|
|
isc_region_t r1;
|
|
|
|
|
isc_region_t r2;
|
|
|
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
1999-08-02 18:18:31 -04:00
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
1999-02-01 20:19:22 -05:00
|
|
|
REQUIRE(rdata1->type == 37);
|
2000-10-25 01:44:10 -04:00
|
|
|
REQUIRE(rdata1->length != 0);
|
|
|
|
|
REQUIRE(rdata2->length != 0);
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, &r1);
|
|
|
|
|
dns_rdata_toregion(rdata2, &r2);
|
2003-08-12 10:16:17 -04:00
|
|
|
return (isc_region_compare(&r1, &r2));
|
1999-02-01 20:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
fromstruct_cert(ARGS_FROMSTRUCT) {
|
2000-05-22 08:38:12 -04:00
|
|
|
dns_rdata_cert_t *cert = source;
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
REQUIRE(type == 37);
|
2000-05-22 08:38:12 -04:00
|
|
|
REQUIRE(source != NULL);
|
|
|
|
|
REQUIRE(cert->common.rdtype == type);
|
|
|
|
|
REQUIRE(cert->common.rdclass == rdclass);
|
2000-07-31 21:33:37 -04:00
|
|
|
|
2001-03-16 17:53:20 -05:00
|
|
|
UNUSED(type);
|
2000-11-30 20:40:59 -05:00
|
|
|
UNUSED(rdclass);
|
|
|
|
|
|
2000-05-22 08:38:12 -04:00
|
|
|
RETERR(uint16_tobuffer(cert->type, target));
|
|
|
|
|
RETERR(uint16_tobuffer(cert->key_tag, target));
|
|
|
|
|
RETERR(uint8_tobuffer(cert->algorithm, target));
|
1999-02-01 20:19:22 -05:00
|
|
|
|
2000-05-22 08:38:12 -04:00
|
|
|
return (mem_tobuffer(target, cert->certificate, cert->length));
|
1999-02-01 20:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
tostruct_cert(ARGS_TOSTRUCT) {
|
2000-05-05 01:50:14 -04:00
|
|
|
dns_rdata_cert_t *cert = target;
|
|
|
|
|
isc_region_t region;
|
1999-02-01 20:19:22 -05:00
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == 37);
|
2000-05-18 22:02:11 -04:00
|
|
|
REQUIRE(target != NULL);
|
2000-10-25 01:44:10 -04:00
|
|
|
REQUIRE(rdata->length != 0);
|
2000-04-27 21:24:18 -04:00
|
|
|
|
2000-05-05 01:50:14 -04:00
|
|
|
cert->common.rdclass = rdata->rdclass;
|
|
|
|
|
cert->common.rdtype = rdata->type;
|
|
|
|
|
ISC_LINK_INIT(&cert->common, link);
|
|
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
|
|
|
|
|
|
cert->type = uint16_fromregion(®ion);
|
|
|
|
|
isc_region_consume(®ion, 2);
|
|
|
|
|
cert->key_tag = uint16_fromregion(®ion);
|
|
|
|
|
isc_region_consume(®ion, 2);
|
|
|
|
|
cert->algorithm = uint8_fromregion(®ion);
|
|
|
|
|
isc_region_consume(®ion, 1);
|
|
|
|
|
cert->length = region.length;
|
|
|
|
|
|
2001-06-21 00:00:47 -04:00
|
|
|
cert->certificate = mem_maybedup(mctx, region.base, region.length);
|
|
|
|
|
if (cert->certificate == NULL)
|
|
|
|
|
return (ISC_R_NOMEMORY);
|
2000-05-05 01:50:14 -04:00
|
|
|
|
|
|
|
|
cert->mctx = mctx;
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-02-01 20:19:22 -05:00
|
|
|
}
|
1999-05-06 23:24:15 -04:00
|
|
|
|
1999-08-11 21:32:42 -04:00
|
|
|
static inline void
|
2000-06-01 14:26:56 -04:00
|
|
|
freestruct_cert(ARGS_FREESTRUCT) {
|
|
|
|
|
dns_rdata_cert_t *cert = source;
|
2000-05-05 01:50:14 -04:00
|
|
|
|
2000-06-01 14:26:56 -04:00
|
|
|
REQUIRE(cert != NULL);
|
2000-05-05 01:50:14 -04:00
|
|
|
REQUIRE(cert->common.rdtype == 37);
|
2000-04-27 21:24:18 -04:00
|
|
|
|
2000-05-05 01:50:14 -04:00
|
|
|
if (cert->mctx == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cert->certificate != NULL)
|
|
|
|
|
isc_mem_free(cert->mctx, cert->certificate);
|
|
|
|
|
cert->mctx = NULL;
|
1999-05-06 23:24:15 -04:00
|
|
|
}
|
1999-08-02 18:18:31 -04:00
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
additionaldata_cert(ARGS_ADDLDATA) {
|
1999-08-02 18:18:31 -04:00
|
|
|
REQUIRE(rdata->type == 37);
|
|
|
|
|
|
2000-04-27 21:24:18 -04:00
|
|
|
UNUSED(rdata);
|
2000-03-15 20:43:42 -05:00
|
|
|
UNUSED(add);
|
|
|
|
|
UNUSED(arg);
|
1999-08-02 18:18:31 -04:00
|
|
|
|
2000-04-06 18:03:35 -04:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-08-02 18:18:31 -04:00
|
|
|
}
|
|
|
|
|
|
1999-12-22 19:09:04 -05:00
|
|
|
static inline isc_result_t
|
2000-06-01 14:26:56 -04:00
|
|
|
digest_cert(ARGS_DIGEST) {
|
1999-08-31 18:05:55 -04:00
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == 37);
|
|
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &r);
|
|
|
|
|
|
|
|
|
|
return ((digest)(arg, &r));
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-04 20:19:04 -04:00
|
|
|
#endif /* RDATA_GENERIC_CERT_37_C */
|