Update to ldns-1.6.7
[dragonfly.git] / contrib / ldns / ldns / tsig.h
1 /*
2  * tsig.h -- defines for TSIG [RFC2845]
3  *
4  * Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  */
8
9 #ifndef LDNS_TSIG_H
10 #define LDNS_TSIG_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 /**
17  * \file
18  *
19  * Defines functions for TSIG usage
20  */
21
22
23 /**
24  * Contains credentials for TSIG
25 */
26 typedef struct ldns_tsig_credentials_struct
27 {
28     char *algorithm;
29     char *keyname;
30     char *keydata;
31     /* XXX More eventually. */
32 } ldns_tsig_credentials;
33
34 char *ldns_tsig_algorithm(ldns_tsig_credentials *);
35 char *ldns_tsig_keyname(ldns_tsig_credentials *);
36 char *ldns_tsig_keydata(ldns_tsig_credentials *);
37 char *ldns_tsig_keyname_clone(ldns_tsig_credentials *);
38 char *ldns_tsig_keydata_clone(ldns_tsig_credentials *);
39
40 /**
41  * verifies the tsig rr for the given packet and key.
42  * The wire must be given too because tsig does not sign normalized packets.
43  * \param[in] pkt the packet to verify
44  * \param[in] wire needed to verify the mac
45  * \param[in] wire_size size of wire
46  * \param[in] key_name the name of the shared key
47  * \param[in] key_data the key in base 64 format
48  * \param[in] mac original mac
49  * \param[in] tsig_timers_only must be zero for the first packet and positive for subsequent packets. If zero, all digest
50    components are used to verify the _mac. If non-zero, only the TSIG timers are used to verify the mac.
51  * \return true if tsig is correct, false if not, or if tsig is not set
52  */
53 bool ldns_pkt_tsig_verify(ldns_pkt *pkt, uint8_t *wire, size_t wire_size, const char *key_name, const char *key_data, ldns_rdf *mac);
54
55 bool ldns_pkt_tsig_verify_next(ldns_pkt *pkt, uint8_t *wire, size_t wire_size, const char *key_name, const char *key_data, ldns_rdf *mac,
56     int tsig_timers_only);
57
58 /**
59  * creates a tsig rr for the given packet and key.
60  * \param[in] pkt the packet to sign
61  * \param[in] key_name the name of the shared key
62  * \param[in] key_data the key in base 64 format
63  * \param[in] fudge seconds of error permitted in time signed
64  * \param[in] algorithm_name the name of the algorithm used
65  * \param[in] query_mac is added to the digest if not NULL (so NULL is for signing queries, not NULL is for signing answers)
66  * \param[in] tsig_timers_only must be zero for the first packet and positive for subsequent packets. If zero, all digest
67    components are used to create the query_mac. If non-zero, only the TSIG timers are used to create the query_mac.
68  * \return status (OK if success)
69  */
70 ldns_status ldns_pkt_tsig_sign(ldns_pkt *pkt, const char *key_name, const char *key_data, uint16_t fudge,
71     const char *algorithm_name, ldns_rdf *query_mac);
72
73 ldns_status ldns_pkt_tsig_sign_next(ldns_pkt *pkt, const char *key_name, const char *key_data, uint16_t fudge,
74     const char *algorithm_name, ldns_rdf *query_mac, int tsig_timers_only);
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif /* LDNS_TSIG_H */