Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TsigGenerate for non-0 TSIG error or non-empty other data #1138

Merged
merged 2 commits into from Jul 21, 2020

Conversation

jinmeiib
Copy link
Contributor

The current implementation of TsigGenerate ignores the TSIG error and other data fields of the TSIG RR in the passed DNS message for generating the signed binary-format message (it uses these fields correctly for computing the MAC). So the resulting message would fail to be verified at the recipient. This PR is a straightforward fix to this problem.

@@ -131,15 +131,11 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s
return nil, "", ErrKeyAlg
}
h.Write(buf)
// Copy all TSIG fields expect MAC and its size, which are filled using the computed digest.
*t = *rr
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could alternatively copy the error and other data (plus its length) fields separately below. I chose this way as it seemed more concise and less error prone (it's clear no fields are forgotten and all fields are an exact copy of the original TSIG RR), but I don't mind taking the alternative approach.

t.MAC = hex.EncodeToString(h.Sum(nil))
t.MACSize = uint16(len(t.MAC) / 2) // Size is half!

t.Hdr = RR_Header{Name: rr.Hdr.Name, Rrtype: TypeTSIG, Class: ClassANY, Ttl: 0}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: technically we can't always assume TTL is 0 here; the TSIG in the passed message could have a non-0 value (RFC2845 states it's 0 but doesn't prohibit using a different value). The fix in this PR preserves the passed TTL.

t.Fudge = rr.Fudge
t.TimeSigned = rr.TimeSigned
t.Algorithm = rr.Algorithm
t.OrigId = m.Id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also not always correct and should be rr.OrigId. The fix in this PR makes it correct, too.

Copy link
Collaborator

@tmthrgd tmthrgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of the RFC semantics, but seems reasonable and code looks fine. LGTM.

@jinmeiib
Copy link
Contributor Author

Not sure of the RFC semantics, but seems reasonable and code looks fine. LGTM.

@tmthrgd thank you for the prompt review and approval. Just to let you know I've just noticed one minor typo in a comment line and corrected it.

@miekg
Copy link
Owner

miekg commented Jul 21, 2020 via email

@cbot cbot bot merged commit f3da20b into miekg:master Jul 21, 2020
aanm pushed a commit to cilium/dns that referenced this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants