aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/add-entry/main.go14
-rw-r--r--client/client.go4
-rw-r--r--server/descriptor/.descriptor.go.swpbin12288 -> 0 bytes
-rw-r--r--server/descriptor/descriptor.go10
-rw-r--r--server/descriptor/descriptor_test.go8
5 files changed, 15 insertions, 21 deletions
diff --git a/client/add-entry/main.go b/client/add-entry/main.go
index 693aca8..e782b09 100644
--- a/client/add-entry/main.go
+++ b/client/add-entry/main.go
@@ -89,17 +89,9 @@ func setup() (*client.Client, error) {
return nil, fmt.Errorf("failed decoding log identifier: %v", err)
}
- // TODO: define FindLog() for []Operator
- var log *descriptor.Log
- for _, op := range ops {
- l, err := op.FindLog(id)
- if err == nil {
- log = l
- break
- }
- }
- if log == nil {
- return nil, fmt.Errorf("unknown log identifier: %v", err)
+ log, err := descriptor.FindLog(ops, id)
+ if err != nil {
+ return nil, err
}
return client.NewClient(log, &http.Client{}, c, &k), nil
}
diff --git a/client/client.go b/client/client.go
index e1663a0..bf854b9 100644
--- a/client/client.go
+++ b/client/client.go
@@ -50,7 +50,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI
}{
Item: base64.StdEncoding.EncodeToString(leaf),
Scheme: uint16(tls.Ed25519),
- Signature: base64.StdEncoding.EncodeToString(ed25519.Sign(*c.PrivateKey, serialized)),
+ Signature: base64.StdEncoding.EncodeToString(ed25519.Sign(*c.PrivateKey, leaf)),
Chain: c.b64Chain(),
})
if err != nil {
@@ -79,7 +79,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI
if item.Format != stfe.StFormatSignedDebugInfoV1 {
return nil, fmt.Errorf("bad StItem format: %v", item.Format)
}
- if err := item.SignedDebugInfoV1.Verify(c.Log.Scheme, c.Log.PublicKey, serialized); err != nil {
+ if err := item.SignedDebugInfoV1.Verify(c.Log.Scheme, c.Log.PublicKey, leaf); err != nil {
return nil, fmt.Errorf("bad SignedDebugInfoV1 signature: %v", err)
}
return &item, nil
diff --git a/server/descriptor/.descriptor.go.swp b/server/descriptor/.descriptor.go.swp
deleted file mode 100644
index e12d5cd..0000000
--- a/server/descriptor/.descriptor.go.swp
+++ /dev/null
Binary files differ
diff --git a/server/descriptor/descriptor.go b/server/descriptor/descriptor.go
index ba90289..016d1cc 100644
--- a/server/descriptor/descriptor.go
+++ b/server/descriptor/descriptor.go
@@ -30,10 +30,12 @@ type Log struct {
BaseUrl string `json:"base_url"` // E.g., example.com/st/v1
}
-func (op *Operator) FindLog(logId []byte) (*Log, error) {
- for _, log := range op.Logs {
- if bytes.Equal(logId, log.Id) {
- return log, nil
+func FindLog(ops []Operator, logId []byte) (*Log, error) {
+ for _, op := range ops {
+ for _, log := range op.Logs {
+ if bytes.Equal(logId, log.Id) {
+ return log, nil
+ }
}
}
return nil, fmt.Errorf("no such log: %s", base64.StdEncoding.EncodeToString(logId))
diff --git a/server/descriptor/descriptor_test.go b/server/descriptor/descriptor_test.go
index e461f88..d01fc66 100644
--- a/server/descriptor/descriptor_test.go
+++ b/server/descriptor/descriptor_test.go
@@ -48,14 +48,14 @@ func TestUnmarshal(t *testing.T) {
func TestFindLog(t *testing.T) {
for _, table := range []struct {
- op Operator
+ ops []Operator
logId []byte
wantError bool
}{
- {makeOperatorList()[0], deb64("B9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPM="), false},
- {makeOperatorList()[0], []byte{0, 1, 2, 3}, true},
+ {makeOperatorList(), deb64("B9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPM="), false},
+ {makeOperatorList(), []byte{0, 1, 2, 3}, true},
} {
- _, err := table.op.FindLog(table.logId)
+ _, err := FindLog(table.ops, table.logId)
if (err != nil) != table.wantError {
t.Errorf("wanted log not found for id: %v", table.logId)
}