tsig.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009-2011  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: tsig.h,v 1.59 2011/01/11 23:47:13 tbox Exp $ */
00019 
00020 #ifndef DNS_TSIG_H
00021 #define DNS_TSIG_H 1
00022 
00023 /*! \file dns/tsig.h */
00024 
00025 #include <isc/lang.h>
00026 #include <isc/refcount.h>
00027 #include <isc/rwlock.h>
00028 #include <isc/stdio.h>
00029 #include <isc/stdtime.h>
00030 
00031 #include <dns/types.h>
00032 #include <dns/name.h>
00033 
00034 #include <dst/dst.h>
00035 
00036 /*
00037  * Algorithms.
00038  */
00039 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacmd5_name;
00040 #define DNS_TSIG_HMACMD5_NAME           dns_tsig_hmacmd5_name
00041 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_gssapi_name;
00042 #define DNS_TSIG_GSSAPI_NAME            dns_tsig_gssapi_name
00043 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_gssapims_name;
00044 #define DNS_TSIG_GSSAPIMS_NAME          dns_tsig_gssapims_name
00045 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha1_name;
00046 #define DNS_TSIG_HMACSHA1_NAME          dns_tsig_hmacsha1_name
00047 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha224_name;
00048 #define DNS_TSIG_HMACSHA224_NAME        dns_tsig_hmacsha224_name
00049 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha256_name;
00050 #define DNS_TSIG_HMACSHA256_NAME        dns_tsig_hmacsha256_name
00051 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha384_name;
00052 #define DNS_TSIG_HMACSHA384_NAME        dns_tsig_hmacsha384_name
00053 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_tsig_hmacsha512_name;
00054 #define DNS_TSIG_HMACSHA512_NAME        dns_tsig_hmacsha512_name
00055 
00056 /*%
00057  * Default fudge value.
00058  */
00059 #define DNS_TSIG_FUDGE                  300
00060 
00061 struct dns_tsig_keyring {
00062         dns_rbt_t *keys;
00063         unsigned int writecount;
00064         isc_rwlock_t lock;
00065         isc_mem_t *mctx;
00066         /*
00067          * LRU list of generated key along with a count of the keys on the
00068          * list and a maximum size.
00069          */
00070         unsigned int generated;
00071         unsigned int maxgenerated;
00072         ISC_LIST(dns_tsigkey_t) lru;
00073         unsigned int references;
00074 };
00075 
00076 struct dns_tsigkey {
00077         /* Unlocked */
00078         unsigned int            magic;          /*%< Magic number. */
00079         isc_mem_t               *mctx;
00080         dst_key_t               *key;           /*%< Key */
00081         dns_name_t              name;           /*%< Key name */
00082         dns_name_t              *algorithm;     /*%< Algorithm name */
00083         dns_name_t              *creator;       /*%< name that created secret */
00084         isc_boolean_t           generated;      /*%< was this generated? */
00085         isc_stdtime_t           inception;      /*%< start of validity period */
00086         isc_stdtime_t           expire;         /*%< end of validity period */
00087         dns_tsig_keyring_t      *ring;          /*%< the enclosing keyring */
00088         isc_refcount_t          refs;           /*%< reference counter */
00089         ISC_LINK(dns_tsigkey_t) link;
00090 };
00091 
00092 #define dns_tsigkey_identity(tsigkey) \
00093         ((tsigkey) == NULL ? NULL : \
00094          (tsigkey)->generated ? ((tsigkey)->creator) : \
00095          (&((tsigkey)->name)))
00096 
00097 ISC_LANG_BEGINDECLS
00098 
00099 isc_result_t
00100 dns_tsigkey_create(dns_name_t *name, dns_name_t *algorithm,
00101                    unsigned char *secret, int length, isc_boolean_t generated,
00102                    dns_name_t *creator, isc_stdtime_t inception,
00103                    isc_stdtime_t expire, isc_mem_t *mctx,
00104                    dns_tsig_keyring_t *ring, dns_tsigkey_t **key);
00105 
00106 isc_result_t
00107 dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm,
00108                           dst_key_t *dstkey, isc_boolean_t generated,
00109                           dns_name_t *creator, isc_stdtime_t inception,
00110                           isc_stdtime_t expire, isc_mem_t *mctx,
00111                           dns_tsig_keyring_t *ring, dns_tsigkey_t **key);
00112 /*%<
00113  *      Creates a tsig key structure and saves it in the keyring.  If key is
00114  *      not NULL, *key will contain a copy of the key.  The keys validity
00115  *      period is specified by (inception, expire), and will not expire if
00116  *      inception == expire.  If the key was generated, the creating identity,
00117  *      if there is one, should be in the creator parameter.  Specifying an
00118  *      unimplemented algorithm will cause failure only if dstkey != NULL; this
00119  *      allows a transient key with an invalid algorithm to exist long enough
00120  *      to generate a BADKEY response.
00121  *
00122  *      If dns_tsigkey_createfromkey is successful a new reference to 'dstkey'
00123  *      will have been made.
00124  *
00125  *      Requires:
00126  *\li           'name' is a valid dns_name_t
00127  *\li           'algorithm' is a valid dns_name_t
00128  *\li           'secret' is a valid pointer
00129  *\li           'length' is an integer >= 0
00130  *\li           'dstkey' is a valid dst key or NULL
00131  *\li           'creator' points to a valid dns_name_t or is NULL
00132  *\li           'mctx' is a valid memory context
00133  *\li           'ring' is a valid TSIG keyring or NULL
00134  *\li           'key' or '*key' must be NULL
00135  *
00136  *      Returns:
00137  *\li           #ISC_R_SUCCESS
00138  *\li           #ISC_R_EXISTS - a key with this name already exists
00139  *\li           #ISC_R_NOTIMPLEMENTED - algorithm is not implemented
00140  *\li           #ISC_R_NOMEMORY
00141  */
00142 
00143 void
00144 dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp);
00145 /*%<
00146  *      Attach '*targetp' to 'source'.
00147  *
00148  *      Requires:
00149  *\li           'key' is a valid TSIG key
00150  *
00151  *      Ensures:
00152  *\li           *targetp is attached to source.
00153  */
00154 
00155 void
00156 dns_tsigkey_detach(dns_tsigkey_t **keyp);
00157 /*%<
00158  *      Detaches from the tsig key structure pointed to by '*key'.
00159  *
00160  *      Requires:
00161  *\li           'keyp' is not NULL and '*keyp' is a valid TSIG key
00162  *
00163  *      Ensures:
00164  *\li           'keyp' points to NULL
00165  */
00166 
00167 void
00168 dns_tsigkey_setdeleted(dns_tsigkey_t *key);
00169 /*%<
00170  *      Prevents this key from being used again.  It will be deleted when
00171  *      no references exist.
00172  *
00173  *      Requires:
00174  *\li           'key' is a valid TSIG key on a keyring
00175  */
00176 
00177 isc_result_t
00178 dns_tsig_sign(dns_message_t *msg);
00179 /*%<
00180  *      Generates a TSIG record for this message
00181  *
00182  *      Requires:
00183  *\li           'msg' is a valid message
00184  *\li           'msg->tsigkey' is a valid TSIG key
00185  *\li           'msg->tsig' is NULL
00186  *
00187  *      Returns:
00188  *\li           #ISC_R_SUCCESS
00189  *\li           #ISC_R_NOMEMORY
00190  *\li           #ISC_R_NOSPACE
00191  *\li           #DNS_R_EXPECTEDTSIG
00192  *                      - this is a response & msg->querytsig is NULL
00193  */
00194 
00195 isc_result_t
00196 dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg,
00197                 dns_tsig_keyring_t *ring1, dns_tsig_keyring_t *ring2);
00198 /*%<
00199  *      Verifies the TSIG record in this message
00200  *
00201  *      Requires:
00202  *\li           'source' is a valid buffer containing the unparsed message
00203  *\li           'msg' is a valid message
00204  *\li           'msg->tsigkey' is a valid TSIG key if this is a response
00205  *\li           'msg->tsig' is NULL
00206  *\li           'msg->querytsig' is not NULL if this is a response
00207  *\li           'ring1' and 'ring2' are each either a valid keyring or NULL
00208  *
00209  *      Returns:
00210  *\li           #ISC_R_SUCCESS
00211  *\li           #ISC_R_NOMEMORY
00212  *\li           #DNS_R_EXPECTEDTSIG - A TSIG was expected but not seen
00213  *\li           #DNS_R_UNEXPECTEDTSIG - A TSIG was seen but not expected
00214  *\li           #DNS_R_TSIGERRORSET - the TSIG verified but ->error was set
00215  *                                   and this is a query
00216  *\li           #DNS_R_CLOCKSKEW - the TSIG failed to verify because of
00217  *                                the time was out of the allowed range.
00218  *\li           #DNS_R_TSIGVERIFYFAILURE - the TSIG failed to verify
00219  *\li           #DNS_R_EXPECTEDRESPONSE - the message was set over TCP and
00220  *                                       should have been a response,
00221  *                                       but was not.
00222  */
00223 
00224 isc_result_t
00225 dns_tsigkey_find(dns_tsigkey_t **tsigkey, dns_name_t *name,
00226                  dns_name_t *algorithm, dns_tsig_keyring_t *ring);
00227 /*%<
00228  *      Returns the TSIG key corresponding to this name and (possibly)
00229  *      algorithm.  Also increments the key's reference counter.
00230  *
00231  *      Requires:
00232  *\li           'tsigkey' is not NULL
00233  *\li           '*tsigkey' is NULL
00234  *\li           'name' is a valid dns_name_t
00235  *\li           'algorithm' is a valid dns_name_t or NULL
00236  *\li           'ring' is a valid keyring
00237  *
00238  *      Returns:
00239  *\li           #ISC_R_SUCCESS
00240  *\li           #ISC_R_NOTFOUND
00241  */
00242 
00243 
00244 isc_result_t
00245 dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ringp);
00246 /*%<
00247  *      Create an empty TSIG key ring.
00248  *
00249  *      Requires:
00250  *\li           'mctx' is not NULL
00251  *\li           'ringp' is not NULL, and '*ringp' is NULL
00252  *
00253  *      Returns:
00254  *\li           #ISC_R_SUCCESS
00255  *\li           #ISC_R_NOMEMORY
00256  */
00257 
00258 isc_result_t
00259 dns_tsigkeyring_add(dns_tsig_keyring_t *ring, dns_name_t *name,
00260                     dns_tsigkey_t *tkey);
00261 /*%<
00262  *      Place a TSIG key onto a key ring.
00263  *
00264  *      Requires:
00265  *\li           'ring', 'name' and 'tkey' are not NULL
00266  *
00267  *      Returns:
00268  *\li           #ISC_R_SUCCESS
00269  *\li           Any other value indicates failure.
00270  */
00271 
00272 
00273 void
00274 dns_tsigkeyring_attach(dns_tsig_keyring_t *source, dns_tsig_keyring_t **target);
00275 
00276 void
00277 dns_tsigkeyring_detach(dns_tsig_keyring_t **ringp);
00278 
00279 isc_result_t
00280 dns_tsigkeyring_dumpanddetach(dns_tsig_keyring_t **ringp, FILE *fp);
00281 
00282 /*%<
00283  *      Destroy a TSIG key ring.
00284  *
00285  *      Requires:
00286  *\li           'ringp' is not NULL
00287  */
00288 
00289 void
00290 dns_keyring_restore(dns_tsig_keyring_t *ring, FILE *fp);
00291 
00292 ISC_LANG_ENDDECLS
00293 
00294 #endif /* DNS_TSIG_H */

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha