From 20f52e16880210b1893d89e2d20819171632da32 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sun, 26 May 2024 15:37:58 +0200 Subject: Only bootstrap a compact range once per log As opposed to doing a new bootstrap with get-proof-by-hash every time the next root is constructed. Bootstrapping the compact range from a get-proof-by-hash query works for the most part, but fails if the log included a duplicate entry and gives us the index for that instead. Log operators with duplicate entries include Cloudflare and Digicert. If bootstrap fails (unlucky), we try to bootstrap again once the log's signed tree head moved forward (hoping the last entry has no duplicate). The more reliable way to bootstrap a compact range would be to use the get-entry-and-proof endpoint. This does not work in practise because some logs are not implementing this endpoint. Digicert has such logs. --- internal/ioutil/ioutil.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'internal/ioutil') diff --git a/internal/ioutil/ioutil.go b/internal/ioutil/ioutil.go index 7fe6cfc..8e98c65 100644 --- a/internal/ioutil/ioutil.go +++ b/internal/ioutil/ioutil.go @@ -1,6 +1,7 @@ package ioutil import ( + "crypto/sha256" "encoding/json" "fmt" "os" @@ -54,3 +55,34 @@ func DirectoriesExist(paths []string) error { } return nil } + +func CopyHashes(hashes [][sha256.Size]byte) (ret [][sha256.Size]byte) { + for _, hash := range hashes { + var dst [sha256.Size]byte + copy(dst[:], hash[:]) + ret = append(ret, dst) + } + return +} + +func SliceHashes(hashes [][sha256.Size]byte) (ret [][]byte) { + for _, hash := range hashes { + dst := hash + ret = append(ret, dst[:]) + } + return +} + +// UnsliceHashes panics unless all hashes are 32 bytes +func UnsliceHashes(hashes [][]byte) (ret [][sha256.Size]byte) { + for _, hash := range hashes { + if got, want := len(hash), sha256.Size; got != want { + panic(fmt.Sprintf("bug: invalid hash: size %d", got)) + } + + var dst [sha256.Size]byte + copy(dst[:], hash) + ret = append(ret, dst) + } + return +} -- cgit v1.2.3