]>
git.saurik.com Git - apple/libresolv.git/blob - res_sendsigned.c
2 #include "port_before.h"
3 #include "fd_setsize.h"
9 #include <netinet/in.h>
10 #include <arpa/nameser.h>
11 #include <arpa/inet.h>
23 #include "port_after.h"
28 #include "res_private.h"
31 #include "res_debug.h"
36 res_nsendsigned(res_state statp
, const u_char
*msg
, int msglen
,
37 ns_tsig_key
*key
, u_char
*answer
, int anslen
)
43 int newmsglen
, bufsize
, siglen
;
51 nstatp
= (res_state
) malloc(sizeof(*statp
));
56 memcpy(nstatp
, statp
, sizeof(*statp
));
59 bufsize
= msglen
+ 1024;
60 newmsg
= (u_char
*) malloc(bufsize
);
65 memcpy(newmsg
, msg
, msglen
);
68 if (ns_samename(key
->alg
, NS_TSIG_ALG_HMAC_MD5
) != 1)
71 dstkey
= dst_buffer_to_key(key
->name
, KEY_HMAC_MD5
,
72 NS_KEY_TYPE_AUTH_ONLY
,
84 ret
= ns_sign(newmsg
, &newmsglen
, bufsize
, ns_r_noerror
, dstkey
, NULL
, 0,
90 if (ret
== NS_TSIG_ERROR_NO_SPACE
)
97 if (newmsglen
> NS_PACKETSZ
|| (nstatp
->options
& RES_IGNTC
))
100 nstatp
->options
|= RES_IGNTC
;
102 nstatp
->options
|= RES_USEVC
;
106 ret
= res_nsend(nstatp
, newmsg
, newmsglen
, answer
, anslen
);
110 dst_free_key(dstkey
);
115 ret
= ns_verify(answer
, &anslen
, dstkey
, sig
, siglen
,
116 NULL
, NULL
, &tsig_time
, nstatp
->options
& RES_KEEPTSIG
);
118 Dprint(nstatp
->pfcode
& RES_PRF_REPLY
,
119 (stdout
, ";; TSIG invalid (%s)\n", p_rcode(ret
)));
122 dst_free_key(dstkey
);
129 Dprint(nstatp
->pfcode
& RES_PRF_REPLY
, (stdout
, ";; TSIG ok\n"));
131 hp
= (HEADER
*) answer
;
132 if (hp
->tc
&& usingTCP
== 0) {
133 nstatp
->options
&= ~RES_IGNTC
;
140 dst_free_key(dstkey
);