OpenDNSSEC-signer  1.4.1
tsig.h
Go to the documentation of this file.
1 /*
2  * $Id: tsig.h 4958 2011-04-18 07:11:09Z matthijs $
3  *
4  * Copyright (c) 2011 NLNet Labs. All rights reserved.
5  *
6  * Taken from NSD3 and adjusted for OpenDNSSEC, NLnet Labs.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
36 #ifndef WIRE_TSIG_H
37 #define WIRE_TSIG_H
38 
39 #include "config.h"
40 #include "shared/allocator.h"
41 #include "shared/status.h"
42 #include "wire/buffer.h"
43 
44 #include <ldns/ldns.h>
45 
46 #define TSIG_ERROR_BADSIG 16
47 #define TSIG_ERROR_BADKEY 17
48 #define TSIG_ERROR_BADTIME 18
49 
50 #define TSIG_HMAC_MD5 157
51 #define TSIG_HMAC_SHA1 158
52 #define TSIG_HMAC_SHA256 159
53 
62 };
64 
71 {
72  uint8_t id;
73  const char* short_name;
74 };
75 
82  ldns_rdf* dname;
83  size_t size;
84  const uint8_t* data;
85 };
86 
93  const char* txt_name;
94  ldns_rdf* wf_name;
96  const void* data;
97  /* create a new HMAC context */
98  void*(*hmac_create)(allocator_type* allocator);
99  /* initialize an HMAC context */
100  void(*hmac_init)(void* context, tsig_algo_type* algo,
101  tsig_key_type* key);
102  /* update the HMAC context */
103  void(*hmac_update)(void* context, const void* data, size_t size);
104  /* finalize digest */
105  void(*hmac_final)(void* context, uint8_t* digest, size_t* size);
106 };
107 
112 typedef struct tsig_struct tsig_type;
113 struct tsig_struct {
115  const char* name;
116  const char* algorithm;
117  const char* secret;
119 };
120 
129  size_t position;
132  void* context;
136  uint8_t* prior_mac_data;
137 
138  ldns_rdf* key_name;
139  ldns_rdf* algo_name;
141  uint32_t signed_time_low;
143  uint16_t mac_size;
144  uint8_t* mac_data;
146  uint16_t error_code;
147  uint16_t other_size;
148  uint8_t* other_data;
149 };
150 
158 
163 void tsig_handler_cleanup(void);
164 
171 
178 
188 tsig_type* tsig_create(allocator_type* allocator, char* name, char* algo,
189  char* secret);
190 
198 tsig_type* tsig_lookup_by_name(tsig_type* tsig, const char* name);
199 
206 tsig_algo_type* tsig_lookup_algo(const char* name);
207 
215 
224 
232 int tsig_rr_find(tsig_rr_type* trr, buffer_type* buffer);
233 
241 int tsig_rr_parse(tsig_rr_type* trr, buffer_type* buffer);
242 
249 int tsig_rr_lookup(tsig_rr_type* trr);
250 
256 void tsig_rr_prepare(tsig_rr_type* trr);
257 
267 void tsig_rr_update(tsig_rr_type* trr, buffer_type* buffer, size_t length);
268 
274 void tsig_rr_sign(tsig_rr_type* trr);
275 
282 int tsig_rr_verify(tsig_rr_type* trr);
283 
290 void tsig_rr_append(tsig_rr_type* trr, buffer_type* buffer);
291 
292 /*
293  * The amount of space to reserve in the response for the TSIG data.
294  * \param[in] trr TSIG RR
295  * \return size_t reserved space size
296  *
297  */
299 
305 void tsig_rr_error(tsig_rr_type* trr);
306 
313 const char* tsig_status2str(tsig_status status);
314 
321 const char* tsig_strerror(uint16_t error);
322 
328 void tsig_rr_free(tsig_rr_type* trr);
329 
335 void tsig_rr_cleanup(tsig_rr_type* trr);
336 
343 void tsig_cleanup(tsig_type* tsig, allocator_type* allocator);
344 
345 #endif /* WIRE_TSIG_H */