cert_37.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 /* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
00021 
00022 /* RFC2538 */
00023 
00024 #ifndef RDATA_GENERIC_CERT_37_C
00025 #define RDATA_GENERIC_CERT_37_C
00026 
00027 #define RRTYPE_CERT_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_cert(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         dns_secalg_t secalg;
00033         dns_cert_t cert;
00034 
00035         REQUIRE(type == 37);
00036 
00037         UNUSED(type);
00038         UNUSED(rdclass);
00039         UNUSED(origin);
00040         UNUSED(options);
00041         UNUSED(callbacks);
00042 
00043         /*
00044          * Cert type.
00045          */
00046         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00047                                       ISC_FALSE));
00048         RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
00049         RETERR(uint16_tobuffer(cert, target));
00050 
00051         /*
00052          * Key tag.
00053          */
00054         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00055                                       ISC_FALSE));
00056         if (token.value.as_ulong > 0xffffU)
00057                 RETTOK(ISC_R_RANGE);
00058         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00059 
00060         /*
00061          * Algorithm.
00062          */
00063         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00064                                       ISC_FALSE));
00065         RETTOK(dns_secalg_fromtext(&secalg, &token.value.as_textregion));
00066         RETERR(mem_tobuffer(target, &secalg, 1));
00067 
00068         return (isc_base64_tobuffer(lexer, target, -1));
00069 }
00070 
00071 static inline isc_result_t
00072 totext_cert(ARGS_TOTEXT) {
00073         isc_region_t sr;
00074         char buf[sizeof("64000 ")];
00075         unsigned int n;
00076 
00077         REQUIRE(rdata->type == 37);
00078         REQUIRE(rdata->length != 0);
00079 
00080         UNUSED(tctx);
00081 
00082         dns_rdata_toregion(rdata, &sr);
00083 
00084         /*
00085          * Type.
00086          */
00087         n = uint16_fromregion(&sr);
00088         isc_region_consume(&sr, 2);
00089         RETERR(dns_cert_totext((dns_cert_t)n, target));
00090         RETERR(str_totext(" ", target));
00091 
00092         /*
00093          * Key tag.
00094          */
00095         n = uint16_fromregion(&sr);
00096         isc_region_consume(&sr, 2);
00097         sprintf(buf, "%u ", n);
00098         RETERR(str_totext(buf, target));
00099 
00100         /*
00101          * Algorithm.
00102          */
00103         RETERR(dns_secalg_totext(sr.base[0], target));
00104         isc_region_consume(&sr, 1);
00105 
00106         /*
00107          * Cert.
00108          */
00109         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00110                 RETERR(str_totext(" (", target));
00111         RETERR(str_totext(tctx->linebreak, target));
00112         if (tctx->width == 0)   /* No splitting */
00113                 RETERR(isc_base64_totext(&sr, 60, "", target));
00114         else
00115                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
00116                                          tctx->linebreak, target));
00117         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00118                 RETERR(str_totext(" )", target));
00119         return (ISC_R_SUCCESS);
00120 }
00121 
00122 static inline isc_result_t
00123 fromwire_cert(ARGS_FROMWIRE) {
00124         isc_region_t sr;
00125 
00126         REQUIRE(type == 37);
00127 
00128         UNUSED(type);
00129         UNUSED(rdclass);
00130         UNUSED(dctx);
00131         UNUSED(options);
00132 
00133         isc_buffer_activeregion(source, &sr);
00134         if (sr.length < 5)
00135                 return (ISC_R_UNEXPECTEDEND);
00136 
00137         isc_buffer_forward(source, sr.length);
00138         return (mem_tobuffer(target, sr.base, sr.length));
00139 }
00140 
00141 static inline isc_result_t
00142 towire_cert(ARGS_TOWIRE) {
00143         isc_region_t sr;
00144 
00145         REQUIRE(rdata->type == 37);
00146         REQUIRE(rdata->length != 0);
00147 
00148         UNUSED(cctx);
00149 
00150         dns_rdata_toregion(rdata, &sr);
00151         return (mem_tobuffer(target, sr.base, sr.length));
00152 }
00153 
00154 static inline int
00155 compare_cert(ARGS_COMPARE) {
00156         isc_region_t r1;
00157         isc_region_t r2;
00158 
00159         REQUIRE(rdata1->type == rdata2->type);
00160         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00161         REQUIRE(rdata1->type == 37);
00162         REQUIRE(rdata1->length != 0);
00163         REQUIRE(rdata2->length != 0);
00164 
00165         dns_rdata_toregion(rdata1, &r1);
00166         dns_rdata_toregion(rdata2, &r2);
00167         return (isc_region_compare(&r1, &r2));
00168 }
00169 
00170 static inline isc_result_t
00171 fromstruct_cert(ARGS_FROMSTRUCT) {
00172         dns_rdata_cert_t *cert = source;
00173 
00174         REQUIRE(type == 37);
00175         REQUIRE(source != NULL);
00176         REQUIRE(cert->common.rdtype == type);
00177         REQUIRE(cert->common.rdclass == rdclass);
00178 
00179         UNUSED(type);
00180         UNUSED(rdclass);
00181 
00182         RETERR(uint16_tobuffer(cert->type, target));
00183         RETERR(uint16_tobuffer(cert->key_tag, target));
00184         RETERR(uint8_tobuffer(cert->algorithm, target));
00185 
00186         return (mem_tobuffer(target, cert->certificate, cert->length));
00187 }
00188 
00189 static inline isc_result_t
00190 tostruct_cert(ARGS_TOSTRUCT) {
00191         dns_rdata_cert_t *cert = target;
00192         isc_region_t region;
00193 
00194         REQUIRE(rdata->type == 37);
00195         REQUIRE(target != NULL);
00196         REQUIRE(rdata->length != 0);
00197 
00198         cert->common.rdclass = rdata->rdclass;
00199         cert->common.rdtype = rdata->type;
00200         ISC_LINK_INIT(&cert->common, link);
00201 
00202         dns_rdata_toregion(rdata, &region);
00203 
00204         cert->type = uint16_fromregion(&region);
00205         isc_region_consume(&region, 2);
00206         cert->key_tag = uint16_fromregion(&region);
00207         isc_region_consume(&region, 2);
00208         cert->algorithm = uint8_fromregion(&region);
00209         isc_region_consume(&region, 1);
00210         cert->length = region.length;
00211 
00212         cert->certificate = mem_maybedup(mctx, region.base, region.length);
00213         if (cert->certificate == NULL)
00214                 return (ISC_R_NOMEMORY);
00215 
00216         cert->mctx = mctx;
00217         return (ISC_R_SUCCESS);
00218 }
00219 
00220 static inline void
00221 freestruct_cert(ARGS_FREESTRUCT) {
00222         dns_rdata_cert_t *cert = source;
00223 
00224         REQUIRE(cert != NULL);
00225         REQUIRE(cert->common.rdtype == 37);
00226 
00227         if (cert->mctx == NULL)
00228                 return;
00229 
00230         if (cert->certificate != NULL)
00231                 isc_mem_free(cert->mctx, cert->certificate);
00232         cert->mctx = NULL;
00233 }
00234 
00235 static inline isc_result_t
00236 additionaldata_cert(ARGS_ADDLDATA) {
00237         REQUIRE(rdata->type == 37);
00238 
00239         UNUSED(rdata);
00240         UNUSED(add);
00241         UNUSED(arg);
00242 
00243         return (ISC_R_SUCCESS);
00244 }
00245 
00246 static inline isc_result_t
00247 digest_cert(ARGS_DIGEST) {
00248         isc_region_t r;
00249 
00250         REQUIRE(rdata->type == 37);
00251 
00252         dns_rdata_toregion(rdata, &r);
00253 
00254         return ((digest)(arg, &r));
00255 }
00256 
00257 static inline isc_boolean_t
00258 checkowner_cert(ARGS_CHECKOWNER) {
00259 
00260         REQUIRE(type == 37);
00261 
00262         UNUSED(name);
00263         UNUSED(type);
00264         UNUSED(rdclass);
00265         UNUSED(wildcard);
00266 
00267         return (ISC_TRUE);
00268 }
00269 
00270 static inline isc_boolean_t
00271 checknames_cert(ARGS_CHECKNAMES) {
00272 
00273         REQUIRE(rdata->type == 37);
00274 
00275         UNUSED(rdata);
00276         UNUSED(owner);
00277         UNUSED(bad);
00278 
00279         return (ISC_TRUE);
00280 }
00281 
00282 
00283 static inline int
00284 casecompare_cert(ARGS_COMPARE) {
00285         return (compare_cert(rdata1, rdata2));
00286 }
00287 #endif  /* RDATA_GENERIC_CERT_37_C */

Generated on Tue Apr 28 17:40:59 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha