resolved-dns-dnssec.c revision 3f5ecaad3cf914d3c6fa1ab67947e1262f93bea5
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering This file is part of systemd.
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering Copyright 2015 Lennart Poettering
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering (at your option) any later version.
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering systemd is distributed in the hope that it will be useful, but
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering Lesser General Public License for more details.
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering/* Open question:
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * How does the DNSSEC canonical form of a hostname with a label
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * containing a dot look like, the way DNS-SD does it?
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - wildcard zones compatibility (NSEC/NSEC3 wildcard check is missing)
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - multi-label zone compatibility
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - cname/dname compatibility
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - nxdomain on qname
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - bus calls to override DNSEC setting per interface
15bd9a285858c374684e75709de82681ab7daaa7Lennart Poettering * - log all DNSSEC downgrades
* - RFC 4035, Section 5.3.4 (When receiving a positive wildcard reply, use NSEC to ensure it actually really applies)
/* Maximum number of NSEC3 iterations we'll do. RFC5155 says 2500 shall be the maximum useful value */
static void initialize_libgcrypt(void) {
assert(p);
const uint8_t *p;
size_t i;
if (mask_revoke)
f &= ~DNSKEY_FLAG_REVOKE;
static int rr_compare(const void *a, const void *b) {
size_t m;
assert(x);
assert(*x);
assert(y);
assert(*y);
static int dnssec_rsa_verify_raw(
const char *hash_algorithm,
if (ge != 0) {
r = -EIO;
goto finish;
if (ge != 0) {
r = -EIO;
goto finish;
if (ge != 0) {
r = -EIO;
goto finish;
NULL,
if (ge != 0) {
r = -EIO;
goto finish;
NULL,
(int) data_size,
data);
if (ge != 0) {
r = -EIO;
goto finish;
NULL,
if (ge != 0) {
r = -EIO;
goto finish;
else if (ge != 0) {
r = -EIO;
gcry_mpi_release(e);
gcry_mpi_release(n);
gcry_mpi_release(s);
if (public_key_sexp)
if (signature_sexp)
if (data_sexp)
static int dnssec_rsa_verify(
const char *hash_algorithm,
return -EINVAL;
return -EINVAL;
if (exponent_size <= 0)
return -EINVAL;
return -EINVAL;
return dnssec_rsa_verify_raw(
static int dnssec_ecdsa_verify_raw(
const char *hash_algorithm,
const char *curve,
if (ge != 0) {
k = -EIO;
goto finish;
if (ge != 0) {
k = -EIO;
goto finish;
if (ge != 0) {
k = -EIO;
goto finish;
NULL,
if (ge != 0) {
k = -EIO;
goto finish;
NULL,
(int) data_size,
data);
if (ge != 0) {
k = -EIO;
goto finish;
NULL,
if (ge != 0) {
k = -EIO;
goto finish;
else if (ge != 0) {
k = -EIO;
gcry_mpi_release(r);
gcry_mpi_release(s);
gcry_mpi_release(q);
if (public_key_sexp)
if (signature_sexp)
if (data_sexp)
static int dnssec_ecdsa_verify(
const char *hash_algorithm,
int algorithm,
const char *curve;
uint8_t *q;
return -EOPNOTSUPP;
return -EINVAL;
return -EINVAL;
return dnssec_ecdsa_verify_raw(
v = htobe16(v);
v = htobe32(v);
return -EKEYREJECTED;
inception = 0;
switch (algorithm) {
case DNSSEC_ALGORITHM_RSASHA1:
return GCRY_MD_SHA1;
return GCRY_MD_SHA256;
return GCRY_MD_SHA384;
return GCRY_MD_SHA512;
return -EOPNOTSUPP;
int dnssec_verify_rrset(
DnsAnswer *a,
void *hash;
int r, md_algorithm;
size_t k, n = 0;
if (md_algorithm < 0)
return md_algorithm;
if (n > VERIFY_RRS_MAX)
return -E2BIG;
return -ENODATA;
if (!md)
return -EIO;
goto finish;
const char *suffix;
size_t l;
goto finish;
goto finish;
if (!hash) {
r = -EIO;
goto finish;
case DNSSEC_ALGORITHM_RSASHA1:
r = dnssec_rsa_verify(
dnskey);
r = dnssec_ecdsa_verify(
dnskey);
goto finish;
int dnssec_rrsig_match_dnskey(DnsResourceRecord *rrsig, DnsResourceRecord *dnskey, bool revoked_ok) {
return -EINVAL;
static int dnssec_fix_rrset_ttl(DnsAnswer *a, const DnsResourceKey *key, DnsResourceRecord *rrsig, usec_t realtime) {
DnsAnswer *a,
bool found_rrsig = false, found_invalid = false, found_expired_rrsig = false, found_unsupported_algorithm = false;
if (!a || a->n_rrs <= 0)
return -ENODATA;
found_rrsig = true;
switch (one_result) {
case DNSSEC_VALIDATED:
case DNSSEC_INVALID:
found_invalid = true;
found_unsupported_algorithm = true;
case DNSSEC_SIGNATURE_EXPIRED:
found_expired_rrsig = true;
if (found_expired_rrsig)
else if (found_unsupported_algorithm)
else if (found_invalid)
else if (found_rrsig)
size_t c = 0;
return -ENOBUFS;
return -ENOBUFS;
return -EINVAL;
switch (algorithm) {
case DNSSEC_DIGEST_SHA1:
return GCRY_MD_SHA1;
case DNSSEC_DIGEST_SHA256:
return GCRY_MD_SHA256;
case DNSSEC_DIGEST_SHA384:
return GCRY_MD_SHA384;
return -EOPNOTSUPP;
int md_algorithm, r;
void *result;
return -EINVAL;
return -EINVAL;
return -EKEYREJECTED;
return -EKEYREJECTED;
return -EKEYREJECTED;
if (md_algorithm < 0)
return md_algorithm;
if (!md)
return -EIO;
if (mask_revoke)
if (!result) {
r = -EIO;
goto finish;
if (r == -EKEYREJECTED)
switch (algorithm) {
case NSEC3_ALGORITHM_SHA1:
return GCRY_MD_SHA1;
return -EOPNOTSUPP;
int algorithm;
void *result;
return -EINVAL;
log_debug("Ignoring NSEC3 RR %s with excessive number of iterations.", dns_resource_record_to_string(nsec3));
return -EOPNOTSUPP;
if (algorithm < 0)
return algorithm;
return -EINVAL;
if (!md)
return -EIO;
if (!result) {
r = -EIO;
goto finish;
if (!result) {
r = -EIO;
goto finish;
r = (int) hash_size;
if (!nsec3)
return dns_name_equal(a, b);
static int nsec3_hashed_domain(DnsResourceRecord *nsec3, const char *domain, const char *zone, char **ret) {
int hashed_size;
if (hashed_size < 0)
return hashed_size;
return -ENOMEM;
if (!hashed_domain)
return -ENOMEM;
return hashed_size;
* First try to find a NSEC3 record that matches our query precisely, if that fails, find the closest
* is no wildcard domain as a direct descendant of the closest enclosure, or find an NSEC3 record that
* that there is no proof either way. The latter is the case if a the proof of non-existence of a given
* name uses an NSEC3 record with the opt-out bit set. Lastly, if we are given insufficient NSEC3 records
static int dnssec_test_nsec3(DnsAnswer *answer, DnsResourceKey *key, DnssecNsecResult *result, bool *authenticated, uint32_t *ttl) {
int hashed_size, r;
goto found_zone;
if (hashed_size < 0)
return hashed_size;
goto found_closest_encloser;
pp = p;
r = dns_name_parent(&p);
return -EBADMSG;
return -EBADMSG;
if (!pp) {
if (authenticated)
*authenticated = a;
if (ttl)
if (!wildcard)
return -ENOMEM;
if (r != hashed_size)
return -EBADMSG;
if (r != hashed_size)
return -EBADMSG;
if (!label)
return -ENOMEM;
if (!next_hashed_domain)
return -ENOMEM;
optout = true;
no_closer = true;
optout = true;
no_wildcard = true;
return -EBADMSG;
if (!no_closer) {
if (wildcard_rr) {
if (optout)
if (optout)
else if (no_wildcard)
if (authenticated)
*authenticated = a;
if (ttl)
int dnssec_test_nsec(DnsAnswer *answer, DnsResourceKey *key, DnssecNsecResult *result, bool *authenticated, uint32_t *ttl) {
bool have_nsec3 = false;
case DNS_TYPE_NSEC:
if (authenticated)
if (ttl)
r = dns_name_between(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key), rr->nsec.next_domain_name);
if (authenticated)
if (ttl)
case DNS_TYPE_NSEC3:
have_nsec3 = true;
if (have_nsec3)