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

Use golang.org/x/crypto/cryptobyte to unpack DNS records #1507

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a4fd336
Use golang.org/x/crypto/cryptobyte to unpack DNS records
tmthrgd Nov 6, 2023
00fe85c
Eliminate dnsString type
tmthrgd Nov 7, 2023
a205faf
Use cryptobyte.String to unpack EDNS0 and SVCB values
tmthrgd Nov 7, 2023
3e37cee
Be consistent in how we declare cryptobyte.String's in tests
tmthrgd Nov 7, 2023
ed4bfbb
Avoid *cryptobyte.String allocation in UnpackDomainName
tmthrgd Nov 7, 2023
a286fbc
Refactor DNS message unpacking behaviour
tmthrgd Nov 7, 2023
293f1d3
Return final offset when UnpackRR(WithHeader) errors
tmthrgd Nov 7, 2023
785960e
Fix TestTruncatedMsg logic
tmthrgd Nov 7, 2023
857cbcf
Replace errUnpack(Signed)Overflow with ErrBuf
tmthrgd Nov 7, 2023
acaf1b4
Delete TestTruncatedMsg
tmthrgd Nov 7, 2023
1b5a3fa
Allow unpackCounted to return partial results
tmthrgd Nov 7, 2023
c4db081
Avoid passing *cryptobyte.String through an interface
tmthrgd Nov 7, 2023
1150c4f
Remove header count updates in (*Msg).unpack
tmthrgd Nov 7, 2023
f4aaceb
Un-genericfy unpackCounted
tmthrgd Nov 8, 2023
689bd5d
Introduce offset helper
tmthrgd Nov 8, 2023
390ac04
Fix pointer offset check in unpackDomainName
tmthrgd Nov 8, 2023
73318a7
Remove `_ = s` from generated unpack code
tmthrgd Nov 8, 2023
6b408b5
Avoid spilling RR_Header to heap in unpacking happy path
tmthrgd Nov 8, 2023
198f1a8
Rename msg *cryptobyte.String when not specifically referring to the …
tmthrgd Nov 8, 2023
f13deab
Be consistent in how we format EDNS0 methods
tmthrgd Nov 8, 2023
c74fce5
Restore SVCB_NO_DEFAULT_ALPN test case in TestDecodeBadSVCB
tmthrgd Nov 8, 2023
0f65f64
Use semantically sensible error messages when unpacking
tmthrgd Nov 8, 2023
c347f2f
Report unpacking success rather than error for EDNS0 and SVCBKeyValue
tmthrgd Nov 8, 2023
9b4c3a9
Report unpacking success rather than error for unpackMsgHdr
tmthrgd Nov 8, 2023
69b9deb
Add TODOs and comments around dynamic updates and lax unpacking
tmthrgd Nov 8, 2023
8b86ec4
Address review comments
tmthrgd Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ func (co *Conn) ReadMsgHeader(hdr *Header) ([]byte, error) {

p = p[:n]
if hdr != nil {
dh, _, err := unpackMsgHdr(p, 0)
s := newDNSString(p, 0)
dh, err := unpackMsgHdr(s)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type RR interface {
//
// This will only be called on a new and empty RR type with only the header populated. It
// will only be called if the record's RDATA is non-empty.
unpack(msg []byte, off int) (off1 int, err error)
unpack(msg *dnsString) error

// parse parses an RR from zone file format.
//
Expand Down Expand Up @@ -104,7 +104,7 @@ func (h *RR_Header) pack(msg []byte, off int, compression compressionMap, compre
return off, nil
}

func (h *RR_Header) unpack(msg []byte, off int) (int, error) {
func (h *RR_Header) unpack(msg *dnsString) error {
panic("dns: internal error: unpack should never be called on RR_Header")
}

Expand All @@ -128,8 +128,8 @@ func (rr *RFC3597) ToRFC3597(r RR) error {
return nil
}

_, err = rr.unpack(buf, headerEnd)
return err
s := newDNSString(buf, headerEnd)
return rr.unpack(s)
}

// fromRFC3597 converts an unknown RR representation from RFC 3597 to the known RR type.
Expand All @@ -153,6 +153,6 @@ func (rr *RFC3597) fromRFC3597(r RR) error {
return err
}

_, err = r.unpack(msg, 0)
return err
s := newDNSString(msg, 0)
return r.unpack(s)
}
3 changes: 1 addition & 2 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func TestMsgPackBuffer(t *testing.T) {
input, _ := hex.DecodeString(hexData)
m := new(Msg)
if err := m.Unpack(input); err != nil {
t.Errorf("packet %d failed to unpack", i)
continue
t.Errorf("packet %d failed to unpack: %v", i, err)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/miekg/dns
go 1.19

require (
golang.org/x/crypto v0.14.0
golang.org/x/net v0.17.0
golang.org/x/sync v0.4.0
golang.org/x/sys v0.13.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
Expand Down
Loading
Loading