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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 except MAC and its size, which are filled using the computed digest. | ||
*t = *rr | ||
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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also not always correct and should be |
||
|
||
tbuf := make([]byte, Len(t)) | ||
off, err := PackRR(t, tbuf, 0, nil, false) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
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.