tsig_250.c 13.1 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
Michael Graff's avatar
Michael Graff committed
3
 * 
Mark Andrews's avatar
Mark Andrews committed
4
5
6
 * 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.
Michael Graff's avatar
Michael Graff committed
7
 * 
Mark Andrews's avatar
Mark Andrews committed
8
9
10
11
12
13
14
15
16
17
 * 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.
 */

David Lawrence's avatar
David Lawrence committed
18
/* $Id: tsig_250.c,v 1.36 2000/05/15 21:14:18 tale Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

Andreas Gustafsson's avatar
Andreas Gustafsson committed
20
21
22
/* Reviewed: Thu Mar 16 13:39:43 PST 2000 by gson */

/* draft-ietf-dnsext-tsig-00.txt */
Mark Andrews's avatar
Mark Andrews committed
23

24
25
#ifndef RDATA_ANY_255_TSIG_250_C
#define RDATA_ANY_255_TSIG_250_C
Andreas Gustafsson's avatar
Andreas Gustafsson committed
26

27
28
#define RRTYPE_TSIG_ATTRIBUTES \
	(DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION)
29

30
static inline isc_result_t
31
fromtext_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
32
33
34
35
36
		  isc_lex_t *lexer, dns_name_t *origin,
		  isc_boolean_t downcase, isc_buffer_t *target)
{
	isc_token_t token;
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
37
	isc_uint64_t sigtime;
Mark Andrews's avatar
Mark Andrews committed
38
39
40
41
	isc_buffer_t buffer;
	char *e;

	REQUIRE(type == 250);
42
	REQUIRE(rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
43

David Lawrence's avatar
David Lawrence committed
44
45
46
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
47
48
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
	dns_name_init(&name, NULL);
49
	buffer_fromregion(&buffer, &token.value.as_region);
Mark Andrews's avatar
Mark Andrews committed
50
51
52
	origin = (origin != NULL) ? origin : dns_rootname;
	RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));

David Lawrence's avatar
David Lawrence committed
53
54
55
	/*
	 * Time Signed: 48 bits.
	 */
Mark Andrews's avatar
Mark Andrews committed
56
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
57
	sigtime = isc_string_touint64(token.value.as_pointer, &e, 10);
Mark Andrews's avatar
Mark Andrews committed
58
59
60
	if (*e != 0)
		return (DNS_R_SYNTAX);
	if ((sigtime >> 48) != 0)
David Lawrence's avatar
David Lawrence committed
61
		return (ISC_R_RANGE);
62
	RETERR(uint16_tobuffer((isc_uint16_t)(sigtime >> 32), target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
63
	RETERR(uint32_tobuffer((isc_uint32_t)(sigtime & 0xffffffffU), target));
Mark Andrews's avatar
Mark Andrews committed
64

David Lawrence's avatar
David Lawrence committed
65
66
67
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
68
69
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
70
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
71
72
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
73
74
75
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
76
77
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
78
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
79
80
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
81
82
83
84
	/*
	 * Signature.
	 */
	RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
85

David Lawrence's avatar
David Lawrence committed
86
87
88
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
89
90
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
91
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
92
93
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
94
95
96
	/*
	 * Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
97
98
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
99
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
100
101
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
102
103
104
	/*
	 * Other Len.
	 */
Mark Andrews's avatar
Mark Andrews committed
105
106
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
107
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
108
109
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
110
111
112
113
	/*
	 * Other Data.
	 */
	return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
114
115
}

116
static inline isc_result_t
117
118
119
totext_any_tsig(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
		isc_buffer_t *target) 
{
Mark Andrews's avatar
Mark Andrews committed
120
121
122
	isc_region_t sr;
	isc_region_t sigr;
	char buf[sizeof "281474976710655 "];	
Mark Andrews's avatar
Mark Andrews committed
123
	char *bufp;
Mark Andrews's avatar
Mark Andrews committed
124
125
126
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
Mark Andrews's avatar
Mark Andrews committed
127
	isc_uint64_t sigtime;
Mark Andrews's avatar
Mark Andrews committed
128
129
130
	unsigned short n;

	REQUIRE(rdata->type == 250);
131
	REQUIRE(rdata->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
132
133

	dns_rdata_toregion(rdata, &sr);
David Lawrence's avatar
David Lawrence committed
134
135
136
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
137
138
139
	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);
	dns_name_fromregion(&name, &sr);
140
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
141
142
143
144
	RETERR(dns_name_totext(&prefix, sub, target));
	RETERR(str_totext(" ", target));
	isc_region_consume(&sr, name_length(&name));

David Lawrence's avatar
David Lawrence committed
145
146
147
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
148
149
	sigtime = ((isc_uint64_t)sr.base[0] << 40) |
		  ((isc_uint64_t)sr.base[1] << 32) |
Mark Andrews's avatar
Mark Andrews committed
150
151
152
		  (sr.base[2] << 24) | (sr.base[3] << 16) |
		  (sr.base[4] << 8) | sr.base[5];
	isc_region_consume(&sr, 6);
Mark Andrews's avatar
Mark Andrews committed
153
154
155
156
157
158
159
160
161
	bufp = &buf[sizeof buf - 1];
	*bufp-- = 0;
	*bufp-- = ' ';
	do {
		*bufp-- = decdigits[sigtime % 10];
		sigtime /= 10;
	} while (sigtime != 0);
	bufp++;
	RETERR(str_totext(bufp, target));
Mark Andrews's avatar
Mark Andrews committed
162

David Lawrence's avatar
David Lawrence committed
163
164
165
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
166
167
168
169
170
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
171
172
173
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
174
175
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
176
	sprintf(buf, "%u", n);
Mark Andrews's avatar
Mark Andrews committed
177
178
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
179
180
181
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
182
183
184
	REQUIRE(n <= sr.length);
	sigr = sr;
	sigr.length = n;
185
186
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)	
		RETERR(str_totext(" (", target));
187
188
189
	RETERR(str_totext(tctx->linebreak, target));
	RETERR(isc_base64_totext(&sigr, tctx->width - 2, 
				 tctx->linebreak, target));
190
191
192
193
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" ) ", target));
	else
		RETERR(str_totext(" ", target));		
Mark Andrews's avatar
Mark Andrews committed
194
195
	isc_region_consume(&sr, n);

David Lawrence's avatar
David Lawrence committed
196
197
198
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
199
200
201
202
203
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
204
205
206
	/*
	 * Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
207
208
209
210
211
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
212
213
214
	/*
	 * Other Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
215
216
217
218
219
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
220
221
222
	/*
	 * Other.
	 */
223
	return (isc_base64_totext(&sr, 60, " ", target));
Mark Andrews's avatar
Mark Andrews committed
224
225
}

226
static inline isc_result_t
227
fromwire_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
228
229
230
231
232
233
234
235
		  isc_buffer_t *source, dns_decompress_t *dctx,
		  isc_boolean_t downcase, isc_buffer_t *target)
{
	isc_region_t sr;
	dns_name_t name;
	unsigned long n;

	REQUIRE(type == 250);
236
	REQUIRE(rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
237
	
238
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
239

David Lawrence's avatar
David Lawrence committed
240
241
242
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
243
244
245
	dns_name_init(&name, NULL);
	RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));

246
	isc_buffer_activeregion(source, &sr);
David Lawrence's avatar
David Lawrence committed
247
248
249
	/*
	 * Time Signed + Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
250
	if (sr.length < 8)
251
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
252
253
254
255
	RETERR(mem_tobuffer(target, sr.base, 8));
	isc_region_consume(&sr, 8);
	isc_buffer_forward(source, 8);

David Lawrence's avatar
David Lawrence committed
256
257
258
	/*
	 * Signature Length + Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
259
	if (sr.length < 2)
260
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
261
262
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
263
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
264
265
266
267
	RETERR(mem_tobuffer(target, sr.base, n + 2));
	isc_region_consume(&sr, n + 2);
	isc_buffer_forward(source, n + 2);

David Lawrence's avatar
David Lawrence committed
268
269
270
	/*
	 * Original ID + Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
271
	if (sr.length < 4)
272
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
273
274
275
276
	RETERR(mem_tobuffer(target, sr.base,  4));
	isc_region_consume(&sr, 4);
	isc_buffer_forward(source, 4);

David Lawrence's avatar
David Lawrence committed
277
278
279
	/*
	 * Other Length + Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
280
	if (sr.length < 2)
281
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
282
283
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
284
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
285
286
287
288
	isc_buffer_forward(source, n + 2);
	return (mem_tobuffer(target, sr.base, n + 2));
}

289
static inline isc_result_t
290
291
292
towire_any_tsig(dns_rdata_t *rdata, dns_compress_t *cctx,
		isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
293
294
295
296
	isc_region_t sr;
	dns_name_t name;

	REQUIRE(rdata->type == 250);
297
	REQUIRE(rdata->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
298

299
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
300
301
302
303
304
305
306
307
	dns_rdata_toregion(rdata, &sr);
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &sr);
	RETERR(dns_name_towire(&name, cctx, target));
	isc_region_consume(&sr, name_length(&name));
	return (mem_tobuffer(target, sr.base, sr.length));
}

308
static inline int
Mark Andrews's avatar
Mark Andrews committed
309
310
311
312
313
compare_any_tsig(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
	isc_region_t r1;
	isc_region_t r2;
	dns_name_t name1;
	dns_name_t name2;
314
	int order;
Mark Andrews's avatar
Mark Andrews committed
315
316

	REQUIRE(rdata1->type == rdata2->type);
317
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
318
	REQUIRE(rdata1->type == 250);
319
	REQUIRE(rdata1->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
320
321
322
323
324
325
326
	
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);
	dns_name_fromregion(&name1, &r1);
	dns_name_fromregion(&name2, &r2);
327
328
329
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
Mark Andrews's avatar
Mark Andrews committed
330
331
332
333
334
	isc_region_consume(&r1, name_length(&name1));
	isc_region_consume(&r2, name_length(&name2));
	return (compare_region(&r1, &r2));
}

335
static inline isc_result_t
336
fromstruct_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
337
338
		    void *source, isc_buffer_t *target)
{
339
340
	isc_region_t tr;
	dns_rdata_any_tsig_t *tsig;
Mark Andrews's avatar
Mark Andrews committed
341
342

	REQUIRE(type == 250);
343
	REQUIRE(rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
344
	
345
	tsig = (dns_rdata_any_tsig_t *)source;
346

David Lawrence's avatar
David Lawrence committed
347
348
349
	/*
	 * Algorithm Name.
	 */
350
	RETERR(name_tobuffer(&tsig->algorithm, target));
351

352
	isc_buffer_availableregion(target, &tr);
353
	if (tr.length < 6 + 2 + 2)
354
		return (ISC_R_NOSPACE);
355

David Lawrence's avatar
David Lawrence committed
356
357
358
359
360
	/*
	 * Time Signed: 48 bits.
	 */
	RETERR(uint16_tobuffer((isc_uint16_t)(tsig->timesigned >> 32),
			       target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
361
	RETERR(uint32_tobuffer((isc_uint32_t)(tsig->timesigned & 0xffffffffU),
362
			       target));
363

David Lawrence's avatar
David Lawrence committed
364
365
366
	/*
	 * Fudge.
	 */
367
368
	RETERR(uint16_tobuffer(tsig->fudge, target));

David Lawrence's avatar
David Lawrence committed
369
370
371
	/*
	 * Signature Size.
	 */
372
373
	RETERR(uint16_tobuffer(tsig->siglen, target));

David Lawrence's avatar
David Lawrence committed
374
375
376
	/*
	 * Signature.
	 */
377
	if (tsig->siglen > 0) {
378
		isc_buffer_availableregion(target, &tr);
379
		if (tr.length < tsig->siglen)
380
			return (ISC_R_NOSPACE);
381
382
383
384
		memcpy(tr.base, tsig->signature, tsig->siglen);
		isc_buffer_add(target, tsig->siglen);
	}

385
	isc_buffer_availableregion(target, &tr);
386
	if (tr.length < 2 + 2 + 2)
387
		return (ISC_R_NOSPACE);
388

David Lawrence's avatar
David Lawrence committed
389
390
391
	/*
	 * Original ID.
	 */
392
393
	RETERR(uint16_tobuffer(tsig->originalid, target));

David Lawrence's avatar
David Lawrence committed
394
395
396
	/*
	 * Error.
	 */
397
398
	RETERR(uint16_tobuffer(tsig->error, target));

David Lawrence's avatar
David Lawrence committed
399
400
401
	/*
	 * Other Len.
	 */
402
403
	RETERR(uint16_tobuffer(tsig->otherlen, target));

David Lawrence's avatar
David Lawrence committed
404
405
406
	/*
	 * Other Data.
	 */
407
	if (tsig->otherlen > 0) {
408
		isc_buffer_availableregion(target, &tr);
409
		if (tr.length < tsig->otherlen)
410
			return (ISC_R_NOSPACE);
411
412
413
414
		memcpy(tr.base, tsig->other, tsig->otherlen);
		isc_buffer_add(target, tsig->otherlen);
	}

415
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
416
417
}

418
static inline isc_result_t
419
tostruct_any_tsig(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
420
421
422
	dns_rdata_any_tsig_t *tsig;
	dns_name_t alg;
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
423
424

	REQUIRE(rdata->type == 250);
425
	REQUIRE(rdata->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
426
	
427
428
429
430
431
432
433
	tsig = (dns_rdata_any_tsig_t *) target;
	tsig->common.rdclass = rdata->rdclass;
	tsig->common.rdtype = rdata->type;
	ISC_LINK_INIT(&tsig->common, link);
	tsig->mctx = mctx;
	dns_rdata_toregion(rdata, &sr);

David Lawrence's avatar
David Lawrence committed
434
435
436
	/*
	 * Algorithm Name.
	 */
437
438
	dns_name_init(&alg, NULL);
	dns_name_fromregion(&alg, &sr);
439
440
	dns_name_init(&tsig->algorithm, NULL);
	RETERR(dns_name_dup(&alg, mctx, &tsig->algorithm));
441
	
442
	isc_region_consume(&sr, name_length(&tsig->algorithm));
443

David Lawrence's avatar
David Lawrence committed
444
445
446
	/*
	 * Time Signed.
	 */
Brian Wellington's avatar
Brian Wellington committed
447
448
	if (sr.length < 6)
		return (ISC_R_UNEXPECTEDEND);
449
450
451
452
453
454
	tsig->timesigned = ((isc_uint64_t)sr.base[0] << 40) |
			   ((isc_uint64_t)sr.base[1] << 32) |
			   (sr.base[2] << 24) | (sr.base[3] << 16) |
			   (sr.base[4] << 8) | sr.base[5];
	isc_region_consume(&sr, 6);

David Lawrence's avatar
David Lawrence committed
455
456
457
	/*
	 * Fudge.
	 */
Brian Wellington's avatar
Brian Wellington committed
458
459
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
460
461
462
	tsig->fudge = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
463
464
465
	/*
	 * Signature Size.
	 */
Brian Wellington's avatar
Brian Wellington committed
466
467
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
468
469
470
	tsig->siglen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
471
472
473
	/*
	 * Signature.
	 */
474
475
476
477
	if (sr.length < tsig->siglen)
		return (ISC_R_UNEXPECTEDEND);
	tsig->signature = isc_mem_get(mctx, tsig->siglen);
	if (tsig->signature == NULL)
478
		return (ISC_R_NOMEMORY);
479
480
	memcpy(tsig->signature, sr.base, tsig->siglen);
	isc_region_consume(&sr, tsig->siglen);
481

David Lawrence's avatar
David Lawrence committed
482
483
484
	/*
	 * Original ID.
	 */
Brian Wellington's avatar
Brian Wellington committed
485
486
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
487
488
489
	tsig->originalid = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
490
491
492
	/*
	 * Error.
	 */
Brian Wellington's avatar
Brian Wellington committed
493
494
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
495
496
497
	tsig->error = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
498
499
500
	/*
	 * Other Size.
	 */
Brian Wellington's avatar
Brian Wellington committed
501
502
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
503
504
505
	tsig->otherlen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
506
507
508
	/*
	 * Other.
	 */
509
510
511
512
	if (sr.length < tsig->otherlen)
		return (ISC_R_UNEXPECTEDEND);
	tsig->other = isc_mem_get(mctx, tsig->otherlen);
	if (tsig->other == NULL)
513
		return (ISC_R_NOMEMORY);
514
515
	memcpy(tsig->other, sr.base, tsig->otherlen);
	isc_region_consume(&sr, tsig->otherlen);
516

517
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
518
}
519

520
static inline void
521
freestruct_any_tsig(void *source) {
522
	dns_rdata_any_tsig_t *tsig = (dns_rdata_any_tsig_t *) source;
523
524
525
526
527

	REQUIRE(source != NULL);
	REQUIRE(tsig->common.rdclass == 255);
	REQUIRE(tsig->common.rdtype == 250);

528
	dns_name_free(&tsig->algorithm, tsig->mctx);	
529
	if (tsig->signature != NULL)
530
		isc_mem_put(tsig->mctx, tsig->signature, tsig->siglen);
531
	if (tsig->other != NULL)
532
		isc_mem_put(tsig->mctx, tsig->other, tsig->otherlen);
533
}
534

535
static inline isc_result_t
536
537
538
539
540
541
additionaldata_any_tsig(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
			void *arg)
{
	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

542
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
543
544
	UNUSED(add);
	UNUSED(arg);
545

546
	return (ISC_R_SUCCESS);
547
548
}

549
static inline isc_result_t
Bob Halley's avatar
Bob Halley committed
550
551
552
553
554
digest_any_tsig(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {

	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

555
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
556
557
	UNUSED(digest);
	UNUSED(arg);
Bob Halley's avatar
Bob Halley committed
558

559
	return (ISC_R_NOTIMPLEMENTED);
Bob Halley's avatar
Bob Halley committed
560
561
}

562
#endif	/* RDATA_ANY_255_TSIG_250_C */