Add JSON output in gen-html
This commit is contained in:
@@ -4,11 +4,13 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ type Log struct {
|
|||||||
LogID string
|
LogID string
|
||||||
PublicKeyPEM string
|
PublicKeyPEM string
|
||||||
PublicKeyDERB64 string
|
PublicKeyDERB64 string
|
||||||
|
PublicKeyBase64 string
|
||||||
}
|
}
|
||||||
|
|
||||||
const htmlTemplate = `<!DOCTYPE html>
|
const htmlTemplate = `<!DOCTYPE html>
|
||||||
@@ -206,6 +209,14 @@ func generateHTML(yamlFile string) {
|
|||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
fmt.Printf("Generated %s\n", indexPath)
|
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.LogID = logID
|
||||||
logEntry.PublicKeyPEM = string(pubKeyPEM)
|
logEntry.PublicKeyPEM = string(pubKeyPEM)
|
||||||
logEntry.PublicKeyDERB64 = pubKeyDERB64
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user