Skip to content

Commit 35d8c65

Browse files
committed
[SumDB] Non-verifiable SumDB info support
This allows users to run this without a verifiable index. If you fully trust SumDB and don't want to verify it, then this is probably good enough.
1 parent 2119fa0 commit 35d8c65

File tree

2 files changed

+76
-16
lines changed

2 files changed

+76
-16
lines changed

vindex/cmd/sumdbverify/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## SumDB Verify
22

33
> [!IMPORTANT]
4-
> This tool requires a [SumDB VIndex](../sumdb/) to be running.
5-
> Functionality may be added to support reading SumDB contents from non-verifiable endpoints.
4+
> Proper use of this tool requires a [SumDB VIndex](../sumdb/) to be running.
5+
> See [Running non-verifiably](#running-non-verifiably) for the quick and dirty way.
66
77
This tool checks that the contents for a module in SumDB match the state as represented in a local git repository.
88
The command below shows the output for this command querying a local checkout of `github.com/transparency-dev/tessera`:
@@ -27,11 +27,31 @@ v1.0.0 43930254 ✅ ✅ ✅
2727

2828
The output shows all versions present in SumDB, and for each:
2929
- INDEX is the leaf index of this `module@version` in SumDB
30-
- FOUND shows that a tag with the same version string was found in the git version
30+
- FOUND shows that a tag with the same version string was found in the git repository
3131
- go.mod shows that the hashes for the `go.mod` file match. In addition to the green tick, there are two other states:
3232
- ⚠️: no `go.mod` file was found in the git repo at the tagged version; this _could_ be a release from before modules were adopted
3333
- ❌: a `go.mod` file was found in the git repo, but the hash doesn't match that in SumDB. Either the tag was changed, or SumDB is hosting bad content.
3434
- zip shows that the hashes for the zip containing the source code match. In addition to the green tick, there are two other states:
3535
- ⚠️: no `go.mod` file was found in the git repo at the tagged version; this _could_ be a release from before modules were adopted
3636
- ❌: the zip file hash did not match that in SumDB. Either the tag was changed, or SumDB is hosting bad content.
3737

38+
### Running non-verifiably
39+
40+
By omitting the `--base_url` and `--out_log_pub_key` flags, the SumDB information will be fetched from non-verifiable endpoints.
41+
This is useful for casual testing before a public-good instance of the SumDB verifiable index is available.
42+
43+
```shell
44+
go run ./vindex/cmd/sumdbverify --mod_root ~/git/tessera
45+
46+
W1002 13:31:48.254094 2883468 client.go:84] --base_url is not provided. Using NON-VERIFIABLE lookup to source SumDB data.
47+
github.com/transparency-dev/tessera (./go.mod)
48+
VERSION INDEX FOUND go.mod zip
49+
v0.1.0 37258761 ✅ ✅ ✅
50+
v0.1.1 37258762 ✅ ✅ ✅
51+
v0.1.2 37258746 ✅ ✅ ✅
52+
v0.2.0 38108519 ✅ ✅ ✅
53+
v1.0.0-rc1 41510961 ✅ ✅ ✅
54+
v1.0.0-rc2 42710781 ✅ ✅ ✅
55+
v1.0.0-rc3 43267373 ✅ ✅ ✅
56+
v1.0.0 43930254 ✅ ✅ ✅
57+
```

vindex/cmd/sumdbverify/client.go

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package main
1919

2020
import (
21+
"bytes"
2122
"context"
2223
"errors"
2324
"flag"
@@ -71,24 +72,63 @@ func main() {
7172
}
7273

7374
func run(ctx context.Context) error {
74-
if *baseURL == "" {
75-
return errors.New("base_url flag must be provided")
76-
}
77-
if *outLogPubKey == "" {
78-
return errors.New("out_log_pub_key flag must be provided")
79-
}
8075
if *modRoot == "" {
8176
return errors.New("mod_root flag must be provided")
8277
}
8378

84-
// TODO(mhutchinson): Support a non-VIndex version of this that reads the non-verifiable proxy endpoints:
85-
// 1) https://proxy.golang.org/github.com/transparency-dev/tessera/@v/list
86-
// 2) https://sum.golang.org/lookup/github.com/transparency-dev/tessera@v1.0.0
87-
// This will provide a way to use this tool before the VIndex is widely available
88-
sumFetcher := func(ctx context.Context, modName string) (map[string]modData, error) {
89-
vic := newVIndexClientFromFlags()
79+
var sumFetcher func(ctx context.Context, modName string) (map[string]modData, error)
80+
if *baseURL == "" {
81+
klog.Warningf("--base_url is not provided. Using NON-VERIFIABLE lookup to source SumDB data.")
82+
83+
// This constructs the map non-verifiably by calling similar URLs to these:
84+
// 1) https://proxy.golang.org/github.com/transparency-dev/tessera/@v/list
85+
// 2) https://sum.golang.org/lookup/github.com/transparency-dev/tessera@v1.0.0
86+
sumFetcher = func(ctx context.Context, modName string) (map[string]modData, error) {
87+
result := make(map[string]modData)
88+
resp, err := http.Get(fmt.Sprintf("https://proxy.golang.org/%s/@v/list", modName))
89+
if err != nil {
90+
return nil, fmt.Errorf("failed to get module listing: %v", err)
91+
}
92+
body, err := io.ReadAll(resp.Body)
93+
if err != nil {
94+
return nil, fmt.Errorf("failed to get module listing: %v", err)
95+
}
96+
for v := range strings.Lines(string(body)) {
97+
v = strings.TrimSpace(v)
98+
resp, err = http.Get(fmt.Sprintf("https://sum.golang.org/lookup/%s@%s", modName, v))
99+
if err != nil {
100+
return nil, fmt.Errorf("failed to get version info: %v", err)
101+
}
102+
body, err = io.ReadAll(resp.Body)
103+
if err != nil {
104+
return nil, fmt.Errorf("failed to get version info: %v", err)
105+
}
106+
lines := bytes.Split(body, []byte{'\n'})
107+
idx, err := strconv.ParseInt(string(lines[0]), 10, 64)
108+
if err != nil {
109+
return nil, fmt.Errorf("failed to parse index: %v", err)
110+
}
111+
leaf := append(append(append(lines[1], byte('\n')), lines[2]...), byte('\n'))
112+
v2, md, err := parseLeaf(uint64(idx), leaf)
113+
if err != nil {
114+
return nil, fmt.Errorf("failed to parse leaf: %v", err)
115+
}
116+
if v != v2 {
117+
return nil, fmt.Errorf("performed lookup for %s@%s but got version %s", modName, v, v2)
118+
}
119+
result[v] = md
120+
}
121+
return result, nil
122+
}
90123

91-
return queryIndex(ctx, vic, modName)
124+
} else {
125+
if *outLogPubKey == "" {
126+
return errors.New("out_log_pub_key flag must be provided if --base_url is provided")
127+
}
128+
sumFetcher = func(ctx context.Context, modName string) (map[string]modData, error) {
129+
vic := newVIndexClientFromFlags()
130+
return queryIndex(ctx, vic, modName)
131+
}
92132
}
93133

94134
report, reportErr := getReport(ctx, *modRoot, sumFetcher)

0 commit comments

Comments
 (0)