Commit graph

80 commits

Author SHA1 Message Date
Daniel Mack 4e5bf5e158 resolved: add packet header details for mDNS
Validate mDNS queries and responses by looking at some header fields,
add mDNS flags.
2015-12-08 16:41:45 +01:00
Lennart Poettering 24710c48ed resolved: introduce a dnssec_mode setting per scope
The setting controls which kind of DNSSEC validation is done: none at
all, trusting the AD bit, or client-side validation.

For now, no validation is implemented, hence the setting doesn't do much
yet, except of toggling the CD bit in the generated messages if full
client-side validation is requested.
2015-12-03 21:17:49 +01:00
Lennart Poettering 8730bccfc5 resolved: move algorithm/digest definitions into resolved-dns-rr.h
After all, they are for flags and parameters of RRs and already relevant
when dealing with RRs outside of the serialization concept.
2015-12-03 00:26:58 +01:00
Lennart Poettering a8812dd7f1 resolved: add code to generate the wire format for a single RR
This adds dns_resource_record_to_wire_format() that generates the raw
wire-format of a single DnsResourceRecord object, and caches it in the
object, optionally in DNSSEC canonical form. This call is used later to
generate the RR serialization of RRs to verify.

This adds four new fields to DnsResourceRecord objects:

- wire_format points to the buffer with the wire-format version of the
  RR
- wire_format_size stores the size of that buffer
- wire_format_rdata_offset specifies the index into the buffer where the
  RDATA of the RR begins (i.e. the size of the key part of the RR).
- wire_format_canonical is a boolean that stores whether the cached wire
  format is in DNSSEC canonical form or not.

Note that this patch adds a mode where a DnsPacket is allocated on the
stack (instead of on the heap), so that it is cheaper to reuse the
DnsPacket object for generating this wire format. After all we reuse the
DnsPacket object for this, since it comes with all the dynamic memory
management, and serialization calls we need anyway.
2015-12-02 22:50:11 +01:00
Lennart Poettering 9551c15505 resolved: add code to map DNSSEC digest types to strings and back 2015-12-02 22:50:11 +01:00
Lennart Poettering f91dc2400d resolved: store DNSKEY fields flags+protocol as-is
When verifying signatures we need to be able to verify the original
data we got for an RR set, and that means we cannot simply drop flags
bits or consider RRs invalid too eagerly. Hence, instead of parsing the
DNSKEY flags store them as-is. Similar, accept the protocol field as it
is, and don't consider it a parsing error if it is not 3.

Of course, this means that the DNSKEY handling code later on needs to
check explicit for protocol != 3.
2015-12-02 22:50:11 +01:00
Lennart Poettering e30ec345ac resolved: add RFC 5702 defined DNSSEC algorithms to table 2015-12-02 22:50:11 +01:00
Lennart Poettering c38a52dae3 resolved: simplify dns_packet_append_string()
It essentially does the same as dns_packet_append_raw_string(), hence
make it a wrapper around it.
2015-12-02 20:35:08 +01:00
Tom Gundersen 7586f4d172 resolved: set the DNSSEC OK (DO) flag
This indicates that we can handle DNSSEC records (per RFC3225), even if
all we do is silently drop them. This feature requires EDNS0 support.

As we do not yet support larger UDP packets, this feature increases the
risk of getting truncated packets.

Similarly to how we fall back to plain UDP if EDNS0 fails, we will fall
back to plain EDNS0 if EDNS0+DO fails (with the same logic of remembering
success and retrying after a grace period after failure).
2015-11-27 01:35:34 +01:00
Tom Gundersen 9c5e12a431 resolved: implement minimal EDNS0 support
This is a minimal implementation of RFC6891. Only default values
are used, so in reality this will be a noop.

EDNS0 support is dependent on the current server's feature level,
so appending the OPT pseudo RR is done when the packet is emitted,
rather than when it is assembled. To handle different feature
levels on retransmission, we strip off the OPT RR again after
sending the packet.

Similarly, to how we fall back to TCP if UDP fails, we fall back
to plain UDP if EDNS0 fails (but if EDNS0 ever succeeded we never
fall back again, and after a timeout we will retry EDNS0).
2015-11-27 01:35:34 +01:00
Tom Gundersen dc913c9a1f resolved: rr - add OPT pseudo-rr support
Needed for EDNS0.
2015-11-27 01:35:34 +01:00
Tom Gundersen c283267467 Merge pull request #2031 from poettering/resolved-search-domains
resolved. Fully implement search domains for single-label names
2015-11-26 23:58:45 +01:00
Tom Gundersen 09eaf68ce4 resolved: do not reject NSEC records with empty bitmaps
The assumption that no NSEC bitmap could be empty due to the presence of the bit representing
the record itself turns out to be flawed. See (the admittedly experimental) RFC4956 for a
counter example.
2015-11-26 04:03:08 +01:00
Lennart Poettering 422baca0f2 dns-domain: rework dns_label_escape() to not imply memory allocation
The new dns_label_escape() call now operates on a buffer passed in,
similar to dns_label_unescape(). This should make decoding a bit faster,
and nicer.
2015-11-25 22:00:07 +01:00
Lennart Poettering 2001c80560 resolved: accept TXT records with non-UTF8 strings
RFC 6763 is very clear that TXT RRs should allow arbitrary binary
content, hence let's actually accept that. This also means accepting NUL
bytes in the middle of strings.
2015-11-23 21:31:28 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 069360a66a resolved: make packet flags logic more expressive again
This partially reverts 106784ebb7, ad
readds separate DNS_PACKET_MAKE_FLAGS() invocations for the LLMNR and
DNS case. This is important since SOme flags have different names and
meanings on LLMNR and on DNS and we should clarify that via the comments
and how we put things together.
2015-08-25 18:54:55 +02:00
Daniel Mack 106784ebb7 resolved: use switch-case statements for protocol details
With more protocols to come, switch repetitive if-else blocks with a
switch-case statements.
2015-08-25 14:25:56 +02:00
Lennart Poettering f6a5fec6b9 resolved: when passing RRs across the bus, make sure not to use name compression
We explicitly need to turn off name compression when marshalling or
demarshalling RRs for bus transfer, since they otherwise refer to packet
offsets that reference packets that are not transmitted themselves.
2015-08-21 16:04:59 +02:00
Lennart Poettering 78c6a153c4 resolved: rework synthesizing logic
With this change we'll now also generate synthesized RRs for the local
LLMNR hostname (first label of system hostname), the local mDNS hostname
(first label of system hostname suffixed with .local), the "gateway"
hostname and all the reverse PTRs. This hence takes over part of what
nss-myhostname already implemented.

Local hostnames resolve to the set of local IP addresses. Since the
addresses are possibly on different interfaces it is necessary to change
the internal DnsAnswer object to track per-RR interface indexes, and to
change the bus API to always return the interface per-address rather than
per-reply. This change also patches  the existing clients for resolved
accordingly (nss-resolve + systemd-resolve-host).

This also changes the routing logic for queries slightly: we now ensure
that the local hostname is never resolved via LLMNR, thus making it
trustable on the local system.
2015-08-21 12:41:08 +02:00
Tom Gundersen 6b9308d14b resolved: packet - fix typo in read_rr() 2015-08-16 20:52:21 +02:00
Tom Gundersen bfcc67093d resolved: packet - refuse empty type bitmaps
The NSEC type itself must at least be in the bitmap, so NSEC records with empty
bitmaps must be bogus.
2015-07-28 23:25:52 +02:00
Tom Gundersen 2ad613addb resolved: packet - fix read_type_window()
We were tracking the bit offset inside each byte, rather than inside the whole bitmap.
2015-07-28 23:25:52 +02:00
Tom Gundersen 1792f2231f resolve: packet - fix append_types()
We were counting the number of bits set rather than the number of bytes they occupied.
2015-07-28 23:25:52 +02:00
Tom Gundersen 0e03ade57e resolved: packet - fix segfault in truncate()
A size_t was being accessed as a char* due to the order of arguments being inverted.
2015-07-23 18:06:50 +02:00
Tom Gundersen 8e6edc490c resolved: rr - ignore pseudo types in NSEC(3) bitmaps 2015-07-23 18:06:50 +02:00
Tom Gundersen 0bbd72b2f3 resolved: rr - fix parsing of NSEC3
We were appending rather than reading the bitmap.
2015-07-23 18:06:50 +02:00
Tom Gundersen 89492aaf99 resolved: rr - don't read past end of RR when parsing NSEC(3)
We can never read past the end of the packet, so this seems impossible
to exploit, but let's error out early as reading past the end of the
current RR is clearly an error.

Found by Lennart, based on patch by Daniel.
2015-07-23 18:06:50 +02:00
Tom Gundersen 549c1a2564 resolved: rr - SSHFP contains the fingerprint, not the key
Rename the field to make this clearer.
2015-07-23 18:01:50 +02:00
Tom Gundersen f1d178cce1 resolved: packet - fail on invalid zero-length data
Most blobs (keys, signatures, ...) should have a specific size given by
the relevant algorithm. However, as we don't use/verify the algorithms
yet, let's just ensure that we don't read out zero-length data in cases
where this does not make sense.

The only exceptions, where zero-length data is allowed are in the NSEC3
salt field, and the generic data (which we don't know anything about,
so  better not make any assumptions).
2015-07-23 18:01:17 +02:00
Tom Gundersen b96c778a00 Merge pull request #669 from poettering/dns-rr-memdup
resolve: unify memdup() code when parsing RRs
2015-07-23 12:34:34 +02:00
Lennart Poettering 6fa919016a resolved: make sure we alway initialize *start in dns_packet_append_type_window() 2015-07-23 04:54:35 +02:00
Lennart Poettering f5430a3ef3 resolve: unify memdup() code when parsing RRs
Let's make dns_packet_read_public_key() more generic by renaming it to
dns_packet_read_memdup() (which more accurately describes what it
does...). Then, patch all cases where we memdup() RR data to use this
new call.

This specifically checks for zero-length objects, and handles them
gracefully. It will set zero length payload fields as a result.

Special care should be taken to ensure that any code using this call
can handle the returned allocated field to be NULL if the size is
specified as 0!
2015-07-23 04:50:19 +02:00
Tom Gundersen cb57dd4159 bitmap: use external iterator
Reuse the Iterator object from hashmap.h and expose a similar API.

This allows us to do

{
    Iterator i;
    unsigned n;

    BITMAP_FOREACH(n, b, i) {
        Iterator j;
        unsigned m;

        BITMAP_FOREACH(m, b, j) {
            ...
        }
    }
}

without getting confused. Requested by David.
2015-07-16 14:11:12 +02:00
Tom Gundersen 5d45a88084 resolved: rr - add NSEC3 support
Needed for DNSSEC.
2015-07-14 22:17:24 +02:00
Tom Gundersen 50f1e641a9 resolved: rr - add NSEC support
Needed for DNSSEC.
2015-07-14 21:53:10 +02:00
Daniel Mack 9ecec7d766 Merge pull request #586 from teg/resolved-rrs-3
resolved: minor improvements to RR handling
2015-07-14 13:43:18 -04:00
Tom Gundersen abf126a355 resolved: rr - add DS support
Needed for DNSSEC.
2015-07-14 19:16:16 +02:00
Tom Gundersen a0166609f7 resolved: packet - ensure there is space for IP+UDP headers
Currently we only make sure our links can handle the size of the payload witohut
taking the headers into account.
2015-07-14 12:03:04 +02:00
Daniel Mack 818ef443f0 resolved: make LLMNR checks conditional
Make all LLMNR related packet inspections conditional to p->protocol.
Use switch-case statements while at it, which will make future additions
more readable.
2015-07-13 11:28:30 -04:00
Tom Gundersen 0b1b17d325 resolved: fix marshalling of RRSIG records
The key tag is 16, not 8 bits.
2015-07-08 13:53:39 +02:00
Nick Owens 4ad7f2761d resolve: move dns routines into shared 2015-06-10 11:15:45 -07:00
Veres Lajos f131770b14 tree-wide: spelling fixes
https://github.com/vlajos/misspell_fixer

b6fdeb618c
Thanks to Torstein Husebo <torstein@huseboe.net>.
2014-12-30 20:07:04 -05:00
Lennart Poettering 1ccda9b716 resolved: make TXT RR generation and parsing more in-line with RFC 6763, section 6.1
The RFC says to encode an single empty TXT string instead of an empty
TXT array. It also says to treat a zero-length TXT RR as a TXT array
with a single zero-length string.
2014-12-01 03:08:55 +01:00
Stanisław Pitucha 0e3434aeb1 resolve: reject empty TXT records
TXT records should have at least one character, so enforce this.

Before 0f84a72 parser SIGSEGV'd on ->txt.strings being NULL, but
even if this is fixed we should reject invalid TXT records.
2014-11-27 11:07:43 -05:00
Stanisław Pitucha 59aa582137 resolve: set error code on failure
Set the error code in case of incorrect name. This prevents continuing
and failing an assert(name) later on.
2014-11-27 16:40:11 +01:00
Stanisław Pitucha c75dbf9bea resolve: fix redirection loops in compressed RR
Loops in RR compression were only detected for the first entry.
Multiple redirections should be allowed, each one checking for an
infinite loop on its own starting point.
Also update the pointer on each redirection to avoid longer loops of
labels and redirections, in names like:
(start) [len=1] "A", [ptr to start]

(David: rename variable to "jump_barrier" and add reference to RFC)
2014-11-27 16:35:56 +01:00
Tom Gundersen 725ca0e53a resolved: dns-packet - use unaligned read/write helpers 2014-11-01 15:36:29 +01:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00