ldns  1.7.0
dnssec.h
Go to the documentation of this file.
1 /*
2  * dnssec.h -- defines for the Domain Name System (SEC) (DNSSEC)
3  *
4  * Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  *
8  * A bunch of defines that are used in the DNS
9  */
10 
23 #ifndef LDNS_DNSSEC_H
24 #define LDNS_DNSSEC_H
25 
26 #include <ldns/common.h>
27 #if LDNS_BUILD_CONFIG_HAVE_SSL
28 #include <openssl/ssl.h>
29 #include <openssl/evp.h>
30 #endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
31 #include <ldns/packet.h>
32 #include <ldns/keys.h>
33 #include <ldns/zone.h>
34 #include <ldns/resolver.h>
35 #include <ldns/dnssec_zone.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define LDNS_MAX_KEYLEN 2048
42 #define LDNS_DNSSEC_KEYPROTO 3
43 /* default time before sigs expire */
44 #define LDNS_DEFAULT_EXP_TIME 2419200 /* 4 weeks */
45 
47 #define LDNS_SIGNATURE_LEAVE_ADD_NEW 0
48 #define LDNS_SIGNATURE_LEAVE_NO_ADD 1
49 #define LDNS_SIGNATURE_REMOVE_ADD_NEW 2
50 #define LDNS_SIGNATURE_REMOVE_NO_ADD 3
51 
63  const ldns_rr_type type,
64  const ldns_rr_list *rrs);
65 
76 
85 
86 
87 #define LDNS_NSEC3_MAX_ITERATIONS 65535
88 
92 ldns_rdf *
94  ldns_rr_type qtype,
95  const ldns_rr_list *nsec3s);
96 
100 bool
102 
108 
113 
120 uint16_t ldns_calc_keytag(const ldns_rr *key);
121 
128 uint16_t ldns_calc_keytag_raw(const uint8_t* key, size_t keysize);
129 
130 #if LDNS_BUILD_CONFIG_HAVE_SSL
131 
137 DSA *ldns_key_buf2dsa(const ldns_buffer *key);
144 DSA *ldns_key_buf2dsa_raw(const unsigned char* key, size_t len);
145 
154 int ldns_digest_evp(const unsigned char* data, unsigned int len,
155  unsigned char* dest, const EVP_MD* md);
156 
164 EVP_PKEY* ldns_gost2pkey_raw(const unsigned char* key, size_t keylen);
165 
174 EVP_PKEY* ldns_ecdsa2pkey_raw(const unsigned char* key, size_t keylen, uint8_t algo);
175 
183 EVP_PKEY* ldns_ed255192pkey_raw(const unsigned char* key, size_t keylen);
184 
192 EVP_PKEY* ldns_ed4482pkey_raw(const unsigned char* key, size_t keylen);
193 
194 #endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
195 
196 #if LDNS_BUILD_CONFIG_HAVE_SSL
197 
203 RSA *ldns_key_buf2rsa(const ldns_buffer *key);
204 
211 RSA *ldns_key_buf2rsa_raw(const unsigned char* key, size_t len);
212 #endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
213 
222 ldns_rr *ldns_key_rr2ds(const ldns_rr *key, ldns_hash h);
223 
227 ldns_rdf *
229  size_t size,
230  ldns_rr_type nsec_type);
231 
239 int
241 
245 ldns_rr *
247  const ldns_dnssec_name *to,
248  ldns_rr_type nsec_type);
249 
250 
254 ldns_rr *
256  const ldns_dnssec_name *to,
257  const ldns_rdf *zone_name,
258  uint8_t algorithm,
259  uint8_t flags,
260  uint16_t iterations,
261  uint8_t salt_length,
262  const uint8_t *salt);
263 
271 ldns_rr * ldns_create_nsec(ldns_rdf *cur_owner, ldns_rdf *next_owner, ldns_rr_list *rrs);
272 
282 ldns_rdf *ldns_nsec3_hash_name(const ldns_rdf *name, uint8_t algorithm, uint16_t iterations, uint8_t salt_length, const uint8_t *salt);
283 
295  uint8_t algorithm,
296  uint8_t flags,
297  uint16_t iterations,
298  uint8_t salt_length,
299  const uint8_t *salt);
300 
301 /* this will NOT return the NSEC3 completed, you will have to run the
302  finalize function on the rrlist later! */
303 ldns_rr *
304 ldns_create_nsec3(const ldns_rdf *cur_owner,
305  const ldns_rdf *cur_zone,
306  const ldns_rr_list *rrs,
307  uint8_t algorithm,
308  uint8_t flags,
309  uint16_t iterations,
310  uint8_t salt_length,
311  const uint8_t *salt,
312  bool emptynonterminal);
313 
319 uint8_t ldns_nsec3_algorithm(const ldns_rr *nsec3_rr);
320 
324 uint8_t
325 ldns_nsec3_flags(const ldns_rr *nsec3_rr);
326 
332 bool ldns_nsec3_optout(const ldns_rr *nsec3_rr);
333 
339 uint16_t ldns_nsec3_iterations(const ldns_rr *nsec3_rr);
340 
346 ldns_rdf *ldns_nsec3_salt(const ldns_rr *nsec3_rr);
347 
353 uint8_t ldns_nsec3_salt_length(const ldns_rr *nsec3_rr);
354 
360 uint8_t *ldns_nsec3_salt_data(const ldns_rr *nsec3_rr);
361 
367 ldns_rdf *ldns_nsec3_next_owner(const ldns_rr *nsec3_rr);
368 
374 ldns_rdf *ldns_nsec3_bitmap(const ldns_rr *nsec3_rr);
375 
382 ldns_rdf *ldns_nsec3_hash_name_frm_nsec3(const ldns_rr *nsec, const ldns_rdf *name);
383 
390 bool ldns_nsec_bitmap_covers_type(const ldns_rdf* bitmap, ldns_rr_type type);
391 
400 
409 
420 bool ldns_nsec_covers_name(const ldns_rr *nsec, const ldns_rdf *name);
421 
422 #if LDNS_BUILD_CONFIG_HAVE_SSL
423 
434 ldns_status ldns_pkt_verify(const ldns_pkt *p, ldns_rr_type t, const ldns_rdf *o, const ldns_rr_list *k, const ldns_rr_list *s, ldns_rr_list *good_keys);
435 
448 ldns_status ldns_pkt_verify_time(const ldns_pkt *p, ldns_rr_type t, const ldns_rdf *o, const ldns_rr_list *k, const ldns_rr_list *s, time_t check_time, ldns_rr_list *good_keys);
449 
450 #endif
451 
457 
461 int
462 qsort_rr_compare_nsec3(const void *a, const void *b);
463 
467 void
469 
502 
503 #if LDNS_BUILD_CONFIG_HAVE_SSL
504 
512 ldns_rdf *
514  const long sig_len);
515 
526  const ldns_rdf *sig_rdf);
527 
542 ldns_rdf *
544  const long sig_len, int num_bytes);
545 
557  const ldns_rdf *sig_rdf);
558 
568 ldns_rdf *
569 ldns_convert_ed25519_rrsig_asn12rdf(const ldns_buffer *sig, long sig_len);
570 
582  const ldns_rdf *sig_rdf);
583 
593 ldns_rdf *
594 ldns_convert_ed448_rrsig_asn12rdf(const ldns_buffer *sig, long sig_len);
595 
607  const ldns_rdf *sig_rdf);
608 
609 #endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
610 
611 #ifdef __cplusplus
612 }
613 #endif
614 
615 #endif /* LDNS_DNSSEC_H */
uint16_t ldns_calc_keytag_raw(const uint8_t *key, size_t keysize)
Calculates keytag of DNSSEC key, operates on wireformat rdata.
Definition: dnssec.c:301
implementation of buffers to ease operations
Definition: buffer.h:50
ldns_rdf * ldns_nsec3_hash_name_frm_nsec3(const ldns_rr *nsec, const ldns_rdf *name)
Calculates the hashed name using the parameters of the given NSEC3 RR.
Definition: dnssec.c:1359
ldns_rr_list * ldns_dnssec_pkt_get_rrsigs_for_name_and_type(const ldns_pkt *pkt, const ldns_rdf *name, ldns_rr_type type)
Returns a ldns_rr_list containing the signatures covering the given name and type.
Definition: dnssec.c:217
ldns_rdf * ldns_convert_ed25519_rrsig_asn12rdf(const ldns_buffer *sig, long sig_len)
Converts the ECDSA signature from ASN1 representation (as used by OpenSSL) to raw signature data as u...
ldns_rdf * ldns_convert_dsa_rrsig_asn12rdf(const ldns_buffer *sig, const long sig_len)
Converts the DSA signature from ASN1 representation (RFC2459, as used by OpenSSL) to raw signature da...
Definition: dnssec.c:1734
signed char ldns_nsec_bitmap_covers_type(const ldns_rdf *bitmap, ldns_rr_type type)
Check if RR type t is enumerated and set in the RR type bitmap rdf.
Definition: dnssec.c:1384
List or Set of Resource Records.
Definition: rr.h:330
ldns_status ldns_convert_ed448_rrsig_rdf2asn1(ldns_buffer *target_buffer, const ldns_rdf *sig_rdf)
Converts the RRSIG signature RDF (from DNS) to a buffer with the signature in ASN1 format as openssl ...
DSA * ldns_key_buf2dsa(const ldns_buffer *key)
converts a buffer holding key material to a DSA key in openssl.
Definition: dnssec.c:330
ldns_rr * ldns_dnssec_get_rrsig_for_name_and_type(const ldns_rdf *name, const ldns_rr_type type, const ldns_rr_list *rrs)
Returns the first RRSIG rr that corresponds to the rrset with the given name and type.
Definition: dnssec.c:29
DSA * ldns_key_buf2dsa_raw(const unsigned char *key, size_t len)
Like ldns_key_buf2dsa, but uses raw buffer.
Definition: dnssec.c:337
ldns_status ldns_dnssec_chain_nsec3_list(ldns_rr_list *nsec3_rrs)
chains nsec3 list
Definition: dnssec.c:1622
int ldns_dnssec_default_delete_signatures(ldns_rr *sig, void *n)
Default callback function to always remove present signatures, but add no new ones.
enum ldns_enum_hash ldns_hash
Definition: keys.h:84
ldns_status ldns_convert_ed25519_rrsig_rdf2asn1(ldns_buffer *target_buffer, const ldns_rdf *sig_rdf)
Converts the RRSIG signature RDF (from DNS) to a buffer with the signature in ASN1 format as openssl ...
uint8_t * ldns_nsec3_salt_data(const ldns_rr *nsec3_rr)
Returns the salt bytes used in the given NSEC3 RR.
Definition: dnssec.c:1322
void ldns_rr_list_sort_nsec3(ldns_rr_list *unsorted)
sort nsec3 list
Definition: dnssec.c:1692
EVP_PKEY * ldns_ed4482pkey_raw(const unsigned char *key, size_t keylen)
Converts a holding buffer with key material to EVP PKEY in openssl.
int ldns_dnssec_default_replace_signatures(ldns_rr *sig, void *n)
Default callback function to always leave present signatures, and add new ones.
ldns_rdf * ldns_convert_ecdsa_rrsig_asn1len2rdf(const ldns_buffer *sig, const long sig_len, int num_bytes)
Converts the ECDSA signature from ASN1 representation (as used by OpenSSL) to raw signature data as u...
Definition: dnssec.c:1857
ldns_rr_list * ldns_dnssec_pkt_get_rrsigs_for_type(const ldns_pkt *pkt, ldns_rr_type type)
Returns a ldns_rr_list containing the signatures covering the given type.
Definition: dnssec.c:244
Resource Record.
Definition: rr.h:302
ldns_rdf * ldns_nsec3_next_owner(const ldns_rr *nsec3_rr)
Returns the first label of the next ownername in the NSEC3 chain (ie.
Definition: dnssec.c:1339
ldns_rr * ldns_create_nsec(ldns_rdf *cur_owner, ldns_rdf *next_owner, ldns_rr_list *rrs)
Create a NSEC record.
Definition: dnssec.c:951
uint8_t ldns_nsec3_flags(const ldns_rr *nsec3_rr)
Returns flags field.
Definition: dnssec.c:1266
ldns_status ldns_pkt_verify(const ldns_pkt *p, ldns_rr_type t, const ldns_rdf *o, const ldns_rr_list *k, const ldns_rr_list *s, ldns_rr_list *good_keys)
verify a packet
Definition: dnssec.c:1614
int qsort_rr_compare_nsec3(const void *a, const void *b)
compare for nsec3 sort
Definition: dnssec.c:1675
ldns_status ldns_pkt_verify_time(const ldns_pkt *p, ldns_rr_type t, const ldns_rdf *o, const ldns_rr_list *k, const ldns_rr_list *s, time_t check_time, ldns_rr_list *good_keys)
verify a packet
Definition: dnssec.c:1550
uint16_t ldns_nsec3_iterations(const ldns_rr *nsec3_rr)
Returns the number of hash iterations used in the given NSEC3 RR.
Definition: dnssec.c:1285
uint8_t ldns_nsec3_algorithm(const ldns_rr *nsec3_rr)
Returns the hash algorithm used in the given NSEC3 RR.
Definition: dnssec.c:1253
int ldns_dnssec_rrsets_contains_type(const ldns_dnssec_rrsets *rrsets, ldns_rr_type type)
returns whether a rrset of the given type is found in the rrsets.
Definition: dnssec.c:794
ldns_rr * ldns_dnssec_get_dnskey_for_rrsig(const ldns_rr *rrsig, const ldns_rr_list *rrs)
Returns the DNSKEY that corresponds to the given RRSIG rr from the list, if any.
Definition: dnssec.c:57
ldns_rdf * ldns_convert_ed448_rrsig_asn12rdf(const ldns_buffer *sig, long sig_len)
Converts the ECDSA signature from ASN1 representation (as used by OpenSSL) to raw signature data as u...
Defines the ldns_resolver structure, a stub resolver that can send queries and parse answers...
EVP_PKEY * ldns_gost2pkey_raw(const unsigned char *key, size_t keylen)
Converts a holding buffer with key material to EVP PKEY in openssl.
ldns_rr * ldns_dnssec_create_nsec(const ldns_dnssec_name *from, const ldns_dnssec_name *to, ldns_rr_type nsec_type)
Creates NSEC.
Definition: dnssec.c:808
void ldns_nsec3_add_param_rdfs(ldns_rr *rr, uint8_t algorithm, uint8_t flags, uint16_t iterations, uint8_t salt_length, const uint8_t *salt)
Sets all the NSEC3 options.
Definition: dnssec.c:1100
EVP_PKEY * ldns_ecdsa2pkey_raw(const unsigned char *key, size_t keylen, uint8_t algo)
Converts a holding buffer with key material to EVP PKEY in openssl.
RSA * ldns_key_buf2rsa_raw(const unsigned char *key, size_t len)
Like ldns_key_buf2rsa, but uses raw buffer.
Definition: dnssec.c:414
DNS packet.
Definition: packet.h:233
signed char ldns_nsec_covers_name(const ldns_rr *nsec, const ldns_rdf *name)
Checks coverage of NSEC(3) RR name span Remember that nsec and name must both be in canonical form (i...
Definition: dnssec.c:1499
int ldns_dnssec_default_add_to_signatures(ldns_rr *sig, void *n)
Default callback function to always leave present signatures, and add new ones.
int ldns_digest_evp(const unsigned char *data, unsigned int len, unsigned char *dest, const EVP_MD *md)
Utility function to calculate hash using generic EVP_MD pointer.
Definition: dnssec.c:482
enum ldns_enum_status ldns_status
Definition: error.h:134
zone.h
signed char ldns_dnssec_pkt_has_rrsigs(const ldns_pkt *pkt)
Checks whether the packet contains rrsigs.
Definition: dnssec.c:198
signed char ldns_nsec3_optout(const ldns_rr *nsec3_rr)
Returns true if the opt-out flag has been set in the given NSEC3 RR.
Definition: dnssec.c:1279
ldns_rdf * ldns_nsec3_bitmap(const ldns_rr *nsec3_rr)
Returns the bitmap specifying the covered types of the given NSEC3 RR.
Definition: dnssec.c:1349
Addendum to dnssec.h, this module contains key and algorithm definitions and functions.
ldns_rr * ldns_create_nsec3(const ldns_rdf *cur_owner, const ldns_rdf *cur_zone, const ldns_rr_list *rrs, uint8_t algorithm, uint8_t flags, uint16_t iterations, uint8_t salt_length, const uint8_t *salt, signed char emptynonterminal)
RSA * ldns_key_buf2rsa(const ldns_buffer *key)
converts a buffer holding key material to a RSA key in openssl.
Definition: dnssec.c:407
EVP_PKEY * ldns_ed255192pkey_raw(const unsigned char *key, size_t keylen)
Converts a holding buffer with key material to EVP PKEY in openssl.
ldns_rdf * ldns_nsec3_hash_name(const ldns_rdf *name, uint8_t algorithm, uint16_t iterations, uint8_t salt_length, const uint8_t *salt)
Calculates the hashed name using the given parameters.
Definition: dnssec.c:1001
Contains the definition of ldns_pkt and its parts, as well as functions to manipulate those...
ldns_status ldns_nsec_bitmap_set_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and sets the bit.
Definition: dnssec.c:1421
Resource record data field.
Definition: rdata.h:174
ldns_status ldns_convert_ecdsa_rrsig_rdf2asn1(ldns_buffer *target_buffer, const ldns_rdf *sig_rdf)
Converts the RRSIG signature RDF (from DNS) to a buffer with the signature in ASN1 format as openssl ...
Definition: dnssec.c:1895
Common definitions for LDNS.
ldns_status ldns_nsec_bitmap_clear_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and clears the bit.
Definition: dnssec.c:1459
ldns_rdf * ldns_nsec3_salt(const ldns_rr *nsec3_rr)
Returns the salt used in the given NSEC3 RR.
Definition: dnssec.c:1299
enum ldns_enum_rr_type ldns_rr_type
Definition: rr.h:239
ldns_rdf * ldns_dnssec_nsec3_closest_encloser(const ldns_rdf *qname, ldns_rr_type qtype, const ldns_rr_list *nsec3s)
Returns the dname of the closest (provable) encloser.
ldns_rdf * ldns_nsec_get_bitmap(const ldns_rr *nsec)
Returns the rdata field that contains the bitmap of the covered types of the given NSEC record...
Definition: dnssec.c:84
uint16_t ldns_calc_keytag(const ldns_rr *key)
calculates a keytag of a key for use in DNSSEC.
Definition: dnssec.c:271
uint8_t ldns_nsec3_salt_length(const ldns_rr *nsec3_rr)
Returns the length of the salt used in the given NSEC3 RR.
Definition: dnssec.c:1311
ldns_status ldns_convert_dsa_rrsig_rdf2asn1(ldns_buffer *target_buffer, const ldns_rdf *sig_rdf)
Converts the RRSIG signature RDF (in rfc2536 format) to a buffer with the signature in rfc2459 format...
Definition: dnssec.c:1795
int ldns_dnssec_default_leave_signatures(ldns_rr *sig, void *n)
Default callback function to always leave present signatures, and add no new ones for the keys of the...
ldns_rr * ldns_dnssec_create_nsec3(const ldns_dnssec_name *from, const ldns_dnssec_name *to, const ldns_rdf *zone_name, uint8_t algorithm, uint8_t flags, uint16_t iterations, uint8_t salt_length, const uint8_t *salt)
Creates NSEC3.
Definition: dnssec.c:862
ldns_rr * ldns_key_rr2ds(const ldns_rr *key, ldns_hash h)
returns a new DS rr that represents the given key rr.
Definition: dnssec.c:501
ldns_rdf * ldns_dnssec_create_nsec_bitmap(ldns_rr_type rr_type_list[], size_t size, ldns_rr_type nsec_type)
Create the type bitmap for an NSEC(3) record.
Definition: dnssec.c:712