mirror of
https://github.com/SSLMate/certspotter.git
synced 2025-07-01 10:35:33 +02:00

Specifically, certspotter no longer terminates unless it receives SIGTERM or SIGINT or there is a serious error. Although using cron made sense in the early days of Certificate Transparency, certspotter now needs to run continuously to reliably keep up with the high growth rate of contemporary CT logs, and to gracefully handle the many transient errors that can arise when monitoring CT. Closes: #63 Closes: #37 Closes: #32 (presumably by eliminating $DNS_NAMES and $IP_ADDRESSES) Closes: #21 (with $WATCH_ITEM) Closes: #25
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
// Copyright (C) 2023 Opsmate, Inc.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
// Public License, v. 2.0. If a copy of the MPL was not distributed
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
//
|
|
// This software is distributed WITHOUT A WARRANTY OF ANY KIND.
|
|
// See the Mozilla Public License for details.
|
|
|
|
package monitor
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"software.sslmate.com/src/certspotter/ct"
|
|
"software.sslmate.com/src/certspotter/merkletree"
|
|
"time"
|
|
)
|
|
|
|
type stateFile struct {
|
|
DownloadPosition *merkletree.CollapsedTree `json:"download_position"`
|
|
VerifiedPosition *merkletree.CollapsedTree `json:"verified_position"`
|
|
VerifiedSTH *ct.SignedTreeHead `json:"verified_sth"`
|
|
LastSuccess time.Time `json:"last_success"`
|
|
}
|
|
|
|
func loadStateFile(filePath string) (*stateFile, error) {
|
|
fileBytes, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
file := new(stateFile)
|
|
if err := json.Unmarshal(fileBytes, file); err != nil {
|
|
return nil, fmt.Errorf("error parsing %s: %w", filePath, err)
|
|
}
|
|
return file, nil
|
|
}
|
|
|
|
func (file *stateFile) store(filePath string) error {
|
|
fileBytes, err := json.Marshal(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fileBytes = append(fileBytes, '\n')
|
|
return writeFile(filePath, fileBytes, 0666)
|
|
}
|