Skip to content

Commit d15ad74

Browse files
committed
resolved: NSEC3 hash algorithms are distinct from DS digest algorithms
Previously, we'd use the same set of identifiers for both, but that's actually incorrect. It didn't matter much since the only NSEC3 hash algorithm defined (SHA-1) is mapped to code 1 which is also what it is encoded as in DS digests, but we really should make sure to use two distinct enumerations.
1 parent 0a9a2ac commit d15ad74

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/resolve/resolved-dns-dnssec.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,20 @@ int dnssec_verify_dnskey_search(DnsResourceRecord *dnskey, DnsAnswer *validated_
10571057
return 0;
10581058
}
10591059

1060+
static int nsec3_hash_to_gcrypt_md(uint8_t algorithm) {
1061+
1062+
/* Translates a DNSSEC NSEC3 hash algorithm into a gcrypt digest identifier */
1063+
1064+
switch (algorithm) {
1065+
1066+
case NSEC3_ALGORITHM_SHA1:
1067+
return GCRY_MD_SHA1;
1068+
1069+
default:
1070+
return -EOPNOTSUPP;
1071+
}
1072+
}
1073+
10601074
int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
10611075
uint8_t wire_format[DNS_WIRE_FOMAT_HOSTNAME_MAX];
10621076
gcry_md_hd_t md = NULL;
@@ -1073,7 +1087,7 @@ int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
10731087
if (nsec3->key->type != DNS_TYPE_NSEC3)
10741088
return -EINVAL;
10751089

1076-
algorithm = digest_to_gcrypt_md(nsec3->nsec3.algorithm);
1090+
algorithm = nsec3_hash_to_gcrypt_md(nsec3->nsec3.algorithm);
10771091
if (algorithm < 0)
10781092
return algorithm;
10791093

@@ -1138,6 +1152,10 @@ static int nsec3_is_good(DnsResourceRecord *rr, DnsAnswerFlags flags, DnsResourc
11381152
if (!IN_SET(rr->nsec3.flags, 0, 1))
11391153
return 0;
11401154

1155+
/* Ignore NSEC3 RRs whose algorithm we don't know */
1156+
if (nsec3_hash_to_gcrypt_md(rr->nsec3.algorithm) < 0)
1157+
return 0;
1158+
11411159
if (!nsec3)
11421160
return 1;
11431161

src/resolve/resolved-dns-rr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ enum {
7272
_DNSSEC_DIGEST_MAX_DEFINED
7373
};
7474

75+
/* DNSSEC NSEC3 hash algorithms, see
76+
* https://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml */
77+
enum {
78+
NSEC3_ALGORITHM_SHA1 = 1,
79+
_NSEC3_ALGORITHM_MAX_DEFINED
80+
};
81+
7582
struct DnsResourceKey {
7683
unsigned n_ref;
7784
uint16_t class, type;

0 commit comments

Comments
 (0)