Commit Graph

3664 Commits

Author SHA1 Message Date
Tom Thorogood 64746df23b WIP: DNS-over-HTTPS support for Client.Exchange API (#671)
* Add DNS-over-HTTPS support to (*Client).Exchange

* Ignore net/http goroutine leak from DoH

* Use existing Dialer and TLSConfig fields on Client for DOH

* Make DOH http.Client fully configurable

* Pipe context into exchangeDOH
2018-05-16 08:54:01 +01:00
Miek Gieben 3745b9737d
Small comment tweaks (#678)
Some post #668 comments nits.
2018-05-16 08:53:51 +01:00
Pierre Souchay 09649115c1 Fixed len computation when size just goes beyond 14 bits (#668)
* Fixed len computation when size just goes beyond 14 bits

* Added bouds checks around 14bits

* Len() always right including when around 14bits boudaries

* Avoid splitting into labels when not applicable

* Fixed comments

* Added comments in code

* Added new test cases

* Fixed computation of Len() for SRV and all kind of records

* Fixed Sign that was relying on non-copy for Unit tests

* Removed unused padding

* Fixed typo in PackBuffer() function

* Added comment about packBufferWithCompressionMap() for testing purposes
2018-05-16 07:20:13 +01:00
Uladzimir Trehubenka 621df0907e Make MaxTCPQueries configurable (#673) 2018-05-14 20:12:20 +01:00
Tom Thorogood 77d95a53d0 Handle empty NSEC3 salt in scanner (#677)
Fixes #676
2018-05-14 20:07:52 +01:00
chantra 1f2aa4c780 do not modify dns.Rcode when packing to wire format (#675)
* do not modify dns.Rcode when packing to wire format

When the message has an EDNS0 option in the additional section and
dns.Msg.Rcode is set to an extended rcode, dns.Msg.PackBuffer() modifies
dns.Msg.Rcode.
If you were to `Pack` the message and log it after, the Rcode would show
NOERROR.

Running the test before the change would error with:

```
=== RUN   TestPackNoSideEffect
--- FAIL: TestPackNoSideEffect (0.00s)
	msg_test.go:51: after pack: Rcode is expected to be BADVERS
```

after fixing dns.Msg.PackBuffer(), all tests are still passing.

Fixes #674

* address comments from PR#675
2018-05-13 08:36:02 +01:00
Miek Gieben a93f3e4f6b
copyHeader is redundant (#672)
copyHeader() is redundant, we allocate a header and then copy the
non-pointer elements into it; we don't need to do this, because if we
just asssign rr.Hdr to something else we get the same result.

Remove copyHeader() and the generation and use of it in ztypes.go.
2018-05-10 14:50:26 +01:00
Miek Gieben eac804ceef Release 1.0.6 2018-05-09 20:05:41 +01:00
Uladzimir Trehubenka 98a1ef4565 Use workers instead spawning goroutines for each incoming DNS request (#664)
* Use workers instead spawning goroutines for each incoming DNS request

* Replace count (int) with inUse (bool)
2018-05-09 16:44:32 +01:00
Stefan Aurori 9c76f9827e Add DSA to SHA1 mapping in dnssec AlgorithmToHash (#670) 2018-05-05 19:03:36 +02:00
Tom Thorogood 01d59357d4 Cleanup serve function (reland) (#667)
* Split central ServeDNS code out of (*Server).serve

* Add UDP and TCP specific (*Server).serve wrappers

* Move UDP serve functionality into serveUDPPacket

* Merge serve into serveTCPConn

* Cleanup serveTCPConn replacing goto with for

* defer Close in serveTCPConn

* Remove remoteAddr field from response struct

* Fix broken tsigSecret check in serveDNS

* Reorder serveDNS arguments

This makes it consistent with the ordering of arguments to
serveUDPPacket and serveTCPConn.
2018-04-06 16:09:55 +01:00
Tom Thorogood 3f2548fb60 Skip UDP OOB tests on unsupported architectures (#661) 2018-04-06 14:51:59 +01:00
Tom Thorogood 800934f8d4 Cleanup udp.go somewhat (#662)
* Avoid hard-coding required UDP OOB buffer size

* Simplify parseDstFromOOB if statements

* Use self-invoking function for udpOOBSize variable
2018-04-06 14:51:04 +01:00
Eric Greer 46f728d51b ExchangeWithDialer does not exist anymore (#666) 2018-04-06 12:05:09 +01:00
Miek Gieben 83c435cc65 Release 1.0.5 2018-04-01 13:59:20 +01:00
Miek Gieben 7fdfb0141b Revert "Cleanup serve function (#653)"
This reverts commit d174bbf0a5.
2018-04-01 12:27:36 +01:00
Miek Gieben dfb943b13e
Take the max compression offset into account in Len(). (#658)
This offset max was not taking into account leading Len() to emit a
smaller value that could not be matched by Pack(), i.e all names can
be fully compressed or used as a target for compression.

Split length tests off in seperate file length_test.go to clean up
dns_test.og a bit.
2018-04-01 09:45:32 +01:00
Tom Thorogood d174bbf0a5 Cleanup serve function (#653)
* Split central ServeDNS code out of (*Server).serve

* Add UDP and TCP specific (*Server).serve wrappers

* Move UDP serve functionality into serveUDPPacket

* Merge serve into serveTCPConn

* Cleanup serveTCPConn replacing goto with for

* defer Close in serveTCPConn

* Remove remoteAddr field from response struct

* Fix broken tsigSecret check in serveDNS

* Reorder serveDNS arguments

This makes it consistent with the ordering of arguments to
serveUDPPacket and serveTCPConn.
2018-03-30 14:50:27 +01:00
clmul 22cb769f47 use a local variable to calculate rtt (#656) 2018-03-27 08:01:29 +01:00
chantra 5b169d1842 [msg] Add UnpackRRWithHeader (#643)
This function allow to extra the raw content of a record type based on
an existing header.
Fixes #633
2018-03-15 09:09:45 +00:00
Ludovic Fernandez 906238edc6 fix: panicing on options parsing. (#642) 2018-03-01 06:22:09 -08:00
Tom Thorogood 4d25966dce Test that Shutdown does not surface closed errors (#624)
* Test that Shutdown does not surface closed errors

This test checks that calling Shutdown does not cause ActivateAndServe
(via serveTCP and serveUDP) to return the underlying
'use of closed network connection' error.

This commit unifies TestShutdownTCP with TestShutdownUDP. After this
commit, both tests will check that ActivateAndServe returns a nil error
and that Shutdown succeeded.

This was previously broken for serveTCP.

* Add comment explaining why fin chan is buffered
2018-02-27 17:38:12 -08:00
Miek Gieben 5364553f1e Release 1.0.4 2018-01-25 10:38:03 +00:00
Miek Gieben 43913f2f4f
Fix for CVE-2017-15133 TCP DOS (#631)
serveTCP calls reader.ReadTCP in the accept loop rather than in
the per-connection goroutine. If an attacker opens a connection
and leaves it idle, this will block the accept loop until the
connection times out (2s by default). During this time no other
incoming connections will succeed, preventing legitimate queries
from being answered.

This commit moves the call to reader.ReadTCP into the per-connection
goroutine. It also adds a missing call to Close whose absence allowed
file-descirptors to leak in select cases.

This attack and fix have no impact on serving UDP queries.
2018-01-25 10:36:19 +00:00
Frank Denis 862243b3b1 Add dnscrypt-proxy and rpdns to the list of users (#628) 2018-01-17 20:57:19 +00:00
Tom Thorogood f5ac34d755 Fix TCP Shutdown 'use of closed network connection' (#623)
The check for srv.started being false is in the wrong place, it should
be after Accept not after ReadTCP. If Shutdown is called, serveTCP will
currently return a 'use of closed network connection' error, which is
undesired.

This commit mirrors the behaviour of serveUDP with respect to Shutdown.
2018-01-10 13:37:59 +00:00
Miek Gieben 9cef7a0d3d Release: plain push is also needed
Apparently a git push --tags doesn't push all the changes!?!
Adding plain "git push" to avoid release confusion.
2018-01-10 08:17:22 +00:00
Miek Gieben 5ec25f2a50 Release 1.0.3 2018-01-10 08:11:11 +00:00
Tom Thorogood ddd8477be2 Ignore malformed UDP datagrams without headers (#622)
Ignore malformed UDP datagrams with incomplete DNS headers
2018-01-10 07:51:00 +00:00
Tom Thorogood 69d25e845f Fixes #613 & #619 (#621)
* Do not reutrn ErrShortRead in readUDP

A read of zero bytes indicates a peer shutdown for TCP sockets -- and
thus returning ErrShortRead is fine in readTCP -- but not for UDP
sockets. For UDP sockets a read of zero bytes literally indicates a
zero-byte datagram, and is a valid return value not indicating an error.

Removing this case will cause readUDP to correctly return a zero-byte
message.

* Return non-temporary error from serveUDP loop

Fixes #613
2018-01-09 13:57:26 +00:00
Miek Gieben e2db8456df
Revert "Fixes #613 (#617)" (#620)
This reverts commit ac8cd7878c.
2018-01-09 08:03:27 +00:00
Miek Gieben dcdbddd810
ClassANY: don't convert CLASS255 to ANY (#618)
* ClassANY: don't convert CLASS255 to ANY

Class "ANY" is wireformat only. In zonefile you can use CLASS255, but
when String-ing we convert this into "ANY" which is wrong. I.e. this
means we can't read back our own update.

Bit of a kludge to work around this, as I'm not sure we can just remove
ANY from the ClassToString map.
2018-01-07 17:57:04 +00:00
Twitch ac8cd7878c Fixes #613 (#617)
* Fixes #613

* use net.Error interface for detecting temporary errors
2018-01-06 16:01:19 +00:00
Miek Gieben afd3e95dbb
test: remove net tests (#616)
Never executed, flaky and failing now that some SIDN test servers
have been removed.

Just delete the code; hopefully we can bring it back one day in a CI
repo or something?
2018-01-05 13:11:23 +00:00
Miek Gieben 787fb05a25 Release 1.0.1 2017-12-21 11:36:42 +00:00
Lorenz Bauer 9088876525 Don't use untrusted lengths from Header to pre-allocate (#610)
We currently use information from a potential attacker to pre-allocate slices for the Question, Answer, etc. sections. This allows an attacker to force allocation of several MiB per parsed Msg.

Instead, don't pre-allocate those slices. append() always allocates in powers of two, which is probably the best we can do.

Fixes #609.
2017-12-21 10:24:07 +00:00
Miek Gieben 5f2d7c7013
Unpack: return header (#608)
When we unpack a message and only have the header consider it a valid
message and don't return an error.
2017-12-20 10:51:13 +00:00
Matthijs Mekking cef5150e02 Fix issue #605 (#606)
This makes `client.Readmsg` always return the message,
regardless if and how unpacking the message failed.
2017-12-18 20:15:56 +00:00
Miek Gieben 3bbde607ac
relative include: now tested! (#602)
* relative include: now tested!

If you take the effort of creating includePath, actually use it when
opening the file. Now tested (again) with CoreDNS (with a zone file that
includes two others)

Failure to include leads to:

~~~
2017/12/07 16:47:00 plugin/file: /tmp/example.org: dns: failed to include `a/1include1.org' as `/tmp/a/1include1.org': "a/1include1.org" at line: 15:24
~~~

* dont change the error line
2017-12-07 17:12:20 +00:00
Miek Gieben c438b740fe
Allow $INCLUDE to reference relative file (#598)
When using a relative file in an $INCLUDE the file is referenced from
the cwd from the calling processes; this changes it to be down from the
view point where the file exists.

Code from https://github.com/miekg/dns/issues/537#issuecomment-342932962

Fixes #537
2017-12-06 22:03:54 +00:00
Miek Gieben 6d3b6dc31b
Add size-hex: modifier for len() (#599)
This was missing and generated the wrong code for TKEY; it adds a +1 to
the amount. This should happen (technically).

I think the fallout is not super bad (of the +1) as we allocate a byte
more for when pack a message.
2017-12-06 21:41:53 +00:00
Miek Gieben e508eecd67
Some linter fixes from Go report card. (#601)
Implement small linter fixes.
2017-12-06 11:31:56 +00:00
Miek Gieben 862c2faf96
Add codecov yaml to not fail the build (#600) 2017-12-06 10:36:23 +00:00
Miek Gieben fbee4ceea9
Lint: use ignore-this on generated files (#596)
Make golint not complain about generated file - it's a bit of cheating,
but I think that is OK.
2017-12-06 10:02:47 +00:00
Miek Gieben 9271f6595b
Add semver (#595)
Add a version.go that has the semver version of this libary; now at
1.0.0. Use a struct so external code can easily check the for the
version without resulting to string parsing. Add String() function if
you want to access the version string.

Use simple Makefile.release to kick off a new release:

% edit version.go
% make -f Makefile.release

will tag and push according to version, if version is 1.0.0 the tag
in git will be v1.0.0
2017-12-06 09:46:54 +00:00
James Hartig 325e98bb86 Use and vendor golang.org/x/net/ipv4 and golang.org/x/net/ipv6 (#594) 2017-12-04 09:59:24 +00:00
Miek Gieben 6da3249dfb
EDNS0 client subnet: drop draft option (#589)
Noone should be using this option, it has been deprecated ever since
RFC 7178 came out: May 2016. Remove code that deals with that.
2017-11-28 07:48:19 +00:00
spsholleman 052efef004 Add support for TKEY RRs (#567)
* Add support for TKEY RRs

- make sure Key and Data fields are variable length hex fields
- checkin output from 'go generate'
- add a TKEY specific test to ensure this stays working

* go format changes

* address review comments

* add ability to parse TKEY via string

* handle review comments - change TKEY string output
2017-11-28 07:48:02 +00:00
Marc Ende 5ec0c6d20f Modified clientconfig to match ndots0 (#590)
* Modified clientconfig to match ndots0

* Added Tests for reading resolv.conf

* Cleaned up and removed duplicated code in test

* Added test for ndots below 0

* Cleaned up test

* Clean up
2017-11-27 11:17:45 +00:00
Miek Gieben 57a0d1a2cf
458+dep (#591)
* Add support for Ed25519 DNSSEC signing from RFC 8080

Note: The test case from RFC 8080 has been modified
to correct the missing final brace, but is otherwise
present as-is.

* Explain why ed25519 is special cased in (*RRSIG).Sign

* Explain use of ed25519.GenerateKey in readPrivateKeyED25519

* Add dep

This is PR #458 with the dependency added into it.
2017-11-27 10:49:53 +00:00