00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef RDATA_GENERIC_KEY_25_C
00027 #define RDATA_GENERIC_KEY_25_C
00028
00029 #include <dst/dst.h>
00030
00031 #define RRTYPE_KEY_ATTRIBUTES (0)
00032
00033 static inline isc_result_t
00034 fromtext_key(ARGS_FROMTEXT) {
00035 isc_result_t result;
00036 isc_token_t token;
00037 dns_secalg_t alg;
00038 dns_secproto_t proto;
00039 dns_keyflags_t flags;
00040
00041 REQUIRE(type == 25);
00042
00043 UNUSED(type);
00044 UNUSED(rdclass);
00045 UNUSED(origin);
00046 UNUSED(options);
00047 UNUSED(callbacks);
00048
00049
00050 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00051 ISC_FALSE));
00052 RETTOK(dns_keyflags_fromtext(&flags, &token.value.as_textregion));
00053 RETERR(uint16_tobuffer(flags, target));
00054
00055
00056 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00057 ISC_FALSE));
00058 RETTOK(dns_secproto_fromtext(&proto, &token.value.as_textregion));
00059 RETERR(mem_tobuffer(target, &proto, 1));
00060
00061
00062 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00063 ISC_FALSE));
00064 RETTOK(dns_secalg_fromtext(&alg, &token.value.as_textregion));
00065 RETERR(mem_tobuffer(target, &alg, 1));
00066
00067
00068 if ((flags & 0xc000) == 0xc000)
00069 return (ISC_R_SUCCESS);
00070
00071 result = isc_base64_tobuffer(lexer, target, -1);
00072 if (result != ISC_R_SUCCESS)
00073 return (result);
00074
00075
00076 if (alg == DST_ALG_RSAMD5 && isc_buffer_usedlength(target) < 7)
00077 return (ISC_R_UNEXPECTEDEND);
00078
00079 return (ISC_R_SUCCESS);
00080 }
00081
00082 static inline isc_result_t
00083 totext_key(ARGS_TOTEXT) {
00084 isc_region_t sr;
00085 char buf[sizeof("64000")];
00086 unsigned int flags;
00087 unsigned char algorithm;
00088 char namebuf[DNS_NAME_FORMATSIZE];
00089
00090 REQUIRE(rdata->type == 25);
00091 REQUIRE(rdata->length != 0);
00092
00093 dns_rdata_toregion(rdata, &sr);
00094
00095
00096 flags = uint16_fromregion(&sr);
00097 isc_region_consume(&sr, 2);
00098 sprintf(buf, "%u", flags);
00099 RETERR(str_totext(buf, target));
00100 RETERR(str_totext(" ", target));
00101
00102
00103 sprintf(buf, "%u", sr.base[0]);
00104 isc_region_consume(&sr, 1);
00105 RETERR(str_totext(buf, target));
00106 RETERR(str_totext(" ", target));
00107
00108
00109 algorithm = sr.base[0];
00110 sprintf(buf, "%u", algorithm);
00111 isc_region_consume(&sr, 1);
00112 RETERR(str_totext(buf, target));
00113
00114
00115 if ((flags & 0xc000) == 0xc000)
00116 return (ISC_R_SUCCESS);
00117
00118 if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0 &&
00119 algorithm == DNS_KEYALG_PRIVATEDNS) {
00120 dns_name_t name;
00121 dns_name_init(&name, NULL);
00122 dns_name_fromregion(&name, &sr);
00123 dns_name_format(&name, namebuf, sizeof(namebuf));
00124 } else
00125 namebuf[0] = 0;
00126
00127
00128 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00129 RETERR(str_totext(" (", target));
00130 RETERR(str_totext(tctx->linebreak, target));
00131 if (tctx->width == 0)
00132 RETERR(isc_base64_totext(&sr, 60, "", target));
00133 else
00134 RETERR(isc_base64_totext(&sr, tctx->width - 2,
00135 tctx->linebreak, target));
00136
00137 if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0)
00138 RETERR(str_totext(tctx->linebreak, target));
00139 else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00140 RETERR(str_totext(" ", target));
00141
00142 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00143 RETERR(str_totext(")", target));
00144
00145 if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) {
00146 isc_region_t tmpr;
00147
00148 RETERR(str_totext(" ; key id = ", target));
00149 dns_rdata_toregion(rdata, &tmpr);
00150 sprintf(buf, "%u", dst_region_computeid(&tmpr, algorithm));
00151 RETERR(str_totext(buf, target));
00152 if (algorithm == DNS_KEYALG_PRIVATEDNS) {
00153 RETERR(str_totext(tctx->linebreak, target));
00154 RETERR(str_totext("; alg = ", target));
00155 RETERR(str_totext(namebuf, target));
00156 }
00157 }
00158 return (ISC_R_SUCCESS);
00159 }
00160
00161 static inline isc_result_t
00162 fromwire_key(ARGS_FROMWIRE) {
00163 unsigned char algorithm;
00164 isc_region_t sr;
00165
00166 REQUIRE(type == 25);
00167
00168 UNUSED(type);
00169 UNUSED(rdclass);
00170 UNUSED(dctx);
00171 UNUSED(options);
00172
00173 isc_buffer_activeregion(source, &sr);
00174 if (sr.length < 4)
00175 return (ISC_R_UNEXPECTEDEND);
00176
00177 algorithm = sr.base[3];
00178 RETERR(mem_tobuffer(target, sr.base, 4));
00179 isc_region_consume(&sr, 4);
00180 isc_buffer_forward(source, 4);
00181
00182 if (algorithm == DNS_KEYALG_PRIVATEDNS) {
00183 dns_name_t name;
00184 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00185 dns_name_init(&name, NULL);
00186 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
00187 }
00188
00189
00190
00191
00192
00193
00194 if (algorithm == DST_ALG_RSAMD5 && sr.length < 3)
00195 return (ISC_R_UNEXPECTEDEND);
00196
00197 isc_buffer_activeregion(source, &sr);
00198 isc_buffer_forward(source, sr.length);
00199 return (mem_tobuffer(target, sr.base, sr.length));
00200 }
00201
00202 static inline isc_result_t
00203 towire_key(ARGS_TOWIRE) {
00204 isc_region_t sr;
00205
00206 REQUIRE(rdata->type == 25);
00207 REQUIRE(rdata->length != 0);
00208
00209 UNUSED(cctx);
00210
00211 dns_rdata_toregion(rdata, &sr);
00212 return (mem_tobuffer(target, sr.base, sr.length));
00213 }
00214
00215 static inline int
00216 compare_key(ARGS_COMPARE) {
00217 isc_region_t r1;
00218 isc_region_t r2;
00219
00220 REQUIRE(rdata1->type == rdata2->type);
00221 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00222 REQUIRE(rdata1->type == 25);
00223 REQUIRE(rdata1->length != 0);
00224 REQUIRE(rdata2->length != 0);
00225
00226 dns_rdata_toregion(rdata1, &r1);
00227 dns_rdata_toregion(rdata2, &r2);
00228 return (isc_region_compare(&r1, &r2));
00229 }
00230
00231 static inline isc_result_t
00232 fromstruct_key(ARGS_FROMSTRUCT) {
00233 dns_rdata_key_t *key = source;
00234
00235 REQUIRE(type == 25);
00236 REQUIRE(source != NULL);
00237 REQUIRE(key->common.rdtype == type);
00238 REQUIRE(key->common.rdclass == rdclass);
00239
00240 UNUSED(type);
00241 UNUSED(rdclass);
00242
00243
00244 RETERR(uint16_tobuffer(key->flags, target));
00245
00246
00247 RETERR(uint8_tobuffer(key->protocol, target));
00248
00249
00250 RETERR(uint8_tobuffer(key->algorithm, target));
00251
00252
00253 return (mem_tobuffer(target, key->data, key->datalen));
00254 }
00255
00256 static inline isc_result_t
00257 tostruct_key(ARGS_TOSTRUCT) {
00258 dns_rdata_key_t *key = target;
00259 isc_region_t sr;
00260
00261 REQUIRE(rdata->type == 25);
00262 REQUIRE(target != NULL);
00263 REQUIRE(rdata->length != 0);
00264
00265 key->common.rdclass = rdata->rdclass;
00266 key->common.rdtype = rdata->type;
00267 ISC_LINK_INIT(&key->common, link);
00268
00269 dns_rdata_toregion(rdata, &sr);
00270
00271
00272 if (sr.length < 2)
00273 return (ISC_R_UNEXPECTEDEND);
00274 key->flags = uint16_fromregion(&sr);
00275 isc_region_consume(&sr, 2);
00276
00277
00278 if (sr.length < 1)
00279 return (ISC_R_UNEXPECTEDEND);
00280 key->protocol = uint8_fromregion(&sr);
00281 isc_region_consume(&sr, 1);
00282
00283
00284 if (sr.length < 1)
00285 return (ISC_R_UNEXPECTEDEND);
00286 key->algorithm = uint8_fromregion(&sr);
00287 isc_region_consume(&sr, 1);
00288
00289
00290 key->datalen = sr.length;
00291 key->data = mem_maybedup(mctx, sr.base, key->datalen);
00292 if (key->data == NULL)
00293 return (ISC_R_NOMEMORY);
00294
00295 key->mctx = mctx;
00296 return (ISC_R_SUCCESS);
00297 }
00298
00299 static inline void
00300 freestruct_key(ARGS_FREESTRUCT) {
00301 dns_rdata_key_t *key = (dns_rdata_key_t *) source;
00302
00303 REQUIRE(source != NULL);
00304 REQUIRE(key->common.rdtype == 25);
00305
00306 if (key->mctx == NULL)
00307 return;
00308
00309 if (key->data != NULL)
00310 isc_mem_free(key->mctx, key->data);
00311 key->mctx = NULL;
00312 }
00313
00314 static inline isc_result_t
00315 additionaldata_key(ARGS_ADDLDATA) {
00316 REQUIRE(rdata->type == 25);
00317
00318 UNUSED(rdata);
00319 UNUSED(add);
00320 UNUSED(arg);
00321
00322 return (ISC_R_SUCCESS);
00323 }
00324
00325 static inline isc_result_t
00326 digest_key(ARGS_DIGEST) {
00327 isc_region_t r;
00328
00329 REQUIRE(rdata->type == 25);
00330
00331 dns_rdata_toregion(rdata, &r);
00332
00333 return ((digest)(arg, &r));
00334 }
00335
00336 static inline isc_boolean_t
00337 checkowner_key(ARGS_CHECKOWNER) {
00338
00339 REQUIRE(type == 25);
00340
00341 UNUSED(name);
00342 UNUSED(type);
00343 UNUSED(rdclass);
00344 UNUSED(wildcard);
00345
00346 return (ISC_TRUE);
00347 }
00348
00349 static inline isc_boolean_t
00350 checknames_key(ARGS_CHECKNAMES) {
00351
00352 REQUIRE(rdata->type == 25);
00353
00354 UNUSED(rdata);
00355 UNUSED(owner);
00356 UNUSED(bad);
00357
00358 return (ISC_TRUE);
00359 }
00360
00361 static inline int
00362 casecompare_key(ARGS_COMPARE) {
00363 return (compare_key(rdata1, rdata2));
00364 }
00365
00366 #endif