OpenDNSSEC-signer  2.1.7
tsig.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 NLNet Labs. All rights reserved.
3  *
4  * Taken from NSD3 and adjusted for OpenDNSSEC, NLnet Labs.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
34 #ifndef WIRE_TSIG_H
35 #define WIRE_TSIG_H
36 
37 #include "config.h"
38 #include "status.h"
39 #include "wire/buffer.h"
40 
41 #include <ldns/ldns.h>
42 
43 #define TSIG_ERROR_BADSIG 16
44 #define TSIG_ERROR_BADKEY 17
45 #define TSIG_ERROR_BADTIME 18
46 
47 #define TSIG_HMAC_MD5 157
48 #define TSIG_HMAC_SHA1 158
49 #define TSIG_HMAC_SHA256 159
50 
59 };
60 typedef enum tsig_status_enum tsig_status;
61 
68 {
69  uint8_t id;
70  const char* short_name;
71 };
72 
77 typedef struct tsig_key_struct tsig_key_type;
79  ldns_rdf* dname;
80  size_t size;
81  const uint8_t* data;
82 };
83 
88 typedef struct tsig_algo_struct tsig_algo_type;
90  const char* txt_name;
91  ldns_rdf* wf_name;
93  const void* data;
94  /* create a new HMAC context */
95  void*(*hmac_create)(void);
96  /* initialize an HMAC context */
97  void(*hmac_init)(void* context, tsig_algo_type* algo,
98  tsig_key_type* key);
99  /* update the HMAC context */
100  void(*hmac_update)(void* context, const void* data, size_t size);
101  /* finalize digest */
102  void(*hmac_final)(void* context, uint8_t* digest, size_t* size);
103 };
104 
109 typedef struct tsig_struct tsig_type;
110 struct tsig_struct {
112  const char* name;
113  const char* algorithm;
114  const char* secret;
116 };
117 
122 typedef struct tsig_rr_struct tsig_rr_type;
125  size_t position;
128  void* context;
132  uint8_t* prior_mac_data;
133 
134  ldns_rdf* key_name;
135  ldns_rdf* algo_name;
137  uint32_t signed_time_low;
139  uint16_t mac_size;
140  uint8_t* mac_data;
142  uint16_t error_code;
143  uint16_t other_size;
144  uint8_t* other_data;
145 };
146 
153 extern ods_status tsig_handler_init(void);
154 
159 extern void tsig_handler_cleanup(void);
160 
166 extern void tsig_handler_add_key(tsig_key_type* key);
167 
173 extern void tsig_handler_add_algo(tsig_algo_type* algo);
174 
184 extern tsig_type* tsig_create(char* name, char* algo,
185  char* secret);
186 
194 extern tsig_type* tsig_lookup_by_name(tsig_type* tsig, const char* name);
195 
202 extern tsig_algo_type* tsig_lookup_algo(const char* name);
203 
210 extern tsig_rr_type* tsig_rr_create(void);
211 
219 extern void tsig_rr_reset(tsig_rr_type* trr, tsig_algo_type* algo, tsig_key_type* key);
220 
228 extern int tsig_rr_find(tsig_rr_type* trr, buffer_type* buffer);
229 
237 extern int tsig_rr_parse(tsig_rr_type* trr, buffer_type* buffer);
238 
245 extern int tsig_rr_lookup(tsig_rr_type* trr);
246 
252 extern void tsig_rr_prepare(tsig_rr_type* trr);
253 
263 extern void tsig_rr_update(tsig_rr_type* trr, buffer_type* buffer, size_t length);
264 
270 extern void tsig_rr_sign(tsig_rr_type* trr);
271 
278 extern int tsig_rr_verify(tsig_rr_type* trr);
279 
286 extern void tsig_rr_append(tsig_rr_type* trr, buffer_type* buffer);
287 
288 /*
289  * The amount of space to reserve in the response for the TSIG data.
290  * \param[in] trr TSIG RR
291  * \return size_t reserved space size
292  *
293  */
294 extern size_t tsig_rr_reserved_space(tsig_rr_type *trr);
295 
301 extern void tsig_rr_error(tsig_rr_type* trr);
302 
309 extern const char* tsig_status2str(tsig_status status);
310 
317 extern const char* tsig_strerror(uint16_t error);
318 
324 extern void tsig_rr_free(tsig_rr_type* trr);
325 
331 extern void tsig_rr_cleanup(tsig_rr_type* trr);
332 
339 extern void tsig_cleanup(tsig_type* tsig);
340 
341 #endif /* WIRE_TSIG_H */
ldns_rdf * wf_name
Definition: tsig.h:91
const void * data
Definition: tsig.h:93
size_t max_digest_size
Definition: tsig.h:92
void(* hmac_final)(void *context, uint8_t *digest, size_t *size)
Definition: tsig.h:102
const char * txt_name
Definition: tsig.h:90
void(* hmac_init)(void *context, tsig_algo_type *algo, tsig_key_type *key)
Definition: tsig.h:97
void(* hmac_update)(void *context, const void *data, size_t size)
Definition: tsig.h:100
ldns_rdf * dname
Definition: tsig.h:79
const uint8_t * data
Definition: tsig.h:81
size_t size
Definition: tsig.h:80
const char * short_name
Definition: tsig.h:70
tsig_algo_type * algo
Definition: tsig.h:129
void * context
Definition: tsig.h:128
size_t prior_mac_size
Definition: tsig.h:131
size_t position
Definition: tsig.h:125
tsig_key_type * key
Definition: tsig.h:130
uint16_t error_code
Definition: tsig.h:142
size_t response_count
Definition: tsig.h:126
uint16_t other_size
Definition: tsig.h:143
size_t update_since_last_prepare
Definition: tsig.h:127
uint16_t signed_time_high
Definition: tsig.h:136
uint32_t signed_time_low
Definition: tsig.h:137
uint8_t * mac_data
Definition: tsig.h:140
tsig_status status
Definition: tsig.h:124
uint8_t * prior_mac_data
Definition: tsig.h:132
uint16_t original_query_id
Definition: tsig.h:141
uint16_t signed_time_fudge
Definition: tsig.h:138
ldns_rdf * algo_name
Definition: tsig.h:135
uint8_t * other_data
Definition: tsig.h:144
uint16_t mac_size
Definition: tsig.h:139
ldns_rdf * key_name
Definition: tsig.h:134
tsig_key_type * key
Definition: tsig.h:115
const char * secret
Definition: tsig.h:114
const char * name
Definition: tsig.h:112
const char * algorithm
Definition: tsig.h:113
tsig_type * next
Definition: tsig.h:111
int tsig_rr_lookup(tsig_rr_type *trr)
Definition: tsig.c:469
void tsig_rr_cleanup(tsig_rr_type *trr)
Definition: tsig.c:832
tsig_type * tsig_lookup_by_name(tsig_type *tsig, const char *name)
Definition: tsig.c:235
ods_status tsig_handler_init(void)
Definition: tsig.c:116
int tsig_rr_verify(tsig_rr_type *trr)
Definition: tsig.c:650
tsig_algo_type * tsig_lookup_algo(const char *name)
Definition: tsig.c:257
const char * tsig_status2str(tsig_status status)
Definition: tsig.c:759
void tsig_rr_error(tsig_rr_type *trr)
Definition: tsig.c:742
size_t tsig_rr_reserved_space(tsig_rr_type *trr)
Definition: tsig.c:713
tsig_rr_type * tsig_rr_create(void)
Definition: tsig.c:274
tsig_type * tsig_create(char *name, char *algo, char *secret)
Definition: tsig.c:208
void tsig_handler_add_algo(tsig_algo_type *algo)
Definition: tsig.c:93
void tsig_cleanup(tsig_type *tsig)
Definition: tsig.c:847
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:672
void tsig_rr_sign(tsig_rr_type *trr)
Definition: tsig.c:629
int tsig_rr_parse(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:322
void tsig_rr_free(tsig_rr_type *trr)
Definition: tsig.c:811
void tsig_handler_add_key(tsig_key_type *key)
Definition: tsig.c:73
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
Definition: tsig.c:292
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
Definition: tsig.c:559
void tsig_rr_prepare(tsig_rr_type *trr)
Definition: tsig.c:537
tsig_status_enum
Definition: tsig.h:55
@ TSIG_OK
Definition: tsig.h:57
@ TSIG_ERROR
Definition: tsig.h:58
@ TSIG_NOT_PRESENT
Definition: tsig.h:56
enum tsig_status_enum tsig_status
Definition: tsig.h:60
void tsig_handler_cleanup(void)
Definition: tsig.c:135
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:435
const char * tsig_strerror(uint16_t error)
Definition: tsig.c:778