Skip to content

Commit 9922549

Browse files
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='
1 parent d2b5d38 commit 9922549

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scan_rr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,11 @@ func (rr *HIP) parse(c *zlexer, o string) *ParseError {
734734
return &ParseError{"", "bad HIP PublicKey", l}
735735
}
736736
rr.PublicKey = l.token // This cannot contain spaces
737-
rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey)))
737+
decodedPK, decodedPKerr := base64.StdEncoding.DecodeString(rr.PublicKey)
738+
if decodedPKerr != nil{
739+
return &ParseError{"", "bad HIP PublicKey", l}
740+
}
741+
rr.PublicKeyLength = uint16(len(decodedPK))
738742

739743
// RendezvousServers (if any)
740744
l, _ = c.Next()

0 commit comments

Comments
 (0)