12 #include <openssl/ssl.h> 13 #include <openssl/evp.h> 14 #include <openssl/rand.h> 15 #include <openssl/err.h> 16 #include <openssl/md5.h> 67 fprintf(out,
";; rcode: %s\n", rcode->
name);
71 if (rr_descriptor && rr_descriptor->
_name) {
72 fprintf(out,
";; qtype: %s\n", rr_descriptor->
_name);
74 fprintf(out,
"TYPE%u",
78 fprintf(out,
";; NODATA response\n");
80 fprintf(out,
"rrset:\n");
82 fprintf(out,
"sigs:\n");
84 fprintf(out,
"---\n");
86 fprintf(out,
"<no data>\n");
209 printf(
"There were already sigs!\n");
211 printf(
"replacing the old sigs\n");
242 possible_parent_name,
283 ldns_rdf *name = NULL, *key_name = NULL;
287 bool other_rrset =
false;
411 return ldns_dnssec_build_data_chain_nokeyname(res,
418 ldns_dnssec_build_data_chain_dnskey(res,
427 ldns_dnssec_build_data_chain_other(res,
446 if(!new_tree)
return NULL;
448 new_tree->
rrset = NULL;
475 if (parent > result) {
484 print_tabs(FILE *out,
size_t nr, uint8_t *map,
size_t treedepth)
487 for (i = 0; i < nr; i++) {
489 fprintf(out,
"|---");
490 }
else if (map && i < treedepth && map[i] == 1) {
499 ldns_dnssec_trust_tree_print_sm_fmt(FILE *out,
516 memset(sibmap, 0, treedepth);
522 print_tabs(out, tabs, sibmap, treedepth);
526 if (descriptor->
_name) {
527 fprintf(out,
" (%s", descriptor->
_name);
529 fprintf(out,
" (TYPE%d",
534 fprintf(out,
" keytag: %u",
536 fprintf(out,
" alg: ");
538 fprintf(out,
" flags: ");
541 fprintf(out,
" keytag: ");
543 fprintf(out,
" digest type: ");
556 if (tree->
parent_count > 1 && i < tree->parent_count - 1) {
567 print_tabs(out, tabs + 1, sibmap, treedepth);
571 fprintf(out,
"Existence of DS is denied by:\n");
573 fprintf(out,
"Existence is denied by:\n");
578 fprintf(out,
"Existence of DS is denied by:\n");
580 print_tabs(out, tabs + 1, sibmap, treedepth);
582 "Error in denial of existence: %s\n",
589 print_tabs(out, tabs + 1, sibmap, treedepth);
596 printf(
"; SSL Error: ");
597 ERR_load_crypto_strings();
598 ERR_print_errors_fp(stdout);
603 parent_signature[i]);
604 printf(
"For RRset:\n");
607 printf(
"With key:\n");
611 ldns_dnssec_trust_tree_print_sm_fmt(out, fmt,
619 print_tabs(out, tabs, sibmap, treedepth);
620 fprintf(out,
"<no data>\n");
623 fprintf(out,
"<null pointer>\n");
637 ldns_dnssec_trust_tree_print_sm_fmt(out, fmt,
638 tree, tabs, extended, NULL, 0);
648 tree, tabs, extended);
696 if (data_chain && data_chain->
rrset) {
697 cur_rrset = data_chain->
rrset;
710 new_tree->
rr = cur_rr;
711 new_tree->
rrset = cur_rrset;
765 new_tree, data_chain,
772 new_tree, data_chain, check_time);
810 tmp_rrset = cur_rrset;
818 assert(tmp_rrset == cur_rrset);
838 if (tmp_rrset && tmp_rrset != cur_rrset
846 if (cur_parent_rr == new_tree->
parents[i]->
rr) {
874 new_tree, data_chain, cur_sig_rr, ldns_time(NULL));
896 if (cur_parent_rr != cur_rr &&
901 cur_parent_tree->
rr = cur_parent_rr;
902 cur_parent_tree->
rrset = cur_rrset;
904 cur_rrset, cur_sig_rr,
905 cur_parent_rr, check_time);
907 cur_parent_tree, cur_sig_rr, cur_status);
920 new_tree, data_chain, cur_rr, cur_sig_rr, ldns_time(NULL));
973 new_tree, data_chain, cur_rr, ldns_time(NULL));
1022 cur_parent_tree, NULL, result);
1032 new_tree, data_chain, ldns_time(NULL));
1077 result = parent_result;
1101 if (!rrset || !rrsig || !keys) {
1119 keys, check_time, good_keys);
1130 return verify_result;
1147 if (!rrset || !rrsig || !keys) {
1177 return verify_result;
1193 if (res && domain && keys) {
1196 domain, keys, check_time))) {
1203 while (parent_domain &&
1240 if (parent_domain) {
1245 return trusted_keys;
1255 res, domain, keys, ldns_time(NULL), status);
1268 uint16_t key_i; uint16_t key_j; uint16_t key_k;
1269 uint16_t sig_i;
ldns_rr * cur_sig;
1329 return trusted_keys;
1349 return trusted_keys;
1358 res, domain, keys, ldns_time(NULL));
1406 return trusted_keys;
1426 uint16_t sig_i; uint16_t key_i;
1431 if (!res || !rrset || !rrsigs) {
1465 if (validating_keys) {
1488 res, rrset, rrsigs, ldns_time(NULL), validating_keys);
1505 bool name_covered =
false;
1506 bool type_covered =
false;
1507 bool wildcard_covered =
false;
1508 bool wildcard_type_covered =
false;
1531 wildcard_covered =
true;
1536 type_covered =
true;
1540 name_covered =
true;
1547 wildcard_type_covered =
true;
1552 wildcard_covered =
true;
1559 if (type_covered || !name_covered) {
1563 if (wildcard_type_covered || !wildcard_covered) {
1576 ,
bool packet_nodata
1583 bool wildcard_covered =
false;
1587 ldns_rdf *next_closer = next_closer;
1604 if(!closest_encloser) {
1613 hashed_wildcard_name =
1620 hashed_wildcard_name)) {
1621 wildcard_covered =
true;
1629 if (! wildcard_covered) {
1668 if(!closest_encloser) {
1675 hashed_wildcard_name =
1739 if(!closest_encloser) {
1749 hashed_next_closer = hashed_name;
1769 hashed_next_closer) &&
1805 rr, nsecs, rrsigs, packet_rcode,
1806 packet_qtype, packet_nodata, NULL
1815 uint8_t asn[37] = { 0x30, 0x63, 0x30, 0x1c, 0x06, 0x06, 0x2a, 0x85,
1816 0x03, 0x02, 0x02, 0x13, 0x30, 0x12, 0x06, 0x07, 0x2a, 0x85,
1817 0x03, 0x02, 0x02, 0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03,
1818 0x02, 0x02, 0x1e, 0x01, 0x03, 0x43, 0x00, 0x04, 0x40};
1819 unsigned char encoded[37+64];
1820 const unsigned char* pp;
1827 memmove(encoded, asn, 37);
1828 memmove(encoded+37, key, 64);
1829 pp = (
unsigned char*)&encoded[0];
1831 return d2i_PUBKEY(NULL, &pp, (
int)
sizeof(encoded));
1835 ldns_verify_rrsig_gost_raw(
const unsigned char* sig,
size_t siglen,
1836 const ldns_buffer* rrset,
const unsigned char* key,
size_t keylen)
1850 evp_key, EVP_get_digestbyname(
"md_gost94"));
1851 EVP_PKEY_free(evp_key);
1861 const unsigned char* pp = key;
1866 ec = EC_KEY_new_by_curve_name(NID_X25519);
1867 if(!ec)
return NULL;
1868 if(!o2i_ECPublicKey(&ec, &pp, (
int)keylen)) {
1872 evp_key = EVP_PKEY_new();
1877 if (!EVP_PKEY_assign_EC_KEY(evp_key, ec)) {
1878 EVP_PKEY_free(evp_key);
1886 ldns_verify_rrsig_ed25519_raw(
unsigned char* sig,
size_t siglen,
1887 ldns_buffer* rrset,
unsigned char* key,
size_t keylen)
1899 EVP_PKEY_free(evp_key);
1908 const unsigned char* pp = key;
1913 ec = EC_KEY_new_by_curve_name(NID_X448);
1914 if(!ec)
return NULL;
1915 if(!o2i_ECPublicKey(&ec, &pp, (
int)keylen)) {
1919 evp_key = EVP_PKEY_new();
1924 if (!EVP_PKEY_assign_EC_KEY(evp_key, ec)) {
1925 EVP_PKEY_free(evp_key);
1933 ldns_verify_rrsig_ed448_raw(
unsigned char* sig,
size_t siglen,
1934 ldns_buffer* rrset,
unsigned char* key,
size_t keylen)
1946 EVP_PKEY_free(evp_key);
1955 unsigned char buf[256+2];
1956 const unsigned char* pp = buf;
1961 if(keylen != 2*256/8)
return NULL;
1962 ec = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
1964 if(keylen != 2*384/8)
return NULL;
1965 ec = EC_KEY_new_by_curve_name(NID_secp384r1);
1967 if(!ec)
return NULL;
1968 if(keylen+1 >
sizeof(buf))
1972 buf[0] = POINT_CONVERSION_UNCOMPRESSED;
1973 memmove(buf+1, key, keylen);
1974 if(!o2i_ECPublicKey(&ec, &pp, (
int)keylen+1)) {
1978 evp_key = EVP_PKEY_new();
1983 if (!EVP_PKEY_assign_EC_KEY(evp_key, ec)) {
1984 EVP_PKEY_free(evp_key);
1992 ldns_verify_rrsig_ecdsa_raw(
unsigned char* sig,
size_t siglen,
1993 ldns_buffer* rrset,
unsigned char* key,
size_t keylen, uint8_t algo)
2006 else d = EVP_sha384();
2008 EVP_PKEY_free(evp_key);
2018 (
unsigned char*)ldns_buffer_begin(rawsig_buf),
2019 ldns_buffer_position(rawsig_buf),
2021 (
unsigned char*)ldns_buffer_begin(key_buf),
2022 ldns_buffer_position(key_buf), algo);
2027 ldns_buffer *verify_buf,
unsigned char* key,
size_t keylen,
2068 return ldns_verify_rrsig_gost_raw(sig, siglen, verify_buf,
2075 return ldns_verify_rrsig_ecdsa_raw(sig, siglen, verify_buf,
2081 return ldns_verify_rrsig_ed25519_raw(sig, siglen, verify_buf,
2087 return ldns_verify_rrsig_ed448_raw(sig, siglen, verify_buf,
2117 uint8_t label_count;
2140 wildcard_chopped = wildcard_chopped_tmp;
2166 if (rrsig == NULL) {
2275 ldns_rrsig_check_timestamps(
const ldns_rr* rrsig, time_t now)
2277 int32_t inception, expiration;
2285 if (expiration - inception < 0) {
2289 if (((int32_t) now) - inception < 0) {
2293 if (expiration - ((int32_t) now) < 0) {
2323 result = ldns_rrsig2rawsig_buffer(rawsig_buf, rrsig);
2329 ldns_rrset_use_signature_ttl(rrset_clone, rrsig);
2361 if (rrsig == NULL) {
2398 verify_buf, key_buf, sig_algo);
2442 result = ldns_rrsig_check_timestamps(rrsig, check_time);
2469 rrset, rrsig, keys, ldns_time(NULL), good_keys);
2501 result = ldns_prepare_for_verify(rawsig_buf, verify_buf,
2502 rrset_clone, rrsig);
2513 status = ldns_verify_test_sig_key(rawsig_buf, verify_buf,
2577 result = ldns_prepare_for_verify(rawsig_buf, verify_buf,
2578 rrset_clone, rrsig);
2585 result = ldns_verify_test_sig_key(rawsig_buf, verify_buf,
2594 result = ldns_rrsig_check_timestamps(rrsig, check_time);
2610 const EVP_MD *digest_type)
2613 (
unsigned char*)ldns_buffer_begin(sig),
2614 ldns_buffer_position(sig),
2622 const ldns_buffer *rrset, EVP_PKEY *key,
const EVP_MD *digest_type)
2627 #ifdef HAVE_EVP_MD_CTX_NEW 2628 ctx = EVP_MD_CTX_new();
2630 ctx = (EVP_MD_CTX*)malloc(
sizeof(*ctx));
2631 if(ctx) EVP_MD_CTX_init(ctx);
2636 EVP_VerifyInit(ctx, digest_type);
2637 EVP_VerifyUpdate(ctx,
2638 ldns_buffer_begin(rrset),
2639 ldns_buffer_position(rrset));
2640 res = EVP_VerifyFinal(ctx, sig, (
unsigned int) siglen, key);
2642 EVP_MD_CTX_destroy(ctx);
2646 }
else if (res == 0) {
2658 (
unsigned char*) ldns_buffer_begin(sig),
2659 ldns_buffer_position(sig),
2661 (
unsigned char*) ldns_buffer_begin(key),
2662 ldns_buffer_position(key));
2669 (
unsigned char*)ldns_buffer_begin(sig),
2670 ldns_buffer_position(sig),
2672 (
unsigned char*) ldns_buffer_begin(key),
2673 ldns_buffer_position(key));
2680 (
unsigned char*)ldns_buffer_begin(sig),
2681 ldns_buffer_position(sig),
2683 (
unsigned char*) ldns_buffer_begin(key),
2684 ldns_buffer_position(key));
2689 ldns_buffer* rrset,
unsigned char* key,
size_t keylen)
2695 evp_key = EVP_PKEY_new();
2701 # ifdef HAVE_EVP_DSS1
2710 EVP_PKEY_free(evp_key);
2713 (void)sig; (void)siglen; (void)rrset; (void)key; (void)keylen;
2720 ldns_buffer* rrset,
unsigned char* key,
size_t keylen)
2725 evp_key = EVP_PKEY_new();
2735 EVP_PKEY_free(evp_key);
2751 evp_key = EVP_PKEY_new();
2761 EVP_PKEY_free(evp_key);
2786 evp_key = EVP_PKEY_new();
2796 EVP_PKEY_free(evp_key);
2821 evp_key = EVP_PKEY_new();
2831 EVP_PKEY_free(evp_key);
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
implementation of buffers to ease operations
ldns_rdf * ldns_rr_rrsig_labels(const ldns_rr *r)
returns the number of labels of a LDNS_RR_TYPE_RRSIG RR
bool 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...
ldns_rr_list * signatures
void ldns_dnssec_derive_trust_tree_normal_rrset_time(ldns_dnssec_trust_tree *new_tree, ldns_dnssec_data_chain *data_chain, ldns_rr *cur_sig_rr, time_t check_time)
Sub function for derive_trust_tree that is used for a 'normal' rrset.
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
ldns_dnssec_trust_tree * ldns_dnssec_trust_tree_new(void)
Creates a new (empty) dnssec_trust_tree structure.
uint8_t ldns_dname_label_count(const ldns_rdf *r)
count the number of labels inside a LDNS_RDF_DNAME type rdf.
bool ldns_rr_compare_ds(const ldns_rr *orr1, const ldns_rr *orr2)
returns true of the given rr's are equal.
void ldns_rr2canonical(ldns_rr *rr)
converts each dname in a rr to its canonical form.
the canonical name for an alias
RSA * ldns_key_buf2rsa_raw(const unsigned char *key, size_t len)
Like ldns_key_buf2rsa, but uses raw buffer.
ldns_rr_type ldns_rdf2rr_type(const ldns_rdf *rd)
convert an rdf of type LDNS_RDF_TYPE_TYPE to an actual LDNS_RR_TYPE.
ldns_status ldns_verify_trusted_time(ldns_resolver *res, ldns_rr_list *rrset, ldns_rr_list *rrsigs, time_t check_time, ldns_rr_list *validating_keys)
Verifies a list of signatures for one RRset using a valid trust path.
ldns_rr_list * ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type and type from a packet.
int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6...
ldns_status ldns_verify_rrsig_evp(ldns_buffer *sig, ldns_buffer *rrset, EVP_PKEY *key, const EVP_MD *digest_type)
verifies a buffer with signature data for a buffer with rrset data with an EVP_PKEY ...
bool ldns_dnssec_pkt_has_rrsigs(const ldns_pkt *pkt)
Checks whether the packet contains rrsigs.
DNS stub resolver structure.
ldns_rdf * ldns_rr_rrsig_inception(const ldns_rr *r)
returns the inception time of a LDNS_RR_TYPE_RRSIG RR
enum ldns_enum_rr_class ldns_rr_class
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
ldns_pkt * ldns_resolver_query(const ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send a query to a nameserver.
List or Set of Resource Records.
ldns_status ldns_str2rdf_dname(ldns_rdf **d, const char *str)
convert a dname string into wireformat
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 ...
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's respons code.
uint8_t ldns_rdf2native_int8(const ldns_rdf *rd)
returns the native uint8_t representation from the rdf.
ldns_status parent_status[10]
D