]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/bind9/lib/dns/include/dns/tsig.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / bind9 / lib / dns / include / dns / tsig.h
1 /*
2  * Copyright (C) 2004-2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: tsig.h,v 1.43.18.4 2006/01/27 23:57:44 marka Exp $ */
19
20 #ifndef DNS_TSIG_H
21 #define DNS_TSIG_H 1
22
23 /*! \file */
24
25 #include <isc/lang.h>
26 #include <isc/refcount.h>
27 #include <isc/rwlock.h>
28 #include <isc/stdtime.h>
29
30 #include <dns/types.h>
31 #include <dns/name.h>
32
33 #include <dst/dst.h>
34
35 /*
36  * Algorithms.
37  */
38 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacmd5_name;
39 #define DNS_TSIG_HMACMD5_NAME           dns_tsig_hmacmd5_name
40 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_gssapi_name;
41 #define DNS_TSIG_GSSAPI_NAME            dns_tsig_gssapi_name
42 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_gssapims_name;
43 #define DNS_TSIG_GSSAPIMS_NAME          dns_tsig_gssapims_name
44 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha1_name;
45 #define DNS_TSIG_HMACSHA1_NAME          dns_tsig_hmacsha1_name
46 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha224_name;
47 #define DNS_TSIG_HMACSHA224_NAME        dns_tsig_hmacsha224_name
48 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha256_name;
49 #define DNS_TSIG_HMACSHA256_NAME        dns_tsig_hmacsha256_name
50 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha384_name;
51 #define DNS_TSIG_HMACSHA384_NAME        dns_tsig_hmacsha384_name
52 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha512_name;
53 #define DNS_TSIG_HMACSHA512_NAME        dns_tsig_hmacsha512_name
54
55 /*%
56  * Default fudge value.
57  */
58 #define DNS_TSIG_FUDGE                  300
59
60 struct dns_tsig_keyring {
61         dns_rbt_t *keys;
62         isc_rwlock_t lock;
63         isc_mem_t *mctx;
64 };
65
66 struct dns_tsigkey {
67         /* Unlocked */
68         unsigned int            magic;          /*%< Magic number. */
69         isc_mem_t               *mctx;
70         dst_key_t               *key;           /*%< Key */
71         dns_name_t              name;           /*%< Key name */
72         dns_name_t              *algorithm;     /*%< Algorithm name */
73         dns_name_t              *creator;       /*%< name that created secret */
74         isc_boolean_t           generated;      /*%< was this generated? */
75         isc_stdtime_t           inception;      /*%< start of validity period */
76         isc_stdtime_t           expire;         /*%< end of validity period */
77         dns_tsig_keyring_t      *ring;          /*%< the enclosing keyring */
78         isc_refcount_t          refs;           /*%< reference counter */
79 };
80
81 #define dns_tsigkey_identity(tsigkey) \
82         ((tsigkey)->generated ? ((tsigkey)->creator) : (&((tsigkey)->name)))
83
84 ISC_LANG_BEGINDECLS
85
86 isc_result_t
87 dns_tsigkey_create(dns_name_t *name, dns_name_t *algorithm,
88                    unsigned char *secret, int length, isc_boolean_t generated,
89                    dns_name_t *creator, isc_stdtime_t inception,
90                    isc_stdtime_t expire, isc_mem_t *mctx,
91                    dns_tsig_keyring_t *ring, dns_tsigkey_t **key);
92
93 isc_result_t
94 dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm,
95                           dst_key_t *dstkey, isc_boolean_t generated,
96                           dns_name_t *creator, isc_stdtime_t inception,
97                           isc_stdtime_t expire, isc_mem_t *mctx,
98                           dns_tsig_keyring_t *ring, dns_tsigkey_t **key);
99 /*%<
100  *      Creates a tsig key structure and saves it in the keyring.  If key is
101  *      not NULL, *key will contain a copy of the key.  The keys validity
102  *      period is specified by (inception, expire), and will not expire if
103  *      inception == expire.  If the key was generated, the creating identity,
104  *      if there is one, should be in the creator parameter.  Specifying an
105  *      unimplemented algorithm will cause failure only if dstkey != NULL; this
106  *      allows a transient key with an invalid algorithm to exist long enough
107  *      to generate a BADKEY response.
108  *
109  *      Requires:
110  *\li           'name' is a valid dns_name_t
111  *\li           'algorithm' is a valid dns_name_t
112  *\li           'secret' is a valid pointer
113  *\li           'length' is an integer >= 0
114  *\li           'key' is a valid dst key or NULL
115  *\li           'creator' points to a valid dns_name_t or is NULL
116  *\li           'mctx' is a valid memory context
117  *\li           'ring' is a valid TSIG keyring or NULL
118  *\li           'key' or '*key' must be NULL
119  *
120  *      Returns:
121  *\li           #ISC_R_SUCCESS
122  *\li           #ISC_R_EXISTS - a key with this name already exists
123  *\li           #ISC_R_NOTIMPLEMENTED - algorithm is not implemented
124  *\li           #ISC_R_NOMEMORY
125  */
126
127 void
128 dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp);
129 /*%<
130  *      Attach '*targetp' to 'source'.
131  *
132  *      Requires:
133  *\li           'key' is a valid TSIG key
134  *
135  *      Ensures:
136  *\li           *targetp is attached to source.
137  */
138
139 void
140 dns_tsigkey_detach(dns_tsigkey_t **keyp);
141 /*%<
142  *      Detaches from the tsig key structure pointed to by '*key'.
143  *
144  *      Requires:
145  *\li           'keyp' is not NULL and '*keyp' is a valid TSIG key
146  *
147  *      Ensures:
148  *\li           'keyp' points to NULL
149  */
150
151 void
152 dns_tsigkey_setdeleted(dns_tsigkey_t *key);
153 /*%<
154  *      Prevents this key from being used again.  It will be deleted when
155  *      no references exist.
156  *
157  *      Requires:
158  *\li           'key' is a valid TSIG key on a keyring
159  */
160
161 isc_result_t
162 dns_tsig_sign(dns_message_t *msg);
163 /*%<
164  *      Generates a TSIG record for this message
165  *
166  *      Requires:
167  *\li           'msg' is a valid message
168  *\li           'msg->tsigkey' is a valid TSIG key
169  *\li           'msg->tsig' is NULL
170  *
171  *      Returns:
172  *\li           #ISC_R_SUCCESS
173  *\li           #ISC_R_NOMEMORY
174  *\li           #ISC_R_NOSPACE
175  *\li           #DNS_R_EXPECTEDTSIG
176  *                      - this is a response & msg->querytsig is NULL
177  */
178
179 isc_result_t
180 dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg,
181                 dns_tsig_keyring_t *ring1, dns_tsig_keyring_t *ring2);
182 /*%<
183  *      Verifies the TSIG record in this message
184  *
185  *      Requires:
186  *\li           'source' is a valid buffer containing the unparsed message
187  *\li           'msg' is a valid message
188  *\li           'msg->tsigkey' is a valid TSIG key if this is a response
189  *\li           'msg->tsig' is NULL
190  *\li           'msg->querytsig' is not NULL if this is a response
191  *\li           'ring1' and 'ring2' are each either a valid keyring or NULL
192  *
193  *      Returns:
194  *\li           #ISC_R_SUCCESS
195  *\li           #ISC_R_NOMEMORY
196  *\li           #DNS_R_EXPECTEDTSIG - A TSIG was expected but not seen
197  *\li           #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
198  *\li           #DNS_R_TSIGERRORSET - the TSIG verified but ->error was set
199  *                                   and this is a query
200  *\li           #DNS_R_CLOCKSKEW - the TSIG failed to verify because of
201  *                                the time was out of the allowed range.
202  *\li           #DNS_R_TSIGVERIFYFAILURE - the TSIG failed to verify
203  *\li           #DNS_R_EXPECTEDRESPONSE - the message was set over TCP and
204  *                                       should have been a response,
205  *                                       but was not.
206  */
207
208 isc_result_t
209 dns_tsigkey_find(dns_tsigkey_t **tsigkey, dns_name_t *name,
210                  dns_name_t *algorithm, dns_tsig_keyring_t *ring);
211 /*%<
212  *      Returns the TSIG key corresponding to this name and (possibly)
213  *      algorithm.  Also increments the key's reference counter.
214  *
215  *      Requires:
216  *\li           'tsigkey' is not NULL
217  *\li           '*tsigkey' is NULL
218  *\li           'name' is a valid dns_name_t
219  *\li           'algorithm' is a valid dns_name_t or NULL
220  *\li           'ring' is a valid keyring
221  *
222  *      Returns:
223  *\li           #ISC_R_SUCCESS
224  *\li           #ISC_R_NOTFOUND
225  */
226
227
228 isc_result_t
229 dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ringp);
230 /*%<
231  *      Create an empty TSIG key ring.
232  *
233  *      Requires:
234  *\li           'mctx' is not NULL
235  *\li           'ringp' is not NULL, and '*ringp' is NULL
236  *
237  *      Returns:
238  *\li           #ISC_R_SUCCESS
239  *\li           #ISC_R_NOMEMORY
240  */
241
242
243 void
244 dns_tsigkeyring_destroy(dns_tsig_keyring_t **ringp);
245 /*%<
246  *      Destroy a TSIG key ring.
247  *
248  *      Requires:
249  *\li           'ringp' is not NULL
250  */
251
252 ISC_LANG_ENDDECLS
253
254 #endif /* DNS_TSIG_H */