aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go70
1 files changed, 55 insertions, 15 deletions
diff --git a/main.go b/main.go
index 9a62ac3..f1d200b 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"log"
+ "sync"
"time"
"git.sr.ht/~benburwell/gosumdbaudit/sumdb"
@@ -18,23 +19,62 @@ func main() {
pollInterval: 10 * time.Second,
},
}
+ var wg sync.WaitGroup
+ wg.Add(len(dbs))
for _, db := range dbs {
- client := sumdb.NewClient(db)
- // lines, err := client.Lookup("golang.org/x/text", "v0.3.0")
- lines, err := client.Lookup("github.com/influxdata/influxdb", "v0.0.0-20190908081120-80e3efa37a3a")
- if err != nil {
- log.Printf("could not lookup: %v", err)
- } else {
- for _, line := range lines {
- log.Printf("got: %s", line)
+ go func(db *database) {
+ defer wg.Done()
+ if err := monitor(db); err != nil {
+ log.Printf("AUDIT FAILED: %s", err.Error())
+ return
}
- }
- // log.Printf("config: %s", string(db.config["sum.golang.org/latest"]))
- // if err := d.monitor(); err != nil {
- // log.Printf("AUDIT FAIL (%s): %s", d.host, err.Error())
- // }
- // if err := audit(d); err != nil {
- // log.Printf("AUDIT FAIL (%s): %s", d.host, err.Error())
+ }(db)
+ }
+ wg.Wait()
+}
+
+func monitor(db *database) error {
+ log.Printf("starting monitor for %s", db.host)
+
+ client := sumdb.NewClient(db)
+
+ lines, err := client.Lookup("golang.org/x/text", "v0.3.0")
+ if err != nil {
+ return err
+ }
+ log.Printf("got lines: %s", lines)
+
+ // fetch & verify current STH
+ // latest, err := client.Latest()
+ // if err != nil {
+ // return err
+ // }
+
+ // fetch all entries in the tree according to the STH
+ // entries := client.Entries(nil, latest)
+
+ // confirm the tree made from the entries produces the same hash as the STH
+ // IF NOT: the server has signed invalid data
+
+ // prev := latest
+ for {
+ // await a new STH
+ // prev = latest
+ time.Sleep(db.pollInterval)
+ log.Printf("checking %s for new STH...", db.host)
+ // awaitNewSTH()
+
+ // latest, err := client.Latest()
+ // if err != nil {
+ // return err
// }
+
+ // fetch all NEW entries between prev and latest
+ // if unavailable for an extended period, this should be viewed as misbehavior
+ // entries := client.Entries(prev, latest)
+
+ // fetch a consistency proof for the new STH with the previous STH
+ // verify consistency proof
+ // verify the new entries generate the corresponding elements in the consistency proof
}
}