Commit Graph

162 Commits

Author SHA1 Message Date
Miek Gieben 69924a02cf
Make tsigGenerateProvider/TsigVerifyProvider public (#1382)
Make it public as TsigGenerateWithProvider and update the docs a little.
And TsigVerifyWithProvider also - tweak those docs also a little.

Signed-off-by: Miek Gieben <miek@miek.nl>
2022-06-21 10:37:36 +02:00
Tom Thorogood 33e64002b6
Support TsigProvider for Server and Transfer (#1331)
Automatically submitted.
2022-02-05 00:23:49 +00:00
Chris O'Haver 3a58872b63
Do not sign BADKEY and BADSIG TSIG error responses (#1316)
* Per RFC 8945 5.3.2, responses with BADKEY and BADSIG errors must not be signed.

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* refactor to remove else block

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* skip signing only for BADKEY and BADSIG

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
2021-12-20 10:31:57 +01:00
Tom Thorogood 13238cb6ad
Support parsing known RR types in RFC 3597 format (#1211)
* Support parsing known RR types in RFC 3597 format

This is the format used for "Unknown DNS Resource Records", but it's
also useful to support parsing known RR types in this way.

RFC 3597 says:

   An implementation MAY also choose to represent some RRs of known type
   using the above generic representations for the type, class and/or
   RDATA, which carries the benefit of making the resulting master file
   portable to servers where these types are unknown.  Using the generic
   representation for the RDATA of an RR of known type can also be
   useful in the case of an RR type where the text format varies
   depending on a version, protocol, or similar field (or several)
   embedded in the RDATA when such a field has a value for which no text
   format is known, e.g., a LOC RR [RFC1876] with a VERSION other than
   0.

   Even though an RR of known type represented in the \# format is
   effectively treated as an unknown type for the purpose of parsing the
   RDATA text representation, all further processing by the server MUST
   treat it as a known type and take into account any applicable type-
   specific rules regarding compression, canonicalization, etc.

* Correct mistakes in TestZoneParserAddressAAAA

This was spotted when writing TestParseKnownRRAsRFC3597.

* Eliminate canParseAsRR

This has the advantage that concrete types will now be returned for
parsed ANY, NULL, OPT and TSIG records.

* Expand TestDynamicUpdateParsing for RFC 3597

This ensures we're properly handling empty RDATA for RFC 3597 parsed
records.
2021-01-30 14:05:25 +01:00
Matt Dainty 59aea23afe
Add GSS-TSIG support (#1201)
Automatically submitted.
2021-01-07 14:28:20 +00:00
Tom Thorogood 93945c2844
Remove HMAC-MD5 support from TSIG (#1187) 2020-10-24 13:57:51 +02:00
JINMEI Tatuya de1def76d8
Add support for HMAC-SHA224 and HMAC-SHA384 TSIG algorithms (#1139) 2020-07-22 13:59:04 +09:30
JINMEI Tatuya f3da20bc00
fix TsigGenerate for non-0 TSIG error or non-empty other data (#1138)
Automatically submitted.
2020-07-21 15:55:03 +00:00
JINMEI Tatuya a7a0eafd7a
catch error from tsigBuffer, mainly to detect other data overflow (#1136)
* catch error from tsigBuffer, mainly to detect other data overflow

* hardcoded a constant string instead of a const var
2020-07-21 08:04:57 +02:00
JINMEI Tatuya 9093928550
make TsigVerify check time after signature per rfc2845bis (#1135)
Automatically submitted.
2020-07-18 06:06:18 +00:00
Jan Včelák 524a80c35d
CanonicalName function to return domain name in canonical form (#1073)
* add Canonical function to get name in canonical form

* replace strings.ToLower with Canonical

* rename Canonical to CanonicalName

* replace Fqdn with CanonicalName in ServeMux
2020-03-18 11:21:59 +01:00
Miek Gieben bd4ba36771 Add ; before printing TSIG (#1051)
Automatically submitted.
2019-12-17 15:18:05 +00:00
Tom Thorogood 25cacca8ca Prohibit newlines before record data in the ZoneParser (#979)
* Merge setRR into ZoneParser.Next

* Remove file argument from RR.parse

This was only used to fill in the ParseError file field. Instead we now
fill in that field in ZoneParser.Next.

* Move dynamic update check out of RR.parse

This consolidates all the dynamic update checks into one place.

* Check for unexpected newline before parsing RR data

* Move rr.parse call into if-statement

* Allow dynamic updates for TKEY and RFC3597 records

* Document that ParseError file field is unset from parse

* Inline allowDynamicUpdate into ZoneParser.Next

* Improve and simplify TestUnexpectedNewline
2019-06-10 07:38:54 +01:00
Tom Thorogood db3d0ce13b
Use an interface method for parsing zone file records (#886)
* Eliminate Variable bool from parserFunc

Instead we now check whether the last token read from the zlexer was
a zNewline or zEOF. The error check above should be tripped for any
record that ends prematurely.

* Use an interface method for parsing zone file records

* Prevent panic in TestOmittedTTL if no regexp match

* Move slurpRemainder into fixed length parse functions

This is consistent with the original logic in setRR and avoids potential
edge cases.

* Parse synthetic records according to RFC 3597

These records lack a presentation format and cannot be parsed otherwise.
This behaviour is consistent with how this previously operated.
2019-01-06 14:36:16 +10:30
Tom Thorogood 29b9bf368b Remove pointless casts (#895)
* Remove pointless casts

These are all casts where the value was already of the same type.

* Use var style for zero-value not cast style
2019-01-04 10:30:55 +00:00
Tom Thorogood 513c1ff221 Simplify and unify various returns (#893) 2019-01-04 10:19:42 +00:00
Tom Thorogood 778aa4f83d
Properly calculate compressed message lengths (#833)
* Remove fullSize return from compressionLenSearch

This wasn't used anywhere but TestCompressionLenSearch, and was very
wrong.

* Add generated compressedLen functions and use them

This replaces the confusing and complicated compressionLenSlice
function.

* Use compressedLenWithCompressionMap even for uncompressed

This leaves the len() functions unused and they'll soon be removed.

This also fixes the off-by-one error of compressedLen when a (Q)NAME
is ".".

* Use Len helper instead of RR.len private method

* Merge len and compressedLen functions

* Merge compressedLen helper into Msg.Len

* Remove compress bool from compressedLenWithCompressionMap

* Merge map insertion into compressionLenSearch

This eliminates the need to loop over the domain name twice when we're
compressing the name.

* Use compressedNameLen for NSEC.NextDomain

This was a mistake.

* Remove compress from RR.len

* Add test case for multiple questions length

* Add test case for MINFO and SOA compression

These are the only RRs with multiple compressible names within the same
RR, and they were previously broken.

* Rename compressedNameLen to domainNameLen

It also handles the length of uncompressed domain names.

* Use off directly instead of len(s[:off])

* Move initial maxCompressionOffset check out of compressionLenMapInsert

This should allow us to avoid the call overhead of
compressionLenMapInsert in certain limited cases and may result in a
slight performance increase.

compressionLenMapInsert still has a maxCompressionOffset check inside
the for loop.

* Rename compressedLenWithCompressionMap to msgLenWithCompressionMap

This better reflects that it also calculates the uncompressed length.

* Merge TestMsgCompressMINFO with TestMsgCompressSOA

They're both testing the same thing.

* Remove compressionLenMapInsert

compressionLenSearch does everything compressionLenMapInsert did anyway.

* Only call compressionLenSearch in one place in domainNameLen

* Split if statement in domainNameLen

The last two commits worsened the performance of domainNameLen
noticably, this change restores it's original performance.

name                            old time/op    new time/op    delta
MsgLength-12                       550ns ±13%     510ns ±21%    ~     (p=0.050 n=10+10)
MsgLengthNoCompression-12         26.9ns ± 2%    27.0ns ± 1%    ~     (p=0.198 n=9+10)
MsgLengthPack-12                  2.30µs ±12%    2.26µs ±16%    ~     (p=0.739 n=10+10)
MsgLengthMassive-12               32.9µs ± 7%    32.0µs ±10%    ~     (p=0.243 n=9+10)
MsgLengthOnlyQuestion-12          9.60ns ± 1%    9.20ns ± 1%  -4.16%  (p=0.000 n=9+9)

* Remove stray newline from TestMsgCompressionMultipleQuestions

* Remove stray newline in length_test.go

This was introduced when resolving merge conflicts.
2018-11-30 10:03:41 +10:30
Matthijs Mekking 0598bd43cf Fix TSIG bug releated to ID substitution (#504)
* Fix TSIG bug releated to ID substitution

TSIG accounts for ID substitution. This means if the ID in the DNS
message is changed by for example a forwarder, TSIG calculation should
use the original message ID (from the TSIG RR).

I have a test for this as well, but it seems tsig_test.go has been
removed, so not sure where to put it now.

* Add tests for TSIG bugfix
2017-08-12 20:21:44 +01:00
Tom Thorogood b6ecf29d98 Improve performance by addressing some low hanging fruit. (#444)
* Remove unused bytes.Buffer from dns/idn.encode.

This buffer is truncated and written to but never read from. It
serves no purpose and all tests pass with it removed.

It appears to have been introduced when puncycode.go was first
added in miekg/dns@e3c2c07.

* Produce less pointless garbage.

This change:
- removes several needless []byte -> string conversions,
- removes two needless append calls in HashName, and
- writes the hash to the same nsec3 []byte in HashName rather
  than creating a new []byte on each of the k iterations.

These are all minor performance improvements that will likely
go entirely unnoticed. The changes will reduce the ammount of
garbage produced when calling CertificateToDANE, HashName,
(*SIG).Sign and TsigGenerate.
2017-02-02 07:33:49 +00:00
Miek Gieben e6b37d00af Cleanup and removals (#377)
* Cleanup and removals

Gut rawmsg.go as most functions are not used. Reword some documentation.
Add more types to be checked for name compression.

* Yeah, we do use these

* Remove this function as well - only used one
2016-06-13 19:44:38 +01:00
Miek Gieben b51e305bc6 Remove reflection (#376)
Everything is generated. Remove all uses of packStruct/unpackStruct and
make the library reflectionless.
2016-06-12 21:06:46 +01:00
Miek Gieben dbffa4b057 Kill all reflection when packing/unpacking RR (#372)
Update the size-xxx-member tags to point to another field in the struct
that should be used for the length in that field. Fix NSEC3/HIP and TSIG
to use to this and generate the correct pack/unpack functions for them.

Remove IPSECKEY from the lib and handle it as an unknown record - it is
such a horrible RR, needed kludges before - now just handle it as an
unknown RR.

All types now use generated pack and unpack functions. The blacklist is
removed.
2016-06-12 18:31:50 +01:00
Michael Haro a465e84f54 Use encoding/binary's conversion functions when possible. (#364)
* Remove {un,}packUint{16,32}Msg functions.

unpackUint16Msg unpackUint32Msg packUint16Msg packUint32Msg implemented
functionality that is part of the encoding/binary package.

* Use encoding/binary's encoding in more places.
2016-06-08 16:38:42 +01:00
Miek Gieben 475ab80867 Remove (most) reflection
Remove the use of reflection when packing and unpacking, instead
generate all the pack and unpack functions using msg_generate.
This will generate zmsg.go which in turn calls the helper functions from
msg_helper.go.

This increases the speed by about ~30% while cutting back on memory
usage. Not all RRs are using it, but that will be rectified in upcoming
PR.

Most of the speed increase is in the header/question section parsing.
These functions *are* not generated, but straight forward enough. The
implementation can be found in msg.go.

The new code has been fuzzed by go-fuzz, which turned up some issues.

All files that started with 'z', and not autogenerated were renamed,
i.e. zscan.go is now scan.go.

Reflection is still used, in subsequent PRs it will be removed entirely.
2016-06-03 12:45:22 +01:00
Miek Gieben b6897b5a7c TSIG: lowercase algorithm before use
These strings are domain names, so we should lowercase them before
using them.

Also add some tests for Tsig generation and verification.

(/ht ldns release).
2016-03-07 22:17:28 +00:00
Filippo Valsorda 25846488f9 Apply per-type code generation to .copy()
This fixes bugs in MB and CNAME.copy() (using sprintName for copying),
IPSECKEY (missed copyIP) and OPT (partially, Options was not copied as
slice; EDNS0 objects themselves are still pointers).
2015-10-07 05:51:36 +01:00
Filippo Valsorda d4a4e089d0 Generate programmatically per-type code, including .len()
This process probably fixes a bug in NSAPPTR.len(), after a similar one was
found in HINFO.len().

This should also make it easier to make changes to these functions, and
check their correctness.

Generate the code by running "go generate".
2015-10-07 05:48:12 +01:00
Miek Gieben 64fea017a2 Move all docs to docs.go
Another golint change.
2015-02-19 13:47:50 +00:00
Miek Gieben 67945c119e A bunch of golint fixes
The proposed vars names are a nono, because they break the API.
Things left: document each RR and zscan_rr.go has some funcky if-then-elses.
2015-02-19 09:58:33 +00:00
Flavien Lebarbe 067cfe8d4e Add support for HmacSHA512 algorithm in TSIG 2015-01-23 10:51:56 +01:00
Filippo Valsorda 0f1b1184ae Rename and simplify packing helper functions 2014-12-05 19:27:44 +00:00
Miek Gieben 6e3a9dd0d8 Fix tsig fudge factor
Excellent bug report from freb, about how this fails when a message
arrives in the past (because of clock skew).

Closes #153
2014-11-11 17:58:12 +00:00
Miek Gieben 0aa3021a83 Remove all copyright notices
Use the central COPYRIGHT file.
2014-09-11 20:57:37 +01:00
Miek Gieben 4dd48338af documentation tweaks 2014-07-30 07:35:06 +01:00
Andrew Tunnell-Jones 0a5cb5c80a Update TSIG doc header to avoid godoc oddity
For some reason godoc treats it as plain text because it contains
"(TSIG)".
2014-03-02 09:48:46 +00:00
Miek Gieben 83efab6078 Revert "Use dLen in TSIG too"
This reverts commit 37406413d7.
2014-02-14 20:05:51 +00:00
Miek Gieben 37406413d7 Use dLen in TSIG too 2014-02-12 12:51:13 +00:00
Andrew Tunnell-Jones 857a1c66cb Make TsigVerify's MAC comparison take constant time 2014-01-24 03:28:08 +00:00
Miek Gieben 37356f5e68 Documenation fixes 2014-01-12 10:43:59 +00:00
Miek Gieben 4862dd17b4 Slight doc updates 2013-10-12 19:19:24 +01:00
Miek Gieben 0134de62ed Fix TSIG/transfer documentation 2013-10-12 19:14:45 +01:00
Miek Gieben 81941d4422 Update all copyright notices 2013-05-12 16:15:52 +02:00
Miek Gieben d53d9eab81 gofmt 2013-05-05 20:30:44 +02:00
Miek Gieben c88ac95260 whitespace in comments 2013-03-18 17:37:49 +00:00
Miek Gieben cd10853288 Make Len() and Copy() private
I don't think anybody will needs these, msg.Len() is still
available. Severly cuts back on the amount of exported functions.
2013-02-09 08:35:17 +01:00
Miek Gieben 84983bc293 remove space 2013-02-09 08:17:05 +01:00
Miek Gieben 4a951fc1f8 Merge branch 'master' of github.com:miekg/dns 2012-12-14 12:35:25 +01:00
Miek Gieben 99817d7c33 Fix TSIG
If you even add a tag to a struct member, be sure to add that
tag to the other important structs too.
2012-12-13 13:44:27 +01:00
Miek Gieben 375917b7a0 update the todo 2012-12-13 13:10:34 +01:00
Miek Gieben 53dccfe5ed fix docs 2012-12-12 15:08:39 +01:00