Skip to content

Commit

Permalink
Incorrect HIP RR public key length decode (#1262)
Browse files Browse the repository at this point in the history
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='
  • Loading branch information
joseph-stanton-ax authored May 13, 2021
1 parent d2b5d38 commit 9922549
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scan_rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9922549

Please sign in to comment.