/src/bind9/lib/dns/rdata/generic/tlsa_52.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | /* rfc6698.txt */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_TLSA_52_C |
17 | | #define RDATA_GENERIC_TLSA_52_C |
18 | | |
19 | 10.7k | #define RRTYPE_TLSA_ATTRIBUTES 0 |
20 | | |
21 | | static isc_result_t |
22 | 708 | generic_fromtext_tlsa(ARGS_FROMTEXT) { |
23 | 708 | isc_token_t token; |
24 | | |
25 | 708 | UNUSED(type); |
26 | 708 | UNUSED(rdclass); |
27 | 708 | UNUSED(origin); |
28 | 708 | UNUSED(options); |
29 | 708 | UNUSED(callbacks); |
30 | | |
31 | | /* |
32 | | * Certificate Usage. |
33 | | */ |
34 | 708 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
35 | 708 | false)); |
36 | 698 | if (token.value.as_ulong > 0xffU) { |
37 | 30 | RETTOK(ISC_R_RANGE); |
38 | 30 | } |
39 | 668 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
40 | | |
41 | | /* |
42 | | * Selector. |
43 | | */ |
44 | 668 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
45 | 668 | false)); |
46 | 647 | if (token.value.as_ulong > 0xffU) { |
47 | 29 | RETTOK(ISC_R_RANGE); |
48 | 29 | } |
49 | 618 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
50 | | |
51 | | /* |
52 | | * Matching type. |
53 | | */ |
54 | 618 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
55 | 618 | false)); |
56 | 610 | if (token.value.as_ulong > 0xffU) { |
57 | 29 | RETTOK(ISC_R_RANGE); |
58 | 29 | } |
59 | 581 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
60 | | |
61 | | /* |
62 | | * Certificate Association Data. |
63 | | */ |
64 | 581 | return isc_hex_tobuffer(lexer, target, isc_one_or_more); |
65 | 581 | } |
66 | | |
67 | | static isc_result_t |
68 | 2.33k | generic_totext_tlsa(ARGS_TOTEXT) { |
69 | 2.33k | isc_region_t sr; |
70 | 2.33k | char buf[sizeof("64000 ")]; |
71 | 2.33k | unsigned int n; |
72 | | |
73 | 2.33k | REQUIRE(rdata->length != 0); |
74 | | |
75 | 2.33k | UNUSED(tctx); |
76 | | |
77 | 2.33k | dns_rdata_toregion(rdata, &sr); |
78 | | |
79 | | /* |
80 | | * Certificate Usage. |
81 | | */ |
82 | 2.33k | n = uint8_fromregion(&sr); |
83 | 2.33k | isc_region_consume(&sr, 1); |
84 | 2.33k | snprintf(buf, sizeof(buf), "%u ", n); |
85 | 2.33k | RETERR(str_totext(buf, target)); |
86 | | |
87 | | /* |
88 | | * Selector. |
89 | | */ |
90 | 2.33k | n = uint8_fromregion(&sr); |
91 | 2.33k | isc_region_consume(&sr, 1); |
92 | 2.33k | snprintf(buf, sizeof(buf), "%u ", n); |
93 | 2.33k | RETERR(str_totext(buf, target)); |
94 | | |
95 | | /* |
96 | | * Matching type. |
97 | | */ |
98 | 2.33k | n = uint8_fromregion(&sr); |
99 | 2.33k | isc_region_consume(&sr, 1); |
100 | 2.33k | snprintf(buf, sizeof(buf), "%u", n); |
101 | 2.33k | RETERR(str_totext(buf, target)); |
102 | | |
103 | | /* |
104 | | * Certificate Association Data. |
105 | | */ |
106 | 2.33k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
107 | 30 | RETERR(str_totext(" (", target)); |
108 | 30 | } |
109 | 2.33k | RETERR(str_totext(tctx->linebreak, target)); |
110 | 2.33k | if (tctx->width == 0) { /* No splitting */ |
111 | 0 | RETERR(isc_hex_totext(&sr, 0, "", target)); |
112 | 2.33k | } else { |
113 | 2.33k | RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, |
114 | 2.33k | target)); |
115 | 2.33k | } |
116 | 2.33k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
117 | 30 | RETERR(str_totext(" )", target)); |
118 | 30 | } |
119 | 2.33k | return ISC_R_SUCCESS; |
120 | 2.33k | } |
121 | | |
122 | | static isc_result_t |
123 | 3.69k | generic_fromwire_tlsa(ARGS_FROMWIRE) { |
124 | 3.69k | isc_region_t sr; |
125 | | |
126 | 3.69k | UNUSED(type); |
127 | 3.69k | UNUSED(rdclass); |
128 | 3.69k | UNUSED(dctx); |
129 | | |
130 | 3.69k | isc_buffer_activeregion(source, &sr); |
131 | | |
132 | | /* Usage(1), Selector(1), Type(1), Data(1+) */ |
133 | 3.69k | if (sr.length < 4) { |
134 | 20 | return ISC_R_UNEXPECTEDEND; |
135 | 20 | } |
136 | | |
137 | 3.67k | isc_buffer_forward(source, sr.length); |
138 | 3.67k | return mem_tobuffer(target, sr.base, sr.length); |
139 | 3.69k | } |
140 | | |
141 | | static isc_result_t |
142 | 383 | fromtext_tlsa(ARGS_FROMTEXT) { |
143 | 383 | REQUIRE(type == dns_rdatatype_tlsa); |
144 | | |
145 | 383 | return generic_fromtext_tlsa(CALL_FROMTEXT); |
146 | 383 | } |
147 | | |
148 | | static isc_result_t |
149 | 1.26k | totext_tlsa(ARGS_TOTEXT) { |
150 | 1.26k | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
151 | | |
152 | 1.26k | return generic_totext_tlsa(CALL_TOTEXT); |
153 | 1.26k | } |
154 | | |
155 | | static isc_result_t |
156 | 2.08k | fromwire_tlsa(ARGS_FROMWIRE) { |
157 | 2.08k | REQUIRE(type == dns_rdatatype_tlsa); |
158 | | |
159 | 2.08k | return generic_fromwire_tlsa(CALL_FROMWIRE); |
160 | 2.08k | } |
161 | | |
162 | | static isc_result_t |
163 | 647 | towire_tlsa(ARGS_TOWIRE) { |
164 | 647 | isc_region_t sr; |
165 | | |
166 | 647 | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
167 | 647 | REQUIRE(rdata->length != 0); |
168 | | |
169 | 647 | UNUSED(cctx); |
170 | | |
171 | 647 | dns_rdata_toregion(rdata, &sr); |
172 | 647 | return mem_tobuffer(target, sr.base, sr.length); |
173 | 647 | } |
174 | | |
175 | | static int |
176 | 4.67k | compare_tlsa(ARGS_COMPARE) { |
177 | 4.67k | isc_region_t r1; |
178 | 4.67k | isc_region_t r2; |
179 | | |
180 | 4.67k | REQUIRE(rdata1->type == rdata2->type); |
181 | 4.67k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
182 | 4.67k | REQUIRE(rdata1->type == dns_rdatatype_tlsa); |
183 | 4.67k | REQUIRE(rdata1->length != 0); |
184 | 4.67k | REQUIRE(rdata2->length != 0); |
185 | | |
186 | 4.67k | dns_rdata_toregion(rdata1, &r1); |
187 | 4.67k | dns_rdata_toregion(rdata2, &r2); |
188 | 4.67k | return isc_region_compare(&r1, &r2); |
189 | 4.67k | } |
190 | | |
191 | | static isc_result_t |
192 | 0 | generic_fromstruct_tlsa(ARGS_FROMSTRUCT) { |
193 | 0 | dns_rdata_tlsa_t *tlsa = source; |
194 | |
|
195 | 0 | REQUIRE(tlsa != NULL); |
196 | 0 | REQUIRE(tlsa->common.rdtype == type); |
197 | 0 | REQUIRE(tlsa->common.rdclass == rdclass); |
198 | |
|
199 | 0 | UNUSED(type); |
200 | 0 | UNUSED(rdclass); |
201 | |
|
202 | 0 | RETERR(uint8_tobuffer(tlsa->usage, target)); |
203 | 0 | RETERR(uint8_tobuffer(tlsa->selector, target)); |
204 | 0 | RETERR(uint8_tobuffer(tlsa->match, target)); |
205 | |
|
206 | 0 | return mem_tobuffer(target, tlsa->data, tlsa->length); |
207 | 0 | } |
208 | | |
209 | | static isc_result_t |
210 | 0 | generic_tostruct_tlsa(ARGS_TOSTRUCT) { |
211 | 0 | dns_rdata_tlsa_t *tlsa = target; |
212 | 0 | isc_region_t region; |
213 | |
|
214 | 0 | REQUIRE(tlsa != NULL); |
215 | 0 | REQUIRE(rdata->length != 0); |
216 | |
|
217 | 0 | REQUIRE(tlsa != NULL); |
218 | 0 | REQUIRE(tlsa->common.rdclass == rdata->rdclass); |
219 | 0 | REQUIRE(tlsa->common.rdtype == rdata->type); |
220 | |
|
221 | 0 | dns_rdata_toregion(rdata, ®ion); |
222 | |
|
223 | 0 | tlsa->usage = uint8_fromregion(®ion); |
224 | 0 | isc_region_consume(®ion, 1); |
225 | 0 | tlsa->selector = uint8_fromregion(®ion); |
226 | 0 | isc_region_consume(®ion, 1); |
227 | 0 | tlsa->match = uint8_fromregion(®ion); |
228 | 0 | isc_region_consume(®ion, 1); |
229 | 0 | tlsa->length = region.length; |
230 | |
|
231 | 0 | tlsa->data = mem_maybedup(mctx, region.base, region.length); |
232 | 0 | tlsa->mctx = mctx; |
233 | 0 | return ISC_R_SUCCESS; |
234 | 0 | } |
235 | | |
236 | | static void |
237 | 0 | generic_freestruct_tlsa(ARGS_FREESTRUCT) { |
238 | 0 | dns_rdata_tlsa_t *tlsa = source; |
239 | |
|
240 | 0 | REQUIRE(tlsa != NULL); |
241 | |
|
242 | 0 | if (tlsa->mctx == NULL) { |
243 | 0 | return; |
244 | 0 | } |
245 | | |
246 | 0 | if (tlsa->data != NULL) { |
247 | 0 | isc_mem_free(tlsa->mctx, tlsa->data); |
248 | 0 | } |
249 | 0 | tlsa->mctx = NULL; |
250 | 0 | } |
251 | | |
252 | | static isc_result_t |
253 | 0 | fromstruct_tlsa(ARGS_FROMSTRUCT) { |
254 | 0 | REQUIRE(type == dns_rdatatype_tlsa); |
255 | |
|
256 | 0 | return generic_fromstruct_tlsa(CALL_FROMSTRUCT); |
257 | 0 | } |
258 | | |
259 | | static isc_result_t |
260 | 0 | tostruct_tlsa(ARGS_TOSTRUCT) { |
261 | 0 | dns_rdata_tlsa_t *tlsa = target; |
262 | |
|
263 | 0 | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
264 | 0 | REQUIRE(tlsa != NULL); |
265 | |
|
266 | 0 | DNS_RDATACOMMON_INIT(tlsa, rdata->type, rdata->rdclass); |
267 | |
|
268 | 0 | return generic_tostruct_tlsa(CALL_TOSTRUCT); |
269 | 0 | } |
270 | | |
271 | | static void |
272 | 0 | freestruct_tlsa(ARGS_FREESTRUCT) { |
273 | 0 | dns_rdata_tlsa_t *tlsa = source; |
274 | |
|
275 | 0 | REQUIRE(tlsa != NULL); |
276 | 0 | REQUIRE(tlsa->common.rdtype == dns_rdatatype_tlsa); |
277 | |
|
278 | 0 | generic_freestruct_tlsa(source); |
279 | 0 | } |
280 | | |
281 | | static isc_result_t |
282 | 0 | additionaldata_tlsa(ARGS_ADDLDATA) { |
283 | 0 | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
284 | |
|
285 | 0 | UNUSED(rdata); |
286 | 0 | UNUSED(owner); |
287 | 0 | UNUSED(add); |
288 | 0 | UNUSED(arg); |
289 | |
|
290 | 0 | return ISC_R_SUCCESS; |
291 | 0 | } |
292 | | |
293 | | static isc_result_t |
294 | 0 | digest_tlsa(ARGS_DIGEST) { |
295 | 0 | isc_region_t r; |
296 | |
|
297 | 0 | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
298 | |
|
299 | 0 | dns_rdata_toregion(rdata, &r); |
300 | |
|
301 | 0 | return (digest)(arg, &r); |
302 | 0 | } |
303 | | |
304 | | static bool |
305 | 0 | checkowner_tlsa(ARGS_CHECKOWNER) { |
306 | 0 | REQUIRE(type == dns_rdatatype_tlsa); |
307 | |
|
308 | 0 | UNUSED(name); |
309 | 0 | UNUSED(type); |
310 | 0 | UNUSED(rdclass); |
311 | 0 | UNUSED(wildcard); |
312 | |
|
313 | 0 | return true; |
314 | 0 | } |
315 | | |
316 | | static bool |
317 | 0 | checknames_tlsa(ARGS_CHECKNAMES) { |
318 | 0 | REQUIRE(rdata->type == dns_rdatatype_tlsa); |
319 | |
|
320 | 0 | UNUSED(rdata); |
321 | 0 | UNUSED(owner); |
322 | 0 | UNUSED(bad); |
323 | |
|
324 | 0 | return true; |
325 | 0 | } |
326 | | |
327 | | static int |
328 | 0 | casecompare_tlsa(ARGS_COMPARE) { |
329 | 0 | return compare_tlsa(rdata1, rdata2); |
330 | 0 | } |
331 | | |
332 | | #endif /* RDATA_GENERIC_TLSA_52_C */ |