OpenDNSSEC-signer  2.1.5
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 };
61 
68 {
69  uint8_t id;
70  const char* short_name;
71 };
72 
79  ldns_rdf* dname;
80  size_t size;
81  const uint8_t* data;
82 };
83 
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 
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 ods_status tsig_handler_init(void);
154 
159 void tsig_handler_cleanup(void);
160 
167 
174 
184 tsig_type* tsig_create(char* name, char* algo,
185  char* secret);
186 
194 tsig_type* tsig_lookup_by_name(tsig_type* tsig, const char* name);
195 
202 tsig_algo_type* tsig_lookup_algo(const char* name);
203 
211 
220 
228 int tsig_rr_find(tsig_rr_type* trr, buffer_type* buffer);
229 
237 int tsig_rr_parse(tsig_rr_type* trr, buffer_type* buffer);
238 
245 int tsig_rr_lookup(tsig_rr_type* trr);
246 
252 void tsig_rr_prepare(tsig_rr_type* trr);
253 
263 void tsig_rr_update(tsig_rr_type* trr, buffer_type* buffer, size_t length);
264 
270 void tsig_rr_sign(tsig_rr_type* trr);
271 
278 int tsig_rr_verify(tsig_rr_type* trr);
279 
286 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  */
295 
301 void tsig_rr_error(tsig_rr_type* trr);
302 
309 const char* tsig_status2str(tsig_status status);
310 
317 const char* tsig_strerror(uint16_t error);
318 
324 void tsig_rr_free(tsig_rr_type* trr);
325 
331 void tsig_rr_cleanup(tsig_rr_type* trr);
332 
339 void tsig_cleanup(tsig_type* tsig);
340 
341 #endif /* WIRE_TSIG_H */
TSIG_ERROR
@ TSIG_ERROR
Definition: tsig.h:58
tsig_rr_struct::algo_name
ldns_rdf * algo_name
Definition: tsig.h:135
tsig_key_struct::data
const uint8_t * data
Definition: tsig.h:81
tsig_algo_struct::hmac_update
void(* hmac_update)(void *context, const void *data, size_t size)
Definition: tsig.h:100
tsig_handler_cleanup
void tsig_handler_cleanup(void)
Definition: tsig.c:135
tsig_rr_struct::error_code
uint16_t error_code
Definition: tsig.h:142
tsig_rr_struct::signed_time_high
uint16_t signed_time_high
Definition: tsig.h:136
tsig_algo_struct::txt_name
const char * txt_name
Definition: tsig.h:90
tsig_struct::name
const char * name
Definition: tsig.h:112
tsig_strerror
const char * tsig_strerror(uint16_t error)
Definition: tsig.c:778
tsig_lookup_table_struct::id
uint8_t id
Definition: tsig.h:69
tsig_rr_append
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:672
tsig_struct
Definition: tsig.h:110
tsig_algo_struct::hmac_init
void(* hmac_init)(void *context, tsig_algo_type *algo, tsig_key_type *key)
Definition: tsig.h:97
tsig_rr_struct::mac_size
uint16_t mac_size
Definition: tsig.h:139
tsig_rr_reset
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
Definition: tsig.c:292
tsig_handler_init
ods_status tsig_handler_init(void)
Definition: tsig.c:116
tsig_rr_free
void tsig_rr_free(tsig_rr_type *trr)
Definition: tsig.c:811
tsig_status
enum tsig_status_enum tsig_status
Definition: tsig.h:60
tsig_struct::key
tsig_key_type * key
Definition: tsig.h:115
tsig_rr_struct
Definition: tsig.h:123
tsig_handler_add_key
void tsig_handler_add_key(tsig_key_type *key)
Definition: tsig.c:73
tsig_rr_error
void tsig_rr_error(tsig_rr_type *trr)
Definition: tsig.c:742
tsig_rr_reserved_space
size_t tsig_rr_reserved_space(tsig_rr_type *trr)
Definition: tsig.c:713
tsig_rr_struct::prior_mac_data
uint8_t * prior_mac_data
Definition: tsig.h:132
tsig_rr_struct::signed_time_fudge
uint16_t signed_time_fudge
Definition: tsig.h:138
tsig_rr_struct::update_since_last_prepare
size_t update_since_last_prepare
Definition: tsig.h:127
tsig_rr_struct::other_data
uint8_t * other_data
Definition: tsig.h:144
tsig_algo_struct::wf_name
ldns_rdf * wf_name
Definition: tsig.h:91
tsig_rr_lookup
int tsig_rr_lookup(tsig_rr_type *trr)
Definition: tsig.c:469
tsig_struct::next
tsig_type * next
Definition: tsig.h:111
tsig_algo_struct::data
const void * data
Definition: tsig.h:93
tsig_rr_struct::prior_mac_size
size_t prior_mac_size
Definition: tsig.h:131
tsig_rr_prepare
void tsig_rr_prepare(tsig_rr_type *trr)
Definition: tsig.c:537
tsig_struct::algorithm
const char * algorithm
Definition: tsig.h:113
tsig_rr_sign
void tsig_rr_sign(tsig_rr_type *trr)
Definition: tsig.c:629
tsig_rr_create
tsig_rr_type * tsig_rr_create(void)
Definition: tsig.c:274
tsig_rr_cleanup
void tsig_rr_cleanup(tsig_rr_type *trr)
Definition: tsig.c:832
tsig_lookup_table_struct
Definition: tsig.h:67
tsig_algo_struct
Definition: tsig.h:89
buffer_struct
Definition: buffer.h:112
tsig_status_enum
tsig_status_enum
Definition: tsig.h:55
tsig_rr_struct::key_name
ldns_rdf * key_name
Definition: tsig.h:134
tsig_rr_struct::position
size_t position
Definition: tsig.h:125
tsig_algo_struct::max_digest_size
size_t max_digest_size
Definition: tsig.h:92
tsig_lookup_by_name
tsig_type * tsig_lookup_by_name(tsig_type *tsig, const char *name)
Definition: tsig.c:235
tsig_status2str
const char * tsig_status2str(tsig_status status)
Definition: tsig.c:759
buffer.h
tsig_rr_verify
int tsig_rr_verify(tsig_rr_type *trr)
Definition: tsig.c:650
tsig_rr_struct::signed_time_low
uint32_t signed_time_low
Definition: tsig.h:137
tsig_create
tsig_type * tsig_create(char *name, char *algo, char *secret)
Definition: tsig.c:208
tsig_rr_struct::key
tsig_key_type * key
Definition: tsig.h:130
tsig_key_struct::size
size_t size
Definition: tsig.h:80
TSIG_NOT_PRESENT
@ TSIG_NOT_PRESENT
Definition: tsig.h:56
tsig_rr_struct::mac_data
uint8_t * mac_data
Definition: tsig.h:140
tsig_rr_parse
int tsig_rr_parse(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:322
tsig_struct::secret
const char * secret
Definition: tsig.h:114
tsig_key_struct
Definition: tsig.h:78
tsig_cleanup
void tsig_cleanup(tsig_type *tsig)
Definition: tsig.c:847
tsig_algo_struct::hmac_final
void(* hmac_final)(void *context, uint8_t *digest, size_t *size)
Definition: tsig.h:102
tsig_rr_find
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:435
tsig_rr_update
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
Definition: tsig.c:559
TSIG_OK
@ TSIG_OK
Definition: tsig.h:57
tsig_rr_struct::original_query_id
uint16_t original_query_id
Definition: tsig.h:141
tsig_key_struct::dname
ldns_rdf * dname
Definition: tsig.h:79
tsig_lookup_table_struct::short_name
const char * short_name
Definition: tsig.h:70
tsig_lookup_algo
tsig_algo_type * tsig_lookup_algo(const char *name)
Definition: tsig.c:257
tsig_rr_struct::status
tsig_status status
Definition: tsig.h:124
tsig_rr_struct::response_count
size_t response_count
Definition: tsig.h:126
tsig_rr_struct::other_size
uint16_t other_size
Definition: tsig.h:143
tsig_rr_struct::context
void * context
Definition: tsig.h:128
tsig_rr_struct::algo
tsig_algo_type * algo
Definition: tsig.h:129
tsig_handler_add_algo
void tsig_handler_add_algo(tsig_algo_type *algo)
Definition: tsig.c:93