From c6e6be4e71b569fc8da3c6a959c9dd75bc691187 Mon Sep 17 00:00:00 2001 From: Adit Sachde <23707194+aditsachde@users.noreply.github.com> Date: Sat, 3 Aug 2024 12:56:10 -0700 Subject: [PATCH] encode fingerprint length correctly --- internal/sunlight/tile_ol.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/sunlight/tile_ol.go b/internal/sunlight/tile_ol.go index aaa01af..f87702b 100644 --- a/internal/sunlight/tile_ol.go +++ b/internal/sunlight/tile_ol.go @@ -169,10 +169,11 @@ func ReadTileLeaf(tile []byte) (e *LogEntry, rest []byte, err error) { } // look at first byte to determine the length of the chain - var fingerprintCount uint16 - if !s.ReadUint16(&fingerprintCount) { + var fingerprintBytes uint16 + if !s.ReadUint16(&fingerprintBytes) { return nil, s, fmt.Errorf("invalid data tile precert_entry") } + var fingerprintCount = fingerprintBytes / 32 // then, try to read out that many fingerprints e.ChainFp = make([][32]byte, 0, fingerprintCount) for i := uint16(0); i < fingerprintCount; i++ { @@ -217,7 +218,8 @@ func AppendTileLeaf(t []byte, e *LogEntry) []byte { b.AddBytes(e.PreCertificate) }) } - b.AddUint16(uint16(len(e.ChainFp))) + // A Fingerprint is always 32 bytes and the length is the total number of bytes + b.AddUint16(uint16(len(e.ChainFp) * 32)) for _, fingerprint := range e.ChainFp { b.AddBytes(fingerprint[:]) }