Skip to content

Commit 41815a4

Browse files
committed
resolve: print a noisy warning if we show crypto keys that could not be authenticated
Doing DNS retrieval on non-authenticated crypt keys is useless, hence warn loudly about it.
1 parent 9dc907f commit 41815a4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/resolve/dns-type.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ bool dns_type_is_obsolete(uint16_t type) {
193193
DNS_TYPE_NULL);
194194
}
195195

196+
bool dns_type_needs_authentication(uint16_t type) {
197+
198+
/* Returns true for all (non-obsolete) RR types where records are not useful if they aren't
199+
* authenticated. I.e. everything that contains crypto keys. */
200+
201+
return IN_SET(type,
202+
DNS_TYPE_CERT,
203+
DNS_TYPE_SSHFP,
204+
DNS_TYPE_IPSECKEY,
205+
DNS_TYPE_DS,
206+
DNS_TYPE_DNSKEY,
207+
DNS_TYPE_TLSA,
208+
DNS_TYPE_CDNSKEY,
209+
DNS_TYPE_OPENPGPKEY,
210+
DNS_TYPE_CAA);
211+
}
212+
196213
int dns_type_to_af(uint16_t t) {
197214
switch (t) {
198215

src/resolve/dns-type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ bool dns_type_is_dnssec(uint16_t type);
132132
bool dns_type_is_obsolete(uint16_t type);
133133
bool dns_type_may_wildcard(uint16_t type);
134134
bool dns_type_apex_only(uint16_t type);
135+
bool dns_type_needs_authentication(uint16_t type);
135136
int dns_type_to_af(uint16_t t);
136137

137138
bool dns_class_is_pseudo(uint16_t class);

src/resolve/resolve-tool.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ static int resolve_record(sd_bus *bus, const char *name, uint16_t class, uint16_
339339
uint64_t flags;
340340
int r;
341341
usec_t ts;
342+
bool needs_authentication = false;
342343

343344
assert(name);
344345

@@ -421,6 +422,10 @@ static int resolve_record(sd_bus *bus, const char *name, uint16_t class, uint16_
421422
log_warning_errno(errno, "Failed to resolve interface name for index %i: %m", ifindex);
422423

423424
printf("%s%s%s\n", s, isempty(ifname) ? "" : " # interface ", ifname);
425+
426+
if (dns_type_needs_authentication(t))
427+
needs_authentication = true;
428+
424429
n++;
425430
}
426431
if (r < 0)
@@ -441,6 +446,18 @@ static int resolve_record(sd_bus *bus, const char *name, uint16_t class, uint16_
441446

442447
print_source(flags, ts);
443448

449+
if ((flags & SD_RESOLVED_AUTHENTICATED) == 0 && needs_authentication) {
450+
fflush(stdout);
451+
452+
fprintf(stderr, "\n%s"
453+
"WARNING: The resources shown contain cryptographic key data which could not be\n"
454+
" authenticated. It is not suitable to authenticate any communication.\n"
455+
" This is usually indication that DNSSEC authentication was not enabled\n"
456+
" or is not available for the selected protocol or DNS servers.%s\n",
457+
ansi_highlight_red(),
458+
ansi_normal());
459+
}
460+
444461
return 0;
445462
}
446463

0 commit comments

Comments
 (0)