From 0e97b2d87222860e05c7d735a2159b54910190a4 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 24 Aug 2025 10:51:15 +0200 Subject: [PATCH] Add JSON output in gen-html --- tesseract/genconf/main.go | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tesseract/genconf/main.go b/tesseract/genconf/main.go index 28ed4a4..9484b1d 100644 --- a/tesseract/genconf/main.go +++ b/tesseract/genconf/main.go @@ -4,11 +4,13 @@ import ( "crypto/sha256" "crypto/x509" "encoding/base64" + "encoding/json" "encoding/pem" "flag" "fmt" "log" "os" + "path/filepath" "text/template" "time" @@ -39,6 +41,7 @@ type Log struct { LogID string PublicKeyPEM string PublicKeyDERB64 string + PublicKeyBase64 string } const htmlTemplate = ` @@ -206,6 +209,14 @@ func generateHTML(yamlFile string) { file.Close() fmt.Printf("Generated %s\n", indexPath) + + // Generate log.v3.json for this log + jsonPath := filepath.Join(logEntry.LocalDirectory, "log.v3.json") + err = generateLogJSON(logEntry, jsonPath) + if err != nil { + log.Fatalf("Failed to generate %s: %v", jsonPath, err) + } + fmt.Printf("Generated %s\n", jsonPath) } } @@ -254,6 +265,49 @@ func computeKeyInfo(logEntry *Log) error { logEntry.LogID = logID logEntry.PublicKeyPEM = string(pubKeyPEM) logEntry.PublicKeyDERB64 = pubKeyDERB64 + logEntry.PublicKeyBase64 = pubKeyDERB64 // Same as DER base64 for JSON + + return nil +} + +type LogV3JSON struct { + Description string `json:"description"` + SubmissionURL string `json:"submission_url"` + MonitoringURL string `json:"monitoring_url"` + TemporalInterval TemporalInterval `json:"temporal_interval"` + LogID string `json:"log_id"` + Key string `json:"key"` + MMD int `json:"mmd"` +} + +type TemporalInterval struct { + StartInclusive string `json:"start_inclusive"` + EndExclusive string `json:"end_exclusive"` +} + +func generateLogJSON(logEntry Log, outputPath string) error { + logJSON := LogV3JSON{ + Description: fmt.Sprintf("%s.log.ct.ipng.ch", logEntry.ShortName), + SubmissionURL: fmt.Sprintf("%s/", logEntry.SubmissionPrefix), + MonitoringURL: fmt.Sprintf("%s/", logEntry.MonitoringPrefix), + TemporalInterval: TemporalInterval{ + StartInclusive: logEntry.NotAfterStart.Format("2006-01-02T15:04:05Z"), + EndExclusive: logEntry.NotAfterLimit.Format("2006-01-02T15:04:05Z"), + }, + LogID: logEntry.LogID, + Key: logEntry.PublicKeyBase64, + MMD: 60, // Default MMD of 60 seconds + } + + jsonData, err := json.MarshalIndent(logJSON, "", " ") + if err != nil { + return fmt.Errorf("failed to marshal JSON: %v", err) + } + + err = os.WriteFile(outputPath, jsonData, 0644) + if err != nil { + return fmt.Errorf("failed to write JSON file: %v", err) + } return nil }