From 99225496214f6ec3ab662927271d27bebb0f9989 Mon Sep 17 00:00:00 2001 From: joseph-stanton-ax <69203260+joseph-stanton-ax@users.noreply.github.com> Date: Thu, 13 May 2021 03:33:12 -0400 Subject: [PATCH] Incorrect HIP RR public key length decode (#1262) When decoding a HIP resource record, 'base64.StdEncoding.DecodedLen' can return a length larger than the length of the decoded public key. This change decodes the public key and retrieves the correct length. In our tests, the public key length was being set to 33, instead of 32. Below is our offending resource record: '23b5993f649c0827.a.b.c. 3600 IN HIP 5 200100100020001523B5993F649C0827 Cm6k4jhir9YYoKq9JDqD3Ob1hBfCuwbWam1igFPhkGg=' --- scan_rr.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scan_rr.go b/scan_rr.go index 05765aed..c52e065b 100644 --- a/scan_rr.go +++ b/scan_rr.go @@ -734,7 +734,11 @@ func (rr *HIP) parse(c *zlexer, o string) *ParseError { return &ParseError{"", "bad HIP PublicKey", l} } rr.PublicKey = l.token // This cannot contain spaces - rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey))) + decodedPK, decodedPKerr := base64.StdEncoding.DecodeString(rr.PublicKey) + if decodedPKerr != nil{ + return &ParseError{"", "bad HIP PublicKey", l} + } + rr.PublicKeyLength = uint16(len(decodedPK)) // RendezvousServers (if any) l, _ = c.Next()