Skip to content

Commit 3d9ea25

Browse files
authored
Removed obsolete sumdbaudit command (#983)
This has been replaced with sumdbverify, which now has useful information that was in the sumdbaudit README incorporated
1 parent 0130d2c commit 3d9ea25

File tree

12 files changed

+35
-1355
lines changed

12 files changed

+35
-1355
lines changed

sumdbaudit/client/sumdb.go clone/cmd/sumdbclone/internal/client/sumdb.go

+6-49
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package client
1717

1818
import (
19+
"bytes"
1920
"fmt"
2021
"io"
2122
"net/http"
@@ -72,11 +73,6 @@ func (c *SumDBClient) LatestCheckpoint() (*Checkpoint, error) {
7273
return nil, fmt.Errorf("failed to get /latest Checkpoint; %w", err)
7374
}
7475

75-
return c.ParseCheckpointNote(checkpoint)
76-
}
77-
78-
// ParseCheckpointNote parses a previously acquired raw checkpoint note data.
79-
func (c *SumDBClient) ParseCheckpointNote(checkpoint []byte) (*Checkpoint, error) {
8076
verifier, err := note.NewVerifier(c.vkey)
8177
if err != nil {
8278
return nil, fmt.Errorf("failed to create verifier: %w", err)
@@ -126,46 +122,11 @@ func (c *SumDBClient) tilePath(offset int) string {
126122
}
127123

128124
func dataToLeaves(data []byte) [][]byte {
129-
result := make([][]byte, 0)
130-
start := 0
131-
for i, b := range data {
132-
if b == '\n' {
133-
if i > start && data[i-1] == '\n' {
134-
result = append(result, data[start:i])
135-
start = i + 1
136-
}
137-
}
125+
leaves := bytes.Split(data, []byte{'\n', '\n'})
126+
for i, l := range leaves {
127+
leaves[i] = append(l, '\n')
138128
}
139-
result = append(result, data[start:])
140-
return result
141-
}
142-
143-
// TileHashes gets the hashes at the given level and offset.
144-
// If partial > 0 then a partial tile will be fetched with the number of hashes.
145-
// TODO(mhutchinson): Add better tests for this.
146-
func (c *SumDBClient) TileHashes(level, offset, partial int) ([]tlog.Hash, error) {
147-
url := fmt.Sprintf("/tile/%d/%d/%s", c.height, level, c.tilePath(offset))
148-
if partial > 0 {
149-
url = fmt.Sprintf("%s.p/%d", url, partial)
150-
}
151-
data, err := c.fetcher.GetData(url)
152-
if err != nil {
153-
return nil, err
154-
}
155-
expectedHashes := 1 << c.height
156-
if partial > 0 {
157-
expectedHashes = partial
158-
}
159-
if got, want := len(data), HashLenBytes*expectedHashes; got != want {
160-
return nil, fmt.Errorf("got %d bytes, expected %d", got, want)
161-
}
162-
hashes := make([]tlog.Hash, expectedHashes)
163-
for i := 0; i < cap(hashes); i++ {
164-
var h tlog.Hash
165-
copy(h[:], data[HashLenBytes*i:HashLenBytes*(i+1)])
166-
hashes[i] = h
167-
}
168-
return hashes, nil
129+
return leaves
169130
}
170131

171132
// HTTPFetcher gets the data over HTTP(S).
@@ -189,9 +150,5 @@ func (f *HTTPFetcher) GetData(path string) ([]byte, error) {
189150
if resp.StatusCode != 200 {
190151
return nil, fmt.Errorf("GET %v: %v", target, resp.Status)
191152
}
192-
data, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
193-
if err != nil {
194-
return nil, err
195-
}
196-
return data, nil
153+
return io.ReadAll(io.LimitReader(resp.Body, 1<<20))
197154
}

sumdbaudit/client/sumdb_test.go clone/cmd/sumdbclone/internal/client/sumdb_test.go

-24
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package client
1616

1717
import (
1818
"bytes"
19-
"encoding/hex"
2019
"fmt"
2120
"testing"
2221

@@ -43,8 +42,6 @@ kn9DgqDhXzoZMM8828SQsbuovr/WRn7QfFd5Qe1rpwA=
4342
4443
— sum.golang.org Az3grunuggF5mKymPJeK/l9Pq71lOg/rAVkQVCzGkWRJcnS3ZFunzveHr9PAH8LFsuhpcCWzGDNrn9FFDyXm/66tBg8=
4544
`
46-
47-
tileHashData = `d7b9018cbad2a2fa3950dcd60411cd67ef9d8c1074043c0e033953ec510fd68413f83190fb460efeb65670f9298b4249b8b5fd2492a6cd486f1fe14bfa3eb545590ac0de6fc0f9b016875ba518353cc57654df733f2fa1d1f0dad66f84b66d9ea2744fc0a64bb00d9f286c52838284b4b76bcbe895854d4709c55df1c266b681`
4845
)
4946

5047
func TestLeavesAtOffset(t *testing.T) {
@@ -100,27 +97,6 @@ func TestLatestCheckpoint(t *testing.T) {
10097
}
10198
}
10299

103-
func TestTileHashes(t *testing.T) {
104-
hashData, err := hex.DecodeString(tileHashData)
105-
if err != nil {
106-
t.Fatalf("failed to decode hash data: %v", err)
107-
}
108-
sumdb := &SumDBClient{
109-
vkey: "sum.golang.org+033de0ae+Ac4zctda0e5eza+HJyk9SxEdh+s3Ux18htTTAD8OuAn8",
110-
height: 2,
111-
fetcher: &FakeFetcher{
112-
values: map[string]string{"/tile/2/0/000": string(hashData)},
113-
},
114-
}
115-
hashes, err := sumdb.TileHashes(0, 0, 0)
116-
if err != nil {
117-
t.Fatalf("failed to get hashes: %v", err)
118-
}
119-
if got, want := len(hashes), 4; got != want {
120-
t.Errorf("got, want = %d, %d", got, want)
121-
}
122-
}
123-
124100
type FakeFetcher struct {
125101
values map[string]string
126102
}

clone/cmd/sumdbclone/sumdbclone.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525

2626
"github.com/cenkalti/backoff/v4"
2727
"github.com/golang/glog"
28+
sdbclient "github.com/google/trillian-examples/clone/cmd/sumdbclone/internal/client"
2829
"github.com/google/trillian-examples/clone/internal/cloner"
2930
"github.com/google/trillian-examples/clone/internal/verify"
3031
"github.com/google/trillian-examples/clone/logdb"
31-
sdbclient "github.com/google/trillian-examples/sumdbaudit/client"
3232
"github.com/transparency-dev/merkle/rfc6962"
3333

3434
_ "github.com/go-sql-driver/mysql"

clone/cmd/sumdbverify/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@ This tool clones the log for sum.golang.org and ensures that:
44
1. The cloned data matches the commitments made in the log checkpoint
55
2. That no module + version is declared with different hashes in the log
66

7+
## Background
8+
9+
This is a quick summary of https://blog.golang.org/module-mirror-launch but is not
10+
intended to replace this introduction.
11+
If you have no context on Go SumDB, read that intro first :-)
12+
13+
Go SumDB is a Verifiable Log based on Trillian, which contains entries of the form:
14+
```
15+
github.com/google/trillian v1.3.11 h1:pPzJPkK06mvXId1LHEAJxIegGgHzzp/FUnycPYfoCMI=
16+
github.com/google/trillian v1.3.11/go.mod h1:0tPraVHrSDkA3BO6vKX67zgLXs6SsOAbHEivX+9mPgw=
17+
```
18+
Every module & version used in the Go ecosystem will have such an entry in this log,
19+
and the values are hashes which commit to the state of the repository and its `go.mod`
20+
file at that particular version.
21+
22+
Clients can be assured that they have downloaded the same version of a module as
23+
everybody else provided all of the following are true:
24+
1. The hash of what they have downloaded matches an entry in the SumDB Log
25+
2. There is only one entry in the Log for the `module@version`
26+
3. Entries in the Log are immutable / the Log is append-only
27+
4. Everyone else sees the same Log as this user
28+
29+
Verification of these is performed by different parties:
30+
1. The client checks an inclusion proof for their {module, version, hashes} in the Log
31+
2. This `sumdbverify` tool verifies there are no conflicting versions
32+
3. A [witness](https://github.com/transparency-dev/witness) verifies the log is append-only
33+
4. A [distributor](https://github.com/transparency-dev/distributor) aggregates multiple witness confirmations to verify consensus
34+
735
## Running in Docker
836

937
The `docker-compose` scripts in this directory allow for deployment of the `sumdbclone` tool in a single command:

sumdbaudit/README.md

-155
This file was deleted.

0 commit comments

Comments
 (0)