aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/db/trillian.go2
-rw-r--r--pkg/db/trillian_test.go6
-rw-r--r--pkg/instance/handler_test.go6
-rw-r--r--pkg/instance/instance.go7
4 files changed, 11 insertions, 10 deletions
diff --git a/pkg/db/trillian.go b/pkg/db/trillian.go
index 25b2fb3..453a884 100644
--- a/pkg/db/trillian.go
+++ b/pkg/db/trillian.go
@@ -26,7 +26,7 @@ func (c *TrillianClient) AddLeaf(ctx context.Context, req *requests.Leaf) error
leaf := types.Leaf{
Statement: types.Statement{
ShardHint: req.ShardHint,
- Checksum: req.Checksum,
+ Checksum: *types.HashFn(req.Preimage[:]),
},
Signature: req.Signature,
KeyHash: *types.HashFn(req.VerificationKey[:]),
diff --git a/pkg/db/trillian_test.go b/pkg/db/trillian_test.go
index 955fc46..4dc561d 100644
--- a/pkg/db/trillian_test.go
+++ b/pkg/db/trillian_test.go
@@ -20,10 +20,8 @@ import (
func TestAddLeaf(t *testing.T) {
req := &requests.Leaf{
- Statement: types.Statement{
- ShardHint: 0,
- Checksum: types.Hash{},
- },
+ ShardHint: 0,
+ Preimage: types.Hash{},
Signature: types.Signature{},
VerificationKey: types.PublicKey{},
DomainHint: "example.com",
diff --git a/pkg/instance/handler_test.go b/pkg/instance/handler_test.go
index f8817dc..8a48860 100644
--- a/pkg/instance/handler_test.go
+++ b/pkg/instance/handler_test.go
@@ -658,7 +658,7 @@ func mustHandle(t *testing.T, i Instance, e types.Endpoint) Handler {
return Handler{}
}
-func mustLeafBuffer(t *testing.T, shardHint uint64, checksum types.Hash, wantSig bool) io.Reader {
+func mustLeafBuffer(t *testing.T, shardHint uint64, preimage types.Hash, wantSig bool) io.Reader {
t.Helper()
vk, sk, err := ed25519.GenerateKey(rand.Reader)
@@ -667,7 +667,7 @@ func mustLeafBuffer(t *testing.T, shardHint uint64, checksum types.Hash, wantSig
}
msg := types.Statement{
ShardHint: shardHint,
- Checksum: checksum,
+ Checksum: *types.HashFn(preimage[:]),
}
sig := ed25519.Sign(sk, msg.ToBinary())
if !wantSig {
@@ -676,7 +676,7 @@ func mustLeafBuffer(t *testing.T, shardHint uint64, checksum types.Hash, wantSig
return bytes.NewBufferString(fmt.Sprintf(
"%s=%d\n"+"%s=%x\n"+"%s=%x\n"+"%s=%x\n"+"%s=%s\n",
"shard_hint", shardHint,
- "checksum", checksum[:],
+ "preimage", preimage[:],
"signature", sig,
"verification_key", vk,
"domain_hint", "example.com",
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index bbd6cde..7ade955 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -56,8 +56,11 @@ func (i *Instance) leafRequestFromHTTP(ctx context.Context, r *http.Request) (*r
if err := req.FromASCII(r.Body); err != nil {
return nil, fmt.Errorf("FromASCII: %v", err)
}
-
- if !req.Statement.Verify(&req.VerificationKey, &req.Signature) {
+ stmt := types.Statement{
+ ShardHint: req.ShardHint,
+ Checksum: *types.HashFn(req.Preimage[:]),
+ }
+ if !stmt.Verify(&req.VerificationKey, &req.Signature) {
return nil, fmt.Errorf("invalid signature")
}
shardEnd := uint64(time.Now().Unix())