ns_verify.c revision 1.3 1 1.3 joerg /* $NetBSD: ns_verify.c,v 1.3 2013/09/13 19:29:47 joerg Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 1.1 christos * Copyright (c) 1999 by Internet Software Consortium, Inc.
6 1.1 christos *
7 1.1 christos * Permission to use, copy, modify, and distribute this software for any
8 1.1 christos * purpose with or without fee is hereby granted, provided that the above
9 1.1 christos * copyright notice and this permission notice appear in all copies.
10 1.1 christos *
11 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 1.1 christos * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1 christos */
19 1.1 christos
20 1.3 joerg #include <sys/cdefs.h>
21 1.3 joerg __RCSID("Id: ns_verify.c,v 1.5 2006/03/09 23:57:56 marka Exp ");
22 1.1 christos
23 1.1 christos /* Import. */
24 1.1 christos
25 1.1 christos #include "port_before.h"
26 1.1 christos #include "fd_setsize.h"
27 1.1 christos
28 1.1 christos #include <sys/types.h>
29 1.1 christos #include <sys/param.h>
30 1.1 christos
31 1.1 christos #include <netinet/in.h>
32 1.1 christos #include <arpa/nameser.h>
33 1.1 christos #include <arpa/inet.h>
34 1.1 christos
35 1.1 christos #include <errno.h>
36 1.1 christos #include <netdb.h>
37 1.1 christos #include <resolv.h>
38 1.1 christos #include <stdio.h>
39 1.1 christos #include <stdlib.h>
40 1.1 christos #include <string.h>
41 1.1 christos #include <time.h>
42 1.1 christos #include <unistd.h>
43 1.1 christos
44 1.1 christos #include <isc/dst.h>
45 1.1 christos
46 1.1 christos #include "port_after.h"
47 1.1 christos
48 1.1 christos /* Private. */
49 1.1 christos
50 1.1 christos #define BOUNDS_CHECK(ptr, count) \
51 1.1 christos do { \
52 1.1 christos if ((ptr) + (count) > eom) { \
53 1.1 christos return (NS_TSIG_ERROR_FORMERR); \
54 1.1 christos } \
55 1.1 christos } while (/*CONSTCOND*/0)
56 1.1 christos
57 1.1 christos /* Public. */
58 1.1 christos
59 1.1 christos u_char *
60 1.1 christos ns_find_tsig(u_char *msg, u_char *eom) {
61 1.1 christos HEADER *hp = (void *)msg;
62 1.1 christos int n, type;
63 1.1 christos u_char *cp = msg, *start;
64 1.1 christos
65 1.1 christos if (msg == NULL || eom == NULL || msg > eom)
66 1.1 christos return (NULL);
67 1.1 christos
68 1.1 christos if (cp + HFIXEDSZ >= eom)
69 1.1 christos return (NULL);
70 1.1 christos
71 1.1 christos if (hp->arcount == 0)
72 1.1 christos return (NULL);
73 1.1 christos
74 1.1 christos cp += HFIXEDSZ;
75 1.1 christos
76 1.1 christos n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount));
77 1.1 christos if (n < 0)
78 1.1 christos return (NULL);
79 1.1 christos cp += n;
80 1.1 christos
81 1.1 christos n = ns_skiprr(cp, eom, ns_s_an, ntohs(hp->ancount));
82 1.1 christos if (n < 0)
83 1.1 christos return (NULL);
84 1.1 christos cp += n;
85 1.1 christos
86 1.1 christos n = ns_skiprr(cp, eom, ns_s_ns, ntohs(hp->nscount));
87 1.1 christos if (n < 0)
88 1.1 christos return (NULL);
89 1.1 christos cp += n;
90 1.1 christos
91 1.1 christos n = ns_skiprr(cp, eom, ns_s_ar, ntohs(hp->arcount) - 1);
92 1.1 christos if (n < 0)
93 1.1 christos return (NULL);
94 1.1 christos cp += n;
95 1.1 christos
96 1.1 christos start = cp;
97 1.1 christos n = dn_skipname(cp, eom);
98 1.1 christos if (n < 0)
99 1.1 christos return (NULL);
100 1.1 christos cp += n;
101 1.1 christos if (cp + INT16SZ >= eom)
102 1.1 christos return (NULL);
103 1.1 christos
104 1.1 christos GETSHORT(type, cp);
105 1.1 christos if (type != ns_t_tsig)
106 1.1 christos return (NULL);
107 1.1 christos return (start);
108 1.1 christos }
109 1.1 christos
110 1.1 christos /* ns_verify
111 1.1 christos *
112 1.1 christos * Parameters:
113 1.1 christos *\li statp res stuff
114 1.1 christos *\li msg received message
115 1.1 christos *\li msglen length of message
116 1.1 christos *\li key tsig key used for verifying.
117 1.1 christos *\li querysig (response), the signature in the query
118 1.1 christos *\li querysiglen (response), the length of the signature in the query
119 1.1 christos *\li sig (query), a buffer to hold the signature
120 1.1 christos *\li siglen (query), input - length of signature buffer
121 1.1 christos * output - length of signature
122 1.1 christos *
123 1.1 christos * Errors:
124 1.1 christos *\li - bad input (-1)
125 1.1 christos *\li - invalid dns message (NS_TSIG_ERROR_FORMERR)
126 1.1 christos *\li - TSIG is not present (NS_TSIG_ERROR_NO_TSIG)
127 1.1 christos *\li - key doesn't match (-ns_r_badkey)
128 1.1 christos *\li - TSIG verification fails with BADKEY (-ns_r_badkey)
129 1.1 christos *\li - TSIG verification fails with BADSIG (-ns_r_badsig)
130 1.1 christos *\li - TSIG verification fails with BADTIME (-ns_r_badtime)
131 1.1 christos *\li - TSIG verification succeeds, error set to BAKEY (ns_r_badkey)
132 1.1 christos *\li - TSIG verification succeeds, error set to BADSIG (ns_r_badsig)
133 1.1 christos *\li - TSIG verification succeeds, error set to BADTIME (ns_r_badtime)
134 1.1 christos */
135 1.1 christos int
136 1.1 christos ns_verify(u_char *msg, int *msglen, void *k,
137 1.1 christos const u_char *querysig, int querysiglen, u_char *sig, int *siglen,
138 1.1 christos time_t *timesigned, int nostrip)
139 1.1 christos {
140 1.1 christos HEADER *hp = (void *)msg;
141 1.1 christos DST_KEY *key = (DST_KEY *)k;
142 1.1 christos u_char *cp = msg, *eom;
143 1.1 christos char name[MAXDNAME], alg[MAXDNAME];
144 1.1 christos u_char *recstart, *rdatastart;
145 1.1 christos u_char *sigstart, *otherstart;
146 1.1 christos int n;
147 1.1 christos int error;
148 1.1 christos u_int16_t type, length;
149 1.1 christos u_int16_t fudge, sigfieldlen, otherfieldlen;
150 1.1 christos
151 1.1 christos dst_init();
152 1.1 christos if (msg == NULL || msglen == NULL || *msglen < 0)
153 1.1 christos return (-1);
154 1.1 christos
155 1.1 christos eom = msg + *msglen;
156 1.1 christos
157 1.1 christos recstart = ns_find_tsig(msg, eom);
158 1.1 christos if (recstart == NULL)
159 1.1 christos return (NS_TSIG_ERROR_NO_TSIG);
160 1.1 christos
161 1.1 christos cp = recstart;
162 1.1 christos
163 1.1 christos /* Read the key name. */
164 1.1 christos n = dn_expand(msg, eom, cp, name, MAXDNAME);
165 1.1 christos if (n < 0)
166 1.1 christos return (NS_TSIG_ERROR_FORMERR);
167 1.1 christos cp += n;
168 1.1 christos
169 1.1 christos /* Read the type. */
170 1.1 christos BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ);
171 1.1 christos GETSHORT(type, cp);
172 1.1 christos if (type != ns_t_tsig)
173 1.1 christos return (NS_TSIG_ERROR_NO_TSIG);
174 1.1 christos
175 1.1 christos /* Skip the class and TTL, save the length. */
176 1.1 christos cp += INT16SZ + INT32SZ;
177 1.1 christos GETSHORT(length, cp);
178 1.1 christos if (eom - cp != length)
179 1.1 christos return (NS_TSIG_ERROR_FORMERR);
180 1.1 christos
181 1.1 christos /* Read the algorithm name. */
182 1.1 christos rdatastart = cp;
183 1.1 christos n = dn_expand(msg, eom, cp, alg, MAXDNAME);
184 1.1 christos if (n < 0)
185 1.1 christos return (NS_TSIG_ERROR_FORMERR);
186 1.1 christos if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1)
187 1.1 christos return (-ns_r_badkey);
188 1.1 christos cp += n;
189 1.1 christos
190 1.1 christos /* Read the time signed and fudge. */
191 1.1 christos BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
192 1.1 christos cp += INT16SZ;
193 1.1 christos GETLONG((*timesigned), cp);
194 1.1 christos GETSHORT(fudge, cp);
195 1.1 christos
196 1.1 christos /* Read the signature. */
197 1.1 christos BOUNDS_CHECK(cp, INT16SZ);
198 1.1 christos GETSHORT(sigfieldlen, cp);
199 1.1 christos BOUNDS_CHECK(cp, sigfieldlen);
200 1.1 christos sigstart = cp;
201 1.1 christos cp += sigfieldlen;
202 1.1 christos
203 1.1 christos /* Skip id and read error. */
204 1.1 christos BOUNDS_CHECK(cp, 2*INT16SZ);
205 1.1 christos cp += INT16SZ;
206 1.1 christos GETSHORT(error, cp);
207 1.1 christos
208 1.1 christos /* Parse the other data. */
209 1.1 christos BOUNDS_CHECK(cp, INT16SZ);
210 1.1 christos GETSHORT(otherfieldlen, cp);
211 1.1 christos BOUNDS_CHECK(cp, otherfieldlen);
212 1.1 christos otherstart = cp;
213 1.1 christos cp += otherfieldlen;
214 1.1 christos
215 1.1 christos if (cp != eom)
216 1.1 christos return (NS_TSIG_ERROR_FORMERR);
217 1.1 christos
218 1.1 christos /* Verify that the key used is OK. */
219 1.1 christos if (key != NULL) {
220 1.1 christos if (key->dk_alg != KEY_HMAC_MD5)
221 1.1 christos return (-ns_r_badkey);
222 1.1 christos if (error != ns_r_badsig && error != ns_r_badkey) {
223 1.1 christos if (ns_samename(key->dk_key_name, name) != 1)
224 1.1 christos return (-ns_r_badkey);
225 1.1 christos }
226 1.1 christos }
227 1.1 christos
228 1.1 christos hp->arcount = htons(ntohs(hp->arcount) - 1);
229 1.1 christos
230 1.1 christos /*
231 1.1 christos * Do the verification.
232 1.1 christos */
233 1.1 christos
234 1.1 christos if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
235 1.1 christos void *ctx;
236 1.1 christos u_char buf[MAXDNAME];
237 1.1 christos u_char buf2[MAXDNAME];
238 1.1 christos
239 1.1 christos /* Digest the query signature, if this is a response. */
240 1.1 christos dst_verify_data(SIG_MODE_INIT, key, &ctx, NULL, 0, NULL, 0);
241 1.1 christos if (querysiglen > 0 && querysig != NULL) {
242 1.1 christos u_int16_t len_n = htons(querysiglen);
243 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
244 1.1 christos (void *)&len_n, INT16SZ, NULL, 0);
245 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
246 1.1 christos querysig, querysiglen, NULL, 0);
247 1.1 christos }
248 1.1 christos
249 1.1 christos /* Digest the message. */
250 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx, msg,
251 1.1 christos (int)(recstart - msg), NULL, 0);
252 1.1 christos
253 1.1 christos /* Digest the key name. */
254 1.1 christos n = ns_name_pton(name, buf2, sizeof(buf2));
255 1.1 christos if (n < 0)
256 1.1 christos return (-1);
257 1.1 christos n = ns_name_ntol(buf2, buf, sizeof(buf));
258 1.1 christos if (n < 0)
259 1.1 christos return (-1);
260 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
261 1.1 christos
262 1.1 christos /* Digest the class and TTL. */
263 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
264 1.1 christos recstart + dn_skipname(recstart, eom) + INT16SZ,
265 1.1 christos INT16SZ + INT32SZ, NULL, 0);
266 1.1 christos
267 1.1 christos /* Digest the algorithm. */
268 1.1 christos n = ns_name_pton(alg, buf2, sizeof(buf2));
269 1.1 christos if (n < 0)
270 1.1 christos return (-1);
271 1.1 christos n = ns_name_ntol(buf2, buf, sizeof(buf));
272 1.1 christos if (n < 0)
273 1.1 christos return (-1);
274 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
275 1.1 christos
276 1.1 christos /* Digest the time signed and fudge. */
277 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
278 1.1 christos rdatastart + dn_skipname(rdatastart, eom),
279 1.1 christos INT16SZ + INT32SZ + INT16SZ, NULL, 0);
280 1.1 christos
281 1.1 christos /* Digest the error and other data. */
282 1.1 christos dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
283 1.1 christos otherstart - INT16SZ - INT16SZ,
284 1.1 christos otherfieldlen + INT16SZ + INT16SZ, NULL, 0);
285 1.1 christos
286 1.1 christos n = dst_verify_data(SIG_MODE_FINAL, key, &ctx, NULL, 0,
287 1.1 christos sigstart, sigfieldlen);
288 1.1 christos
289 1.1 christos if (n < 0)
290 1.1 christos return (-ns_r_badsig);
291 1.1 christos
292 1.1 christos if (sig != NULL && siglen != NULL) {
293 1.1 christos if (*siglen < sigfieldlen)
294 1.1 christos return (NS_TSIG_ERROR_NO_SPACE);
295 1.1 christos memcpy(sig, sigstart, sigfieldlen);
296 1.1 christos *siglen = sigfieldlen;
297 1.1 christos }
298 1.1 christos } else {
299 1.1 christos if (sigfieldlen > 0)
300 1.1 christos return (NS_TSIG_ERROR_FORMERR);
301 1.1 christos if (sig != NULL && siglen != NULL)
302 1.1 christos *siglen = 0;
303 1.1 christos }
304 1.1 christos
305 1.1 christos /* Reset the counter, since we still need to check for badtime. */
306 1.1 christos hp->arcount = htons(ntohs(hp->arcount) + 1);
307 1.1 christos
308 1.1 christos /* Verify the time. */
309 1.1 christos if (abs((int)((*timesigned) - time(NULL))) > fudge)
310 1.1 christos return (-ns_r_badtime);
311 1.1 christos
312 1.1 christos if (nostrip == 0) {
313 1.1 christos *msglen = (int)(recstart - msg);
314 1.1 christos hp->arcount = htons(ntohs(hp->arcount) - 1);
315 1.1 christos }
316 1.1 christos
317 1.1 christos if (error != NOERROR)
318 1.1 christos return (error);
319 1.1 christos
320 1.1 christos return (0);
321 1.1 christos }
322 1.1 christos
323 1.1 christos int
324 1.1 christos ns_verify_tcp_init(void *k, const u_char *querysig, int querysiglen,
325 1.1 christos ns_tcp_tsig_state *state)
326 1.1 christos {
327 1.1 christos dst_init();
328 1.1 christos if (state == NULL || k == NULL || querysig == NULL || querysiglen < 0)
329 1.1 christos return (-1);
330 1.1 christos state->counter = -1;
331 1.1 christos state->key = k;
332 1.1 christos if (state->key->dk_alg != KEY_HMAC_MD5)
333 1.1 christos return (-ns_r_badkey);
334 1.1 christos if (querysiglen > (int)sizeof(state->sig))
335 1.1 christos return (-1);
336 1.1 christos memcpy(state->sig, querysig, querysiglen);
337 1.1 christos state->siglen = querysiglen;
338 1.1 christos return (0);
339 1.1 christos }
340 1.1 christos
341 1.1 christos int
342 1.1 christos ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state,
343 1.1 christos int required)
344 1.1 christos {
345 1.1 christos HEADER *hp = (void *)msg;
346 1.1 christos u_char *recstart, *sigstart;
347 1.1 christos unsigned int sigfieldlen, otherfieldlen;
348 1.1 christos u_char *cp, *eom, *cp2;
349 1.1 christos char name[MAXDNAME], alg[MAXDNAME];
350 1.1 christos u_char buf[MAXDNAME];
351 1.1 christos int n, type, length, fudge, error;
352 1.1 christos time_t timesigned;
353 1.1 christos
354 1.1 christos if (msg == NULL || msglen == NULL || state == NULL)
355 1.1 christos return (-1);
356 1.1 christos
357 1.1 christos eom = msg + *msglen;
358 1.1 christos
359 1.1 christos state->counter++;
360 1.1 christos if (state->counter == 0)
361 1.1 christos return (ns_verify(msg, msglen, state->key,
362 1.1 christos state->sig, state->siglen,
363 1.1 christos state->sig, &state->siglen, ×igned, 0));
364 1.1 christos
365 1.1 christos if (state->siglen > 0) {
366 1.1 christos u_int16_t siglen_n = htons(state->siglen);
367 1.1 christos
368 1.1 christos dst_verify_data(SIG_MODE_INIT, state->key, &state->ctx,
369 1.1 christos NULL, 0, NULL, 0);
370 1.1 christos dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
371 1.1 christos (void *)&siglen_n, INT16SZ, NULL, 0);
372 1.1 christos dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
373 1.1 christos state->sig, state->siglen, NULL, 0);
374 1.1 christos state->siglen = 0;
375 1.1 christos }
376 1.1 christos
377 1.1 christos cp = recstart = ns_find_tsig(msg, eom);
378 1.1 christos
379 1.1 christos if (recstart == NULL) {
380 1.1 christos if (required)
381 1.1 christos return (NS_TSIG_ERROR_NO_TSIG);
382 1.1 christos dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
383 1.1 christos msg, *msglen, NULL, 0);
384 1.1 christos return (0);
385 1.1 christos }
386 1.1 christos
387 1.1 christos hp->arcount = htons(ntohs(hp->arcount) - 1);
388 1.1 christos dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
389 1.1 christos msg, (int)(recstart - msg), NULL, 0);
390 1.1 christos
391 1.1 christos /* Read the key name. */
392 1.1 christos n = dn_expand(msg, eom, cp, name, MAXDNAME);
393 1.1 christos if (n < 0)
394 1.1 christos return (NS_TSIG_ERROR_FORMERR);
395 1.1 christos cp += n;
396 1.1 christos
397 1.1 christos /* Read the type. */
398 1.1 christos BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ);
399 1.1 christos GETSHORT(type, cp);
400 1.1 christos if (type != ns_t_tsig)
401 1.1 christos return (NS_TSIG_ERROR_NO_TSIG);
402 1.1 christos
403 1.1 christos /* Skip the class and TTL, save the length. */
404 1.1 christos cp += INT16SZ + INT32SZ;
405 1.1 christos GETSHORT(length, cp);
406 1.1 christos if (eom - cp != length)
407 1.1 christos return (NS_TSIG_ERROR_FORMERR);
408 1.1 christos
409 1.1 christos /* Read the algorithm name. */
410 1.1 christos n = dn_expand(msg, eom, cp, alg, MAXDNAME);
411 1.1 christos if (n < 0)
412 1.1 christos return (NS_TSIG_ERROR_FORMERR);
413 1.1 christos if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1)
414 1.1 christos return (-ns_r_badkey);
415 1.1 christos cp += n;
416 1.1 christos
417 1.1 christos /* Verify that the key used is OK. */
418 1.1 christos if ((ns_samename(state->key->dk_key_name, name) != 1 ||
419 1.1 christos state->key->dk_alg != KEY_HMAC_MD5))
420 1.1 christos return (-ns_r_badkey);
421 1.1 christos
422 1.1 christos /* Read the time signed and fudge. */
423 1.1 christos BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
424 1.1 christos cp += INT16SZ;
425 1.1 christos GETLONG(timesigned, cp);
426 1.1 christos GETSHORT(fudge, cp);
427 1.1 christos
428 1.1 christos /* Read the signature. */
429 1.1 christos BOUNDS_CHECK(cp, INT16SZ);
430 1.1 christos GETSHORT(sigfieldlen, cp);
431 1.1 christos BOUNDS_CHECK(cp, sigfieldlen);
432 1.1 christos sigstart = cp;
433 1.1 christos cp += sigfieldlen;
434 1.1 christos
435 1.1 christos /* Skip id and read error. */
436 1.1 christos BOUNDS_CHECK(cp, 2*INT16SZ);
437 1.1 christos cp += INT16SZ;
438 1.1 christos GETSHORT(error, cp);
439 1.1 christos
440 1.1 christos /* Parse the other data. */
441 1.1 christos BOUNDS_CHECK(cp, INT16SZ);
442 1.1 christos GETSHORT(otherfieldlen, cp);
443 1.1 christos BOUNDS_CHECK(cp, otherfieldlen);
444 1.1 christos cp += otherfieldlen;
445 1.1 christos
446 1.1 christos if (cp != eom)
447 1.1 christos return (NS_TSIG_ERROR_FORMERR);
448 1.1 christos
449 1.1 christos /*
450 1.1 christos * Do the verification.
451 1.1 christos */
452 1.1 christos
453 1.1 christos /* Digest the time signed and fudge. */
454 1.1 christos cp2 = buf;
455 1.1 christos PUTSHORT(0, cp2); /*%< Top 16 bits of time. */
456 1.1 christos PUTLONG(timesigned, cp2);
457 1.1 christos PUTSHORT(NS_TSIG_FUDGE, cp2);
458 1.1 christos
459 1.1 christos dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
460 1.1 christos buf, (int)(cp2 - buf), NULL, 0);
461 1.1 christos
462 1.1 christos n = dst_verify_data(SIG_MODE_FINAL, state->key, &state->ctx, NULL, 0,
463 1.2 christos sigstart, (int)sigfieldlen);
464 1.1 christos if (n < 0)
465 1.1 christos return (-ns_r_badsig);
466 1.1 christos
467 1.1 christos if (sigfieldlen > sizeof(state->sig))
468 1.1 christos return (NS_TSIG_ERROR_NO_SPACE);
469 1.1 christos
470 1.1 christos memcpy(state->sig, sigstart, sigfieldlen);
471 1.1 christos state->siglen = sigfieldlen;
472 1.1 christos
473 1.1 christos /* Verify the time. */
474 1.1 christos if (abs((int)(timesigned - time(NULL))) > fudge)
475 1.1 christos return (-ns_r_badtime);
476 1.1 christos
477 1.1 christos *msglen = (int)(recstart - msg);
478 1.1 christos
479 1.1 christos if (error != NOERROR)
480 1.1 christos return (error);
481 1.1 christos
482 1.1 christos return (0);
483 1.1 christos }
484 1.1 christos
485 1.1 christos /*! \file */
486