From d8b1877e8dbb3ff121da59ee56aa934a499b6ee7 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Fri, 6 Jan 2017 12:51:10 -0800 Subject: [PATCH] Improve filenames of unverified STHs Include the tree size in plain decimal, since it's more user-friendly. Don't include tree size in hash (redundant now that we're storing it outside of hash) or version (implied by signature). --- cmd/log_state.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/log_state.go b/cmd/log_state.go index e51a627..aeba9ba 100644 --- a/cmd/log_state.go +++ b/cmd/log_state.go @@ -16,6 +16,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "strings" "software.sslmate.com/src/certspotter" @@ -31,15 +32,13 @@ func sthFilename (sth *ct.SignedTreeHead) string { hasher := sha256.New() switch sth.Version { case ct.V1: - binary.Write(hasher, binary.LittleEndian, sth.Version) - binary.Write(hasher, binary.LittleEndian, sth.TreeSize) binary.Write(hasher, binary.LittleEndian, sth.Timestamp) binary.Write(hasher, binary.LittleEndian, sth.SHA256RootHash) default: panic(fmt.Sprintf("Unsupported STH version %d", sth.Version)) } // For 6962-bis, we will need to handle a variable-length root hash, and include the signature in the filename hash (since signatures must be deterministic) - return base64.RawURLEncoding.EncodeToString(hasher.Sum(nil)) + return strconv.FormatUint(sth.TreeSize, 10) + "-" + base64.RawURLEncoding.EncodeToString(hasher.Sum(nil)) } func makeLogStateDir (logStatePath string) error {