Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 14151ff

Browse files
authored
Use the Trillian testing environment (#727)
* Use Trillian MapEnv for integration tests * Use Trillian Verifier * Use maphasher in verifier * Compute leafHash before passing to inclusion proof verification * use real public key from tree * Adjust tests for off-by-one TreeRevision starts at 1 now * Fixups
1 parent f839b54 commit 14151ff

File tree

20 files changed

+98
-2701
lines changed

20 files changed

+98
-2701
lines changed

cmd/keytransparency-client/grpcc/grpc_client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ import (
3131
"github.com/google/keytransparency/core/crypto/vrf"
3232
"github.com/google/keytransparency/core/mutator"
3333
"github.com/google/keytransparency/core/mutator/entry"
34-
"github.com/google/keytransparency/core/tree/sparse"
35-
tv "github.com/google/keytransparency/core/tree/sparse/verifier"
3634

3735
"github.com/golang/protobuf/proto"
3836
"github.com/google/trillian/client"
37+
"github.com/google/trillian/merkle/maphasher"
3938
"golang.org/x/net/context"
4039
"google.golang.org/grpc"
4140

@@ -99,7 +98,7 @@ func New(
9998
return &Client{
10099
cli: client,
101100
vrf: vrf,
102-
kt: kt.New(vrf, tv.New(sparse.CONIKSHasher), verifier, log),
101+
kt: kt.New(vrf, maphasher.Default, verifier, log),
103102
log: log,
104103
mutator: entry.New(),
105104
RetryCount: 1,

cmd/keytransparency-server/main.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"database/sql"
1919
"flag"
20-
"fmt"
2120
"io/ioutil"
2221
"log"
2322
"net/http"
@@ -27,11 +26,9 @@ import (
2726
"github.com/google/keytransparency/core/crypto/vrf"
2827
"github.com/google/keytransparency/core/crypto/vrf/p256"
2928
"github.com/google/keytransparency/core/keyserver"
30-
"github.com/google/keytransparency/core/mapserver"
3129
"github.com/google/keytransparency/core/mutator/entry"
3230

3331
cmutation "github.com/google/keytransparency/core/mutation"
34-
ctxn "github.com/google/keytransparency/core/transaction"
3532
"github.com/google/keytransparency/impl/authorization"
3633
gauth "github.com/google/keytransparency/impl/google/authentication"
3734
"github.com/google/keytransparency/impl/mutation"
@@ -40,8 +37,6 @@ import (
4037
"github.com/google/keytransparency/impl/sql/commitments"
4138
"github.com/google/keytransparency/impl/sql/engine"
4239
"github.com/google/keytransparency/impl/sql/mutations"
43-
"github.com/google/keytransparency/impl/sql/sequenced"
44-
"github.com/google/keytransparency/impl/sql/sqlhist"
4540
"github.com/google/keytransparency/impl/transaction"
4641
"github.com/google/trillian"
4742

@@ -131,18 +126,6 @@ func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Ha
131126
})
132127
}
133128

134-
func newReadonlyMapServer(ctx context.Context, mapID int64, sqldb *sql.DB, factory ctxn.Factory) (trillian.TrillianMapClient, error) {
135-
tree, err := sqlhist.New(ctx, mapID, factory)
136-
if err != nil {
137-
return nil, fmt.Errorf("Failed to create SQL history: %v", err)
138-
}
139-
sths, err := sequenced.New(sqldb, mapID)
140-
if err != nil {
141-
return nil, fmt.Errorf("sequenced.New(%v): %v", mapID, err)
142-
}
143-
return mapserver.NewReadonly(mapID, tree, factory, sths), nil
144-
}
145-
146129
func main() {
147130
flag.Parse()
148131

@@ -192,22 +175,12 @@ func main() {
192175
tlog := trillian.NewTrillianLogClient(tconn)
193176

194177
// Connect to map server.
195-
var tmap trillian.TrillianMapClient
196-
var tadmin trillian.TrillianAdminClient
197-
if *mapURL != "" {
198-
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure())
199-
if err != nil {
200-
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err)
201-
}
202-
tmap = trillian.NewTrillianMapClient(mconn)
203-
tadmin = trillian.NewTrillianAdminClient(mconn)
204-
} else {
205-
// Create an in-process readonly mapserver.
206-
tmap, err = newReadonlyMapServer(context.Background(), *mapID, sqldb, factory)
207-
if err != nil {
208-
glog.Exitf("newReadonlyMapServer(): %v", err)
209-
}
178+
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure())
179+
if err != nil {
180+
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err)
210181
}
182+
tmap := trillian.NewTrillianMapClient(mconn)
183+
tadmin := trillian.NewTrillianAdminClient(mconn)
211184

212185
// Create gRPC server.
213186
svr := keyserver.New(*logID, tlog, *mapID, tmap, tadmin, commitments,

cmd/keytransparency-signer/main.go

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,21 @@ package main
1717
import (
1818
"database/sql"
1919
"flag"
20-
"fmt"
2120
"net/http"
2221
"time"
2322

2423
"github.com/google/keytransparency/core/admin"
2524
"github.com/google/keytransparency/core/appender"
26-
"github.com/google/keytransparency/core/mapserver"
2725
"github.com/google/keytransparency/core/mutator/entry"
2826
"github.com/google/keytransparency/core/signer"
29-
ctxn "github.com/google/keytransparency/core/transaction"
3027
"github.com/google/keytransparency/impl/config"
3128
"github.com/google/keytransparency/impl/sql/engine"
3229
"github.com/google/keytransparency/impl/sql/mutations"
33-
"github.com/google/keytransparency/impl/sql/sequenced"
34-
"github.com/google/keytransparency/impl/sql/sqlhist"
3530
"github.com/google/keytransparency/impl/transaction"
3631

3732
"github.com/golang/glog"
3833
"github.com/google/trillian"
39-
"github.com/google/trillian/crypto/keys"
4034
_ "github.com/google/trillian/merkle/objhasher" // Register objhasher
41-
"github.com/google/trillian/util"
4235
"github.com/prometheus/client_golang/prometheus"
4336
"golang.org/x/net/context"
4437
"google.golang.org/grpc"
@@ -76,25 +69,6 @@ func openDB() *sql.DB {
7669
return db
7770
}
7871

79-
func newMapServer(ctx context.Context, sqldb *sql.DB, factory ctxn.Factory) (trillian.TrillianMapClient, error) {
80-
tree, err := sqlhist.New(ctx, *mapID, factory)
81-
if err != nil {
82-
return nil, fmt.Errorf("sqlhist.New(): %v", err)
83-
}
84-
85-
sths, err := sequenced.New(sqldb, *mapID)
86-
if err != nil {
87-
return nil, err
88-
}
89-
signer, err := keys.NewFromPrivatePEMFile(*signingKey, *signingKeyPassword)
90-
if err != nil {
91-
return nil, err
92-
}
93-
94-
return mapserver.New(*mapID, tree, factory, sths, signer,
95-
util.SystemTimeSource{}), nil
96-
}
97-
9872
func main() {
9973
flag.Parse()
10074

@@ -108,20 +82,11 @@ func main() {
10882
factory := transaction.NewFactory(sqldb)
10983

11084
// Connect to map server.
111-
var tmap trillian.TrillianMapClient
112-
if *mapURL != "" {
113-
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure())
114-
if err != nil {
115-
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err)
116-
}
117-
tmap = trillian.NewTrillianMapClient(mconn)
118-
} else {
119-
var err error
120-
tmap, err = newMapServer(context.Background(), sqldb, factory)
121-
if err != nil {
122-
glog.Exitf("newMapServer: %v", err)
123-
}
85+
mconn, err := grpc.Dial(*mapURL, grpc.WithInsecure())
86+
if err != nil {
87+
glog.Exitf("grpc.Dial(%v): %v", *mapURL, err)
12488
}
89+
tmap := trillian.NewTrillianMapClient(mconn)
12590

12691
// Connection to append only log
12792
tlog, err := config.LogClient(*logID, *logURL, *logPubKey)

core/client/kt/verify.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424

2525
"github.com/google/keytransparency/core/crypto/commitments"
2626
"github.com/google/keytransparency/core/crypto/vrf"
27-
"github.com/google/keytransparency/core/tree/sparse"
2827

2928
"github.com/golang/protobuf/proto"
3029
"github.com/google/trillian"
3130
"github.com/google/trillian/client"
31+
"github.com/google/trillian/merkle"
32+
"github.com/google/trillian/merkle/hashers"
3233
"golang.org/x/net/context"
3334

34-
tv "github.com/google/keytransparency/core/tree/sparse/verifier"
3535
tcrypto "github.com/google/trillian/crypto"
3636

3737
tpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
@@ -47,22 +47,22 @@ var (
4747

4848
// Verifier is a client helper library for verifying request and responses.
4949
type Verifier struct {
50-
vrf vrf.PublicKey
51-
tree *tv.Verifier
52-
sig crypto.PublicKey
53-
log client.LogVerifier
50+
vrf vrf.PublicKey
51+
hasher hashers.MapHasher
52+
sig crypto.PublicKey
53+
log client.LogVerifier
5454
}
5555

5656
// New creates a new instance of the client verifier.
5757
func New(vrf vrf.PublicKey,
58-
tree *tv.Verifier,
58+
hasher hashers.MapHasher,
5959
sig crypto.PublicKey,
6060
log client.LogVerifier) *Verifier {
6161
return &Verifier{
62-
vrf: vrf,
63-
tree: tree,
64-
sig: sig,
65-
log: log,
62+
vrf: vrf,
63+
hasher: hasher,
64+
sig: sig,
65+
log: log,
6666
}
6767
}
6868

@@ -107,10 +107,14 @@ func (v *Verifier) VerifyGetEntryResponse(ctx context.Context, userID, appID str
107107
return ErrNilProof
108108
}
109109

110+
leaf := leafProof.GetLeaf().GetLeafValue()
111+
proof := leafProof.GetInclusion()
112+
expectedRoot := in.GetSmr().GetRootHash()
110113
mapID := in.GetSmr().GetMapId()
111-
if err := v.tree.VerifyProof(mapID, leafProof.Inclusion, index[:], leafProof.Leaf.LeafValue, sparse.FromBytes(in.GetSmr().RootHash)); err != nil {
114+
leafHash := v.hasher.HashLeaf(mapID, index[:], leaf)
115+
if err := merkle.VerifyMapInclusionProof(mapID, index[:], leafHash, expectedRoot, proof, v.hasher); err != nil {
112116
Vlog.Printf("✗ Sparse tree proof verification failed.")
113-
return fmt.Errorf("tree.VerifyProof(): %v", err)
117+
return fmt.Errorf("VerifyMapInclusionProof(): %v", err)
114118
}
115119
Vlog.Printf("✓ Sparse tree proof verified.")
116120

0 commit comments

Comments
 (0)