keydata_65533.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009, 2011-2013, 2015  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #ifndef GENERIC_KEYDATA_65533_C
00018 #define GENERIC_KEYDATA_65533_C 1
00019 
00020 #include <isc/time.h>
00021 #include <isc/stdtime.h>
00022 
00023 #include <dst/dst.h>
00024 
00025 #define RRTYPE_KEYDATA_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_keydata(ARGS_FROMTEXT) {
00029         isc_result_t result;
00030         isc_token_t token;
00031         dns_secalg_t alg;
00032         dns_secproto_t proto;
00033         dns_keyflags_t flags;
00034         isc_uint32_t refresh, addhd, removehd;
00035 
00036         REQUIRE(type == 65533);
00037 
00038         UNUSED(type);
00039         UNUSED(rdclass);
00040         UNUSED(origin);
00041         UNUSED(options);
00042         UNUSED(callbacks);
00043 
00044         /* refresh timer */
00045         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00046                                       ISC_FALSE));
00047         RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &refresh));
00048         RETERR(uint32_tobuffer(refresh, target));
00049 
00050         /* add hold-down */
00051         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00052                                       ISC_FALSE));
00053         RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &addhd));
00054         RETERR(uint32_tobuffer(addhd, target));
00055 
00056         /* remove hold-down */
00057         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00058                                       ISC_FALSE));
00059         RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &removehd));
00060         RETERR(uint32_tobuffer(removehd, target));
00061 
00062         /* flags */
00063         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00064                                       ISC_FALSE));
00065         RETTOK(dns_keyflags_fromtext(&flags, &token.value.as_textregion));
00066         RETERR(uint16_tobuffer(flags, target));
00067 
00068         /* protocol */
00069         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00070                                       ISC_FALSE));
00071         RETTOK(dns_secproto_fromtext(&proto, &token.value.as_textregion));
00072         RETERR(mem_tobuffer(target, &proto, 1));
00073 
00074         /* algorithm */
00075         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00076                                       ISC_FALSE));
00077         RETTOK(dns_secalg_fromtext(&alg, &token.value.as_textregion));
00078         RETERR(mem_tobuffer(target, &alg, 1));
00079 
00080         /* No Key? */
00081         if ((flags & 0xc000) == 0xc000)
00082                 return (ISC_R_SUCCESS);
00083 
00084         result = isc_base64_tobuffer(lexer, target, -1);
00085         if (result != ISC_R_SUCCESS)
00086                 return (result);
00087 
00088         /* Ensure there's at least enough data to compute a key ID for MD5 */
00089         if (alg == DST_ALG_RSAMD5 && isc_buffer_usedlength(target) < 19)
00090                 return (ISC_R_UNEXPECTEDEND);
00091 
00092         return (ISC_R_SUCCESS);
00093 }
00094 
00095 static inline isc_result_t
00096 totext_keydata(ARGS_TOTEXT) {
00097         isc_region_t sr;
00098         char buf[sizeof("64000")];
00099         unsigned int flags;
00100         unsigned char algorithm;
00101         unsigned long refresh, add, delete;
00102         char algbuf[DNS_NAME_FORMATSIZE];
00103         const char *keyinfo;
00104 
00105         REQUIRE(rdata->type == 65533);
00106 
00107         if ((tctx->flags & DNS_STYLEFLAG_KEYDATA) == 0 || rdata->length < 16)
00108                 return (unknown_totext(rdata, tctx, target));
00109 
00110         dns_rdata_toregion(rdata, &sr);
00111 
00112         /* refresh timer */
00113         refresh = uint32_fromregion(&sr);
00114         isc_region_consume(&sr, 4);
00115         RETERR(dns_time32_totext(refresh, target));
00116         RETERR(str_totext(" ", target));
00117 
00118         /* add hold-down */
00119         add = uint32_fromregion(&sr);
00120         isc_region_consume(&sr, 4);
00121         RETERR(dns_time32_totext(add, target));
00122         RETERR(str_totext(" ", target));
00123 
00124         /* remove hold-down */
00125         delete = uint32_fromregion(&sr);
00126         isc_region_consume(&sr, 4);
00127         RETERR(dns_time32_totext(delete, target));
00128         RETERR(str_totext(" ", target));
00129 
00130         /* flags */
00131         flags = uint16_fromregion(&sr);
00132         isc_region_consume(&sr, 2);
00133         sprintf(buf, "%u", flags);
00134         RETERR(str_totext(buf, target));
00135         RETERR(str_totext(" ", target));
00136         if ((flags & DNS_KEYFLAG_KSK) != 0) {
00137                 if (flags & DNS_KEYFLAG_REVOKE)
00138                         keyinfo = "revoked KSK";
00139                 else
00140                         keyinfo = "KSK";
00141         } else
00142                 keyinfo = "ZSK";
00143 
00144         /* protocol */
00145         sprintf(buf, "%u", sr.base[0]);
00146         isc_region_consume(&sr, 1);
00147         RETERR(str_totext(buf, target));
00148         RETERR(str_totext(" ", target));
00149 
00150         /* algorithm */
00151         algorithm = sr.base[0];
00152         sprintf(buf, "%u", algorithm);
00153         isc_region_consume(&sr, 1);
00154         RETERR(str_totext(buf, target));
00155 
00156         /* No Key? */
00157         if ((flags & 0xc000) == 0xc000)
00158                 return (ISC_R_SUCCESS);
00159 
00160         /* key */
00161         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00162                 RETERR(str_totext(" (", target));
00163         RETERR(str_totext(tctx->linebreak, target));
00164         if (tctx->width == 0)   /* No splitting */
00165                 RETERR(isc_base64_totext(&sr, 60, "", target));
00166         else
00167                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
00168                                          tctx->linebreak, target));
00169 
00170         if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0)
00171                 RETERR(str_totext(tctx->linebreak, target));
00172         else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00173                 RETERR(str_totext(" ", target));
00174 
00175         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00176                 RETERR(str_totext(")", target));
00177 
00178         if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) {
00179                 isc_region_t tmpr;
00180                 char rbuf[ISC_FORMATHTTPTIMESTAMP_SIZE];
00181                 char abuf[ISC_FORMATHTTPTIMESTAMP_SIZE];
00182                 char dbuf[ISC_FORMATHTTPTIMESTAMP_SIZE];
00183                 isc_time_t t;
00184 
00185                 RETERR(str_totext(" ; ", target));
00186                 RETERR(str_totext(keyinfo, target));
00187                 dns_secalg_format((dns_secalg_t) algorithm, algbuf,
00188                                   sizeof(algbuf));
00189                 RETERR(str_totext("; alg = ", target));
00190                 RETERR(str_totext(algbuf, target));
00191                 RETERR(str_totext("; key id = ", target));
00192                 dns_rdata_toregion(rdata, &tmpr);
00193                 /* Skip over refresh, addhd, and removehd */
00194                 isc_region_consume(&tmpr, 12);
00195                 sprintf(buf, "%u", dst_region_computeid(&tmpr, algorithm));
00196                 RETERR(str_totext(buf, target));
00197 
00198                 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
00199                         isc_stdtime_t now;
00200 
00201                         isc_stdtime_get(&now);
00202 
00203                         RETERR(str_totext(tctx->linebreak, target));
00204                         RETERR(str_totext("; next refresh: ", target));
00205                         isc_time_set(&t, refresh, 0);
00206                         isc_time_formathttptimestamp(&t, rbuf, sizeof(rbuf));
00207                         RETERR(str_totext(rbuf, target));
00208 
00209                         if (add == 0U) {
00210                                 RETERR(str_totext(tctx->linebreak, target));
00211                                 RETERR(str_totext("; no trust", target));
00212                         } else {
00213                                 RETERR(str_totext(tctx->linebreak, target));
00214                                 if (add < now) {
00215                                         RETERR(str_totext("; trusted since: ",
00216                                                           target));
00217                                 } else {
00218                                         RETERR(str_totext("; trust pending: ",
00219                                                           target));
00220                                 }
00221                                 isc_time_set(&t, add, 0);
00222                                 isc_time_formathttptimestamp(&t, abuf,
00223                                                              sizeof(abuf));
00224                                 RETERR(str_totext(abuf, target));
00225                         }
00226 
00227                         if (delete != 0U) {
00228                                 RETERR(str_totext(tctx->linebreak, target));
00229                                 RETERR(str_totext("; removal pending: ",
00230                                                   target));
00231                                 isc_time_set(&t, delete, 0);
00232                                 isc_time_formathttptimestamp(&t, dbuf,
00233                                                              sizeof(dbuf));
00234                                 RETERR(str_totext(dbuf, target));
00235                         }
00236                 }
00237 
00238         }
00239         return (ISC_R_SUCCESS);
00240 }
00241 
00242 static inline isc_result_t
00243 fromwire_keydata(ARGS_FROMWIRE) {
00244         isc_region_t sr;
00245 
00246         REQUIRE(type == 65533);
00247 
00248         UNUSED(type);
00249         UNUSED(rdclass);
00250         UNUSED(dctx);
00251         UNUSED(options);
00252 
00253         isc_buffer_activeregion(source, &sr);
00254         isc_buffer_forward(source, sr.length);
00255         return (mem_tobuffer(target, sr.base, sr.length));
00256 }
00257 
00258 static inline isc_result_t
00259 towire_keydata(ARGS_TOWIRE) {
00260         isc_region_t sr;
00261 
00262         REQUIRE(rdata->type == 65533);
00263 
00264         UNUSED(cctx);
00265 
00266         dns_rdata_toregion(rdata, &sr);
00267         return (mem_tobuffer(target, sr.base, sr.length));
00268 }
00269 
00270 static inline int
00271 compare_keydata(ARGS_COMPARE) {
00272         isc_region_t r1;
00273         isc_region_t r2;
00274 
00275         REQUIRE(rdata1->type == rdata2->type);
00276         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00277         REQUIRE(rdata1->type == 65533);
00278 
00279         dns_rdata_toregion(rdata1, &r1);
00280         dns_rdata_toregion(rdata2, &r2);
00281         return (isc_region_compare(&r1, &r2));
00282 }
00283 
00284 static inline isc_result_t
00285 fromstruct_keydata(ARGS_FROMSTRUCT) {
00286         dns_rdata_keydata_t *keydata = source;
00287 
00288         REQUIRE(type == 65533);
00289         REQUIRE(source != NULL);
00290         REQUIRE(keydata->common.rdtype == type);
00291         REQUIRE(keydata->common.rdclass == rdclass);
00292 
00293         UNUSED(type);
00294         UNUSED(rdclass);
00295 
00296         /* Refresh timer */
00297         RETERR(uint32_tobuffer(keydata->refresh, target));
00298 
00299         /* Add hold-down */
00300         RETERR(uint32_tobuffer(keydata->addhd, target));
00301 
00302         /* Remove hold-down */
00303         RETERR(uint32_tobuffer(keydata->removehd, target));
00304 
00305         /* Flags */
00306         RETERR(uint16_tobuffer(keydata->flags, target));
00307 
00308         /* Protocol */
00309         RETERR(uint8_tobuffer(keydata->protocol, target));
00310 
00311         /* Algorithm */
00312         RETERR(uint8_tobuffer(keydata->algorithm, target));
00313 
00314         /* Data */
00315         return (mem_tobuffer(target, keydata->data, keydata->datalen));
00316 }
00317 
00318 static inline isc_result_t
00319 tostruct_keydata(ARGS_TOSTRUCT) {
00320         dns_rdata_keydata_t *keydata = target;
00321         isc_region_t sr;
00322 
00323         REQUIRE(rdata->type == 65533);
00324         REQUIRE(target != NULL);
00325 
00326         keydata->common.rdclass = rdata->rdclass;
00327         keydata->common.rdtype = rdata->type;
00328         ISC_LINK_INIT(&keydata->common, link);
00329 
00330         dns_rdata_toregion(rdata, &sr);
00331 
00332         /* Refresh timer */
00333         if (sr.length < 4)
00334                 return (ISC_R_UNEXPECTEDEND);
00335         keydata->refresh = uint32_fromregion(&sr);
00336         isc_region_consume(&sr, 4);
00337 
00338         /* Add hold-down */
00339         if (sr.length < 4)
00340                 return (ISC_R_UNEXPECTEDEND);
00341         keydata->addhd = uint32_fromregion(&sr);
00342         isc_region_consume(&sr, 4);
00343 
00344         /* Remove hold-down */
00345         if (sr.length < 4)
00346                 return (ISC_R_UNEXPECTEDEND);
00347         keydata->removehd = uint32_fromregion(&sr);
00348         isc_region_consume(&sr, 4);
00349 
00350         /* Flags */
00351         if (sr.length < 2)
00352                 return (ISC_R_UNEXPECTEDEND);
00353         keydata->flags = uint16_fromregion(&sr);
00354         isc_region_consume(&sr, 2);
00355 
00356         /* Protocol */
00357         if (sr.length < 1)
00358                 return (ISC_R_UNEXPECTEDEND);
00359         keydata->protocol = uint8_fromregion(&sr);
00360         isc_region_consume(&sr, 1);
00361 
00362         /* Algorithm */
00363         if (sr.length < 1)
00364                 return (ISC_R_UNEXPECTEDEND);
00365         keydata->algorithm = uint8_fromregion(&sr);
00366         isc_region_consume(&sr, 1);
00367 
00368         /* Data */
00369         keydata->datalen = sr.length;
00370         keydata->data = mem_maybedup(mctx, sr.base, keydata->datalen);
00371         if (keydata->data == NULL)
00372                 return (ISC_R_NOMEMORY);
00373 
00374         keydata->mctx = mctx;
00375         return (ISC_R_SUCCESS);
00376 }
00377 
00378 static inline void
00379 freestruct_keydata(ARGS_FREESTRUCT) {
00380         dns_rdata_keydata_t *keydata = (dns_rdata_keydata_t *) source;
00381 
00382         REQUIRE(source != NULL);
00383         REQUIRE(keydata->common.rdtype == 65533);
00384 
00385         if (keydata->mctx == NULL)
00386                 return;
00387 
00388         if (keydata->data != NULL)
00389                 isc_mem_free(keydata->mctx, keydata->data);
00390         keydata->mctx = NULL;
00391 }
00392 
00393 static inline isc_result_t
00394 additionaldata_keydata(ARGS_ADDLDATA) {
00395         REQUIRE(rdata->type == 65533);
00396 
00397         UNUSED(rdata);
00398         UNUSED(add);
00399         UNUSED(arg);
00400 
00401         return (ISC_R_SUCCESS);
00402 }
00403 
00404 static inline isc_result_t
00405 digest_keydata(ARGS_DIGEST) {
00406         isc_region_t r;
00407 
00408         REQUIRE(rdata->type == 65533);
00409 
00410         dns_rdata_toregion(rdata, &r);
00411 
00412         return ((digest)(arg, &r));
00413 }
00414 
00415 static inline isc_boolean_t
00416 checkowner_keydata(ARGS_CHECKOWNER) {
00417 
00418         REQUIRE(type == 65533);
00419 
00420         UNUSED(name);
00421         UNUSED(type);
00422         UNUSED(rdclass);
00423         UNUSED(wildcard);
00424 
00425         return (ISC_TRUE);
00426 }
00427 
00428 static inline isc_boolean_t
00429 checknames_keydata(ARGS_CHECKNAMES) {
00430 
00431         REQUIRE(rdata->type == 65533);
00432 
00433         UNUSED(rdata);
00434         UNUSED(owner);
00435         UNUSED(bad);
00436 
00437         return (ISC_TRUE);
00438 }
00439 
00440 static inline int
00441 casecompare_keydata(ARGS_COMPARE) {
00442         return (compare_keydata(rdata1, rdata2));
00443 }
00444 
00445 #endif /* GENERIC_KEYDATA_65533_C */

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