tsig.h
Go to the documentation of this file.
/*
* Copyright (c) 2011 NLNet Labs. All rights reserved.
*
* Taken from NSD3 and adjusted for OpenDNSSEC, NLnet Labs.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WIRE_TSIG_H
#define WIRE_TSIG_H
#include "config.h"
#include "status.h"
#include "wire/buffer.h"
#include <ldns/ldns.h>
#define TSIG_ERROR_BADSIG 16
#define TSIG_ERROR_BADKEY 17
#define TSIG_ERROR_BADTIME 18
#define TSIG_HMAC_MD5 157
#define TSIG_HMAC_SHA1 158
#define TSIG_HMAC_SHA256 159
enum tsig_status_enum {
TSIG_NOT_PRESENT,
TSIG_OK,
TSIG_ERROR
};
typedef enum tsig_status_enum tsig_status;
typedef struct tsig_lookup_table_struct tsig_lookup_table;
struct tsig_lookup_table_struct
{
uint8_t id;
const char* short_name;
};
typedef struct tsig_key_struct tsig_key_type;
struct tsig_key_struct {
ldns_rdf* dname;
size_t size;
const uint8_t* data;
};
typedef struct tsig_algo_struct tsig_algo_type;
struct tsig_algo_struct {
const char* txt_name;
ldns_rdf* wf_name;
size_t max_digest_size;
const void* data;
/* create a new HMAC context */
void*(*hmac_create)(void);
/* initialize an HMAC context */
void(*hmac_init)(void* context, tsig_algo_type* algo,
tsig_key_type* key);
/* update the HMAC context */
void(*hmac_update)(void* context, const void* data, size_t size);
/* finalize digest */
void(*hmac_final)(void* context, uint8_t* digest, size_t* size);
};
typedef struct tsig_struct tsig_type;
struct tsig_struct {
tsig_type* next;
const char* name;
const char* algorithm;
const char* secret;
tsig_key_type* key;
};
typedef struct tsig_rr_struct tsig_rr_type;
struct tsig_rr_struct {
tsig_status status;
size_t position;
size_t response_count;
size_t update_since_last_prepare;
void* context;
tsig_algo_type* algo;
tsig_key_type* key;
size_t prior_mac_size;
uint8_t* prior_mac_data;
ldns_rdf* key_name;
ldns_rdf* algo_name;
uint16_t signed_time_high;
uint32_t signed_time_low;
uint16_t signed_time_fudge;
uint16_t mac_size;
uint8_t* mac_data;
uint16_t original_query_id;
uint16_t error_code;
uint16_t other_size;
uint8_t* other_data;
};
ods_status tsig_handler_init(void);
void tsig_handler_cleanup(void);
void tsig_handler_add_key(tsig_key_type* key);
void tsig_handler_add_algo(tsig_algo_type* algo);
tsig_type* tsig_create(char* name, char* algo,
char* secret);
tsig_type* tsig_lookup_by_name(tsig_type* tsig, const char* name);
tsig_algo_type* tsig_lookup_algo(const char* name);
tsig_rr_type* tsig_rr_create(void);
void tsig_rr_reset(tsig_rr_type* trr, tsig_algo_type* algo, tsig_key_type* key);
int tsig_rr_find(tsig_rr_type* trr, buffer_type* buffer);
int tsig_rr_parse(tsig_rr_type* trr, buffer_type* buffer);
int tsig_rr_lookup(tsig_rr_type* trr);
void tsig_rr_prepare(tsig_rr_type* trr);
void tsig_rr_update(tsig_rr_type* trr, buffer_type* buffer, size_t length);
void tsig_rr_sign(tsig_rr_type* trr);
int tsig_rr_verify(tsig_rr_type* trr);
void tsig_rr_append(tsig_rr_type* trr, buffer_type* buffer);
/*
* The amount of space to reserve in the response for the TSIG data.
* \param[in] trr TSIG RR
* \return size_t reserved space size
*
*/
size_t tsig_rr_reserved_space(tsig_rr_type *trr);
void tsig_rr_error(tsig_rr_type* trr);
const char* tsig_status2str(tsig_status status);
const char* tsig_strerror(uint16_t error);
void tsig_rr_free(tsig_rr_type* trr);
void tsig_rr_cleanup(tsig_rr_type* trr);
void tsig_cleanup(tsig_type* tsig);
#endif /* WIRE_TSIG_H */
tsig_rr_struct::algo
tsig_algo_type * algo
Definition: tsig.h:129
tsig_rr_struct::status
tsig_status status
Definition: tsig.h:124
tsig_algo_struct::max_digest_size
size_t max_digest_size
Definition: tsig.h:92
tsig_rr_struct::mac_size
uint16_t mac_size
Definition: tsig.h:139
tsig_rr_struct::signed_time_high
uint16_t signed_time_high
Definition: tsig.h:136
tsig_handler_add_key
void tsig_handler_add_key(tsig_key_type *key)
Definition: tsig.c:73
tsig_rr_struct::error_code
uint16_t error_code
Definition: tsig.h:142
tsig_rr_lookup
int tsig_rr_lookup(tsig_rr_type *trr)
Definition: tsig.c:469
tsig_struct
Definition: tsig.h:110
tsig_rr_sign
void tsig_rr_sign(tsig_rr_type *trr)
Definition: tsig.c:629
tsig_algo_struct
Definition: tsig.h:89
tsig_rr_struct::prior_mac_data
uint8_t * prior_mac_data
Definition: tsig.h:132
tsig_rr_struct
Definition: tsig.h:123
tsig_lookup_table_struct::short_name
const char * short_name
Definition: tsig.h:70
tsig_algo_struct::wf_name
ldns_rdf * wf_name
Definition: tsig.h:91
tsig_rr_struct::signed_time_fudge
uint16_t signed_time_fudge
Definition: tsig.h:138
tsig_algo_struct::data
const void * data
Definition: tsig.h:93
tsig_rr_struct::update_since_last_prepare
size_t update_since_last_prepare
Definition: tsig.h:127
tsig_lookup_by_name
tsig_type * tsig_lookup_by_name(tsig_type *tsig, const char *name)
Definition: tsig.c:235
tsig_rr_struct::other_data
uint8_t * other_data
Definition: tsig.h:144
tsig_key_struct
Definition: tsig.h:78
tsig_rr_verify
int tsig_rr_verify(tsig_rr_type *trr)
Definition: tsig.c:650
tsig_rr_struct::prior_mac_size
size_t prior_mac_size
Definition: tsig.h:131
tsig_strerror
const char * tsig_strerror(uint16_t error)
Definition: tsig.c:778
tsig_struct::algorithm
const char * algorithm
Definition: tsig.h:113
tsig_struct::key
tsig_key_type * key
Definition: tsig.h:115
tsig_cleanup
void tsig_cleanup(tsig_type *tsig)
Definition: tsig.c:847
tsig_rr_struct::key_name
ldns_rdf * key_name
Definition: tsig.h:134
tsig_rr_find
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:435
tsig_struct::next
tsig_type * next
Definition: tsig.h:111
TSIG_NOT_PRESENT
Definition: tsig.h:56
buffer_struct
Definition: buffer.h:112
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_OK
Definition: tsig.h:57
tsig_key_struct::size
size_t size
Definition: tsig.h:80
tsig_rr_reserved_space
size_t tsig_rr_reserved_space(tsig_rr_type *trr)
Definition: tsig.c:713
tsig_rr_struct::key
tsig_key_type * key
Definition: tsig.h:130
tsig_rr_struct::signed_time_low
uint32_t signed_time_low
Definition: tsig.h:137
tsig_key_struct::dname
ldns_rdf * dname
Definition: tsig.h:79
tsig_handler_cleanup
void tsig_handler_cleanup(void)
Definition: tsig.c:135
tsig_rr_update
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
Definition: tsig.c:559
tsig_rr_create
tsig_rr_type * tsig_rr_create(void)
Definition: tsig.c:274
tsig_lookup_table_struct::id
uint8_t id
Definition: tsig.h:69
tsig_rr_prepare
void tsig_rr_prepare(tsig_rr_type *trr)
Definition: tsig.c:537
tsig_status_enum
tsig_status_enum
Definition: tsig.h:55
tsig_struct::secret
const char * secret
Definition: tsig.h:114
tsig_lookup_algo
tsig_algo_type * tsig_lookup_algo(const char *name)
Definition: tsig.c:257
tsig_rr_struct::position
size_t position
Definition: tsig.h:125
buffer.h
tsig_handler_add_algo
void tsig_handler_add_algo(tsig_algo_type *algo)
Definition: tsig.c:93
tsig_rr_append
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:672
tsig_rr_struct::other_size
uint16_t other_size
Definition: tsig.h:143
tsig_rr_cleanup
void tsig_rr_cleanup(tsig_rr_type *trr)
Definition: tsig.c:832
tsig_rr_struct::context
void * context
Definition: tsig.h:128
tsig_rr_free
void tsig_rr_free(tsig_rr_type *trr)
Definition: tsig.c:811
tsig_create
tsig_type * tsig_create(char *name, char *algo, char *secret)
Definition: tsig.c:208
TSIG_ERROR
Definition: tsig.h:58
tsig_rr_struct::algo_name
ldns_rdf * algo_name
Definition: tsig.h:135
tsig_rr_struct::response_count
size_t response_count
Definition: tsig.h:126
tsig_key_struct::data
const uint8_t * data
Definition: tsig.h:81
tsig_status2str
const char * tsig_status2str(tsig_status status)
Definition: tsig.c:759
tsig_rr_error
void tsig_rr_error(tsig_rr_type *trr)
Definition: tsig.c:742
tsig_struct::name
const char * name
Definition: tsig.h:112
tsig_algo_struct::txt_name
const char * txt_name
Definition: tsig.h:90
tsig_status
enum tsig_status_enum tsig_status
Definition: tsig.h:60
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_struct::original_query_id
uint16_t original_query_id
Definition: tsig.h:141
tsig_lookup_table_struct
Definition: tsig.h:67