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

18 19
#ifndef DNS_CONFKEYS_H
#define DNS_CONFKEYS_H 1
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

/*****
 ***** Module Info
 *****/

/*
 * The ADTs for the key values defined in a named.conf config file.
 */

/*
 * 
 * MP:
 *
 *	Caller must to all necessary locking.
 *
 * Reliability:
 *
 *	Not applicable.
 *
 * Resources:
 *
 *	Memory allocators supplied by caller
 *
 * Security:
James Brister's avatar
James Brister committed
44
 *	
45 46 47
 *	Not applicable.
 *
 * Standards:
James Brister's avatar
James Brister committed
48
 *	
49 50 51 52 53 54 55
 *	Not applicable.
 */

/***
 *** Imports
 ***/

Andreas Gustafsson's avatar
Andreas Gustafsson committed
56 57 58
#include <stdio.h>

#include <isc/types.h>
59 60 61
#include <isc/list.h>


62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#define DNS_C_TKEY_MAGIC		0x544b4559 /* TKEY */
#define DNS_C_TKEYLIST_MAGIC		0x544b4c53 /* TKLS */
#define DNS_C_PUBKEY_MAGIC		0x5055424b /* PUBK */
#define DNS_C_PKLIST_MAGIC		0x504b4c53 /* PKLS */
#define DNS_C_KDEF_MAGIC		0x4b444546 /* KDEF */
#define DNS_C_KDEFLIST_MAGIC		0x4b4c5354 /* KLST */
#define DNS_C_KEYID_MAGIC		0x4b455949 /* KEYI */
#define DNS_C_KEYIDLIST_MAGIC		0x4b494c53 /* KILS */

#define DNS_C_TKEY_VALID(ptr)	   ISC_MAGIC_VALID(ptr, DNS_C_TKEY_MAGIC)
#define DNS_C_TKEYLIST_VALID(ptr)  ISC_MAGIC_VALID(ptr, DNS_C_TKEYLIST_MAGIC)
#define DNS_C_PUBKEY_VALID(ptr)	   ISC_MAGIC_VALID(ptr, DNS_C_PUBKEY_MAGIC)
#define DNS_C_PKLIST_VALID(ptr)	   ISC_MAGIC_VALID(ptr, DNS_C_PKLIST_MAGIC)
#define DNS_C_KDEF_VALID(ptr)	   ISC_MAGIC_VALID(ptr, DNS_C_KDEF_MAGIC)
#define DNS_C_KDEFLIST_VALID(ptr)  ISC_MAGIC_VALID(ptr, DNS_C_KDEFLIST_MAGIC)
#define DNS_C_KEYID_VALID(ptr)	   ISC_MAGIC_VALID(ptr, DNS_C_KEYID_MAGIC)
#define DNS_C_KEYIDLIST_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_KEYIDLIST_MAGIC)


81 82 83 84 85 86 87

/***
 *** Types
 ***/


typedef struct dns_c_pubkey		dns_c_pubkey_t;
88
typedef struct dns_c_pklist		dns_c_pklist_t;
89
typedef struct dns_c_tkey		dns_c_tkey_t;
90
typedef struct dns_c_tkey_list		dns_c_tkeylist_t;
91
typedef struct dns_c_kdef		dns_c_kdef_t;
92
typedef struct dns_c_kdef_list		dns_c_kdeflist_t;
93
typedef struct dns_c_kid		dns_c_kid_t;
94
typedef struct dns_c_kid_list		dns_c_kidlist_t;
95 96 97 98 99


/* The type for holding a trusted key value. */
struct dns_c_tkey
{
100
	isc_uint32_t		magic;
101 102 103 104 105 106 107 108 109 110 111
	isc_mem_t	       *mem;
	
	char		       *domain;
	dns_c_pubkey_t	       *pubkey;

	ISC_LINK(dns_c_tkey_t)	next;
};

/* A list of trusted keys. */
struct dns_c_tkey_list
{
112
	isc_uint32_t		magic;
113 114 115 116 117 118 119 120 121
	isc_mem_t	       *mem;

	ISC_LIST(dns_c_tkey_t)	tkeylist;
};
	
	
/* A public key value */
struct dns_c_pubkey
{
122
	isc_uint32_t	magic;
123 124 125 126
	isc_mem_t      *mem;
	isc_int32_t	flags;
	isc_int32_t	protocol;
	isc_int32_t	algorithm;
James Brister's avatar
James Brister committed
127
	char	       *key;
128 129 130 131 132 133 134 135 136 137 138

	ISC_LINK(dns_c_pubkey_t)	next;
};

/* A list of pubkeys */
struct dns_c_pklist
{
	isc_uint32_t			magic;
	isc_mem_t		       *mem;

	ISC_LIST(dns_c_pubkey_t)	keylist;
139 140 141 142 143 144
};


/* A private key definition from a 'key' statement */
struct dns_c_kdef 
{
145
	isc_uint32_t		magic;
146
	isc_mem_t	       *mem;
147 148 149 150 151 152 153 154 155 156 157 158

	char		       *keyid;
	char		       *algorithm;
	char		       *secret;

	ISC_LINK(dns_c_kdef_t)	next;
};


/* A list of private keys */
struct dns_c_kdef_list
{
159
	isc_uint32_t		magic;
160 161 162 163 164 165 166 167 168
	isc_mem_t	       *mem;

	ISC_LIST(dns_c_kdef_t)	keydefs;
};


/* A key id for in a server statement 'keys' list */
struct dns_c_kid
{
169
	isc_uint32_t		magic;
170
	isc_mem_t	       *mem;
171 172 173 174 175 176 177 178 179 180
	char		       *keyid;

	ISC_LINK(dns_c_kid_t)	next;
};


/* List of key ids for a 'server' statement */
struct dns_c_kid_list
{
	isc_mem_t	       *mem;
181
	isc_uint32_t		magic;
182 183 184 185 186 187 188 189 190

	ISC_LIST(dns_c_kid_t)	keyids;
};


/***
 *** Functions
 ***/

191
isc_result_t	dns_c_pklist_new(isc_mem_t *mem,
192
                                 dns_c_pklist_t **pklist);
193 194
isc_result_t	dns_c_pklist_delete(dns_c_pklist_t **list);
isc_result_t	dns_c_pklist_addpubkey(dns_c_pklist_t *list,
195 196
                                       dns_c_pubkey_t *pkey,
                                       isc_boolean_t deepcopy);
197
isc_result_t	dns_c_pklist_findpubkey(dns_c_pklist_t *list,
198 199 200 201 202
					dns_c_pubkey_t **pubkey,
					isc_int32_t flags,
					isc_int32_t protocol,
					isc_int32_t algorithm,
					const char *key);
203
isc_result_t	dns_c_pklist_rmpubkey(dns_c_pklist_t *list,
204 205 206 207
				      isc_int32_t flags,
				      isc_int32_t protocol,
				      isc_int32_t algorithm,
				      const char *key);
208
void		dns_c_pklist_print(FILE *fp, int indent,
209 210 211 212
				   dns_c_pklist_t *pubkey);



213
isc_result_t	dns_c_pubkey_new(isc_mem_t *mem, isc_int32_t flags,
214 215 216
				 isc_int32_t protocol,
				 isc_int32_t algorithm,
				 const char *key, dns_c_pubkey_t **pubkey);
217 218
isc_result_t	dns_c_pubkey_delete(dns_c_pubkey_t **pubkey);
isc_result_t	dns_c_pubkey_copy(isc_mem_t *mem, dns_c_pubkey_t **dest,
219
				  dns_c_pubkey_t *src);
220
isc_boolean_t	dns_c_pubkey_equal(dns_c_pubkey_t *k1, dns_c_pubkey_t *k2);
221
void		dns_c_pubkey_print(FILE *fp, int indent,
222 223 224
				   dns_c_pubkey_t *pubkey);


225
isc_result_t	dns_c_kidlist_new(isc_mem_t *mem,
James Brister's avatar
James Brister committed
226
				  dns_c_kidlist_t **list);
227 228
isc_result_t	dns_c_kidlist_delete(dns_c_kidlist_t **list);
isc_result_t	dns_c_kidlist_undef(dns_c_kidlist_t *list,
James Brister's avatar
James Brister committed
229
				    const char *keyid);
230
isc_result_t	dns_c_kidlist_find(dns_c_kidlist_t *list,
James Brister's avatar
James Brister committed
231 232
				   const char *keyid,
				   dns_c_kid_t **retval);
233 234
void		dns_c_kidlist_append(dns_c_kidlist_t *list,
				     dns_c_kid_t *keyid);
235
void		dns_c_kidlist_print(FILE *fp, int indent,
James Brister's avatar
James Brister committed
236
				    dns_c_kidlist_t *list);
237
isc_result_t	dns_c_kid_new(isc_mem_t *mem, const char *name,
238 239
			      dns_c_kid_t **keyid);

240 241 242



243
isc_result_t	dns_c_kdeflist_new(isc_mem_t *mem,
James Brister's avatar
James Brister committed
244
				   dns_c_kdeflist_t **list);
245 246
isc_result_t	dns_c_kdeflist_delete(dns_c_kdeflist_t **list);
isc_result_t	dns_c_kdeflist_copy(isc_mem_t *mem,
James Brister's avatar
James Brister committed
247 248
				    dns_c_kdeflist_t **dest,
				    dns_c_kdeflist_t *src);
249
isc_result_t	dns_c_kdeflist_append(dns_c_kdeflist_t *list,
James Brister's avatar
James Brister committed
250 251
				      dns_c_kdef_t *key, isc_boolean_t copy);

252
isc_result_t	dns_c_kdeflist_undef(dns_c_kdeflist_t *list,
James Brister's avatar
James Brister committed
253
				     const char *keyid);
254
isc_result_t	dns_c_kdeflist_find(dns_c_kdeflist_t *list,
James Brister's avatar
James Brister committed
255 256
				    const char *keyid,
				    dns_c_kdef_t **retval);
257
void		dns_c_kdeflist_print(FILE *fp, int indent,
James Brister's avatar
James Brister committed
258
				     dns_c_kdeflist_t *list);
James Brister's avatar
James Brister committed
259

260
isc_result_t	dns_c_kdef_new(isc_mem_t *mem, const char *name,
261
			       dns_c_kdef_t **keyid);
262 263
isc_result_t	dns_c_kdef_delete(dns_c_kdef_t **keydef);
isc_result_t	dns_c_kdef_copy(isc_mem_t *mem,
James Brister's avatar
James Brister committed
264 265
				dns_c_kdef_t **dest, dns_c_kdef_t *src);

266
void		dns_c_kdef_print(FILE *fp, int indent, dns_c_kdef_t *keydef);
James Brister's avatar
James Brister committed
267 268


269
isc_result_t	dns_c_kdef_setalgorithm(dns_c_kdef_t *elem,
James Brister's avatar
James Brister committed
270
					const char *algorithm);
271
isc_result_t	dns_c_kdef_setsecret(dns_c_kdef_t *elem,
James Brister's avatar
James Brister committed
272 273
				     const char *secret);

274
isc_result_t	dns_c_tkeylist_new(isc_mem_t *mem,
James Brister's avatar
James Brister committed
275
				   dns_c_tkeylist_t **newlist);
276 277
isc_result_t	dns_c_tkeylist_delete(dns_c_tkeylist_t **list);
isc_result_t	dns_c_tkeylist_copy(isc_mem_t *mem,
James Brister's avatar
James Brister committed
278 279
				    dns_c_tkeylist_t **dest,
				    dns_c_tkeylist_t *src);
280
void		dns_c_tkeylist_print(FILE *fp, int indent,
James Brister's avatar
James Brister committed
281
				     dns_c_tkeylist_t *list);
282
isc_result_t	dns_c_tkeylist_append(dns_c_tkeylist_t *list,
James Brister's avatar
James Brister committed
283 284 285
				      dns_c_tkey_t *element,
				      isc_boolean_t copy);

286
isc_result_t	dns_c_tkey_new(isc_mem_t *mem, const char *domain,
287 288 289 290
			       isc_int32_t flags,
			       isc_int32_t protocol,
			       isc_int32_t algorithm,
			       const char *key, dns_c_tkey_t **newkey);
291 292
isc_result_t	dns_c_tkey_delete(dns_c_tkey_t **tkey);
isc_result_t	dns_c_tkey_copy(isc_mem_t *mem,
293 294
				dns_c_tkey_t **dest, dns_c_tkey_t *src);

295
isc_result_t	dns_c_tkey_getflags(dns_c_tkey_t *tkey,
James Brister's avatar
James Brister committed
296
				    isc_int32_t *flags);
297
isc_result_t	dns_c_tkey_getprotocol(dns_c_tkey_t *tkey,
James Brister's avatar
James Brister committed
298
				       isc_int32_t *protocol);
299
isc_result_t	dns_c_tkey_getalgorithm(dns_c_tkey_t *tkey,
James Brister's avatar
James Brister committed
300
					isc_int32_t *algorithm);
301
isc_result_t	dns_c_tkey_getkey(dns_c_tkey_t *tkey,
James Brister's avatar
James Brister committed
302
				  const char **key);
303
void		dns_c_tkey_print(FILE *fp, int indent, dns_c_tkey_t *tkey);
304 305 306



307
#endif /* DNS_CONFKEYS_H */