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

Commit a7f163d

Browse files
committed
Use trillian logverifier instead
1 parent 588c0c0 commit a7f163d

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

cmd/keytransparency-monitor/main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import (
4242
spb "github.com/google/keytransparency/impl/proto/keytransparency_v1_service"
4343
mopb "github.com/google/keytransparency/impl/proto/monitor_v1_service"
4444
mupb "github.com/google/keytransparency/impl/proto/mutation_v1_service"
45-
_ "github.com/google/trillian/merkle/coniks" // Register coniks
45+
tlogcli "github.com/google/trillian/client"
46+
"github.com/google/trillian/crypto/keys/der"
47+
_ "github.com/google/trillian/merkle/coniks" // Register coniks
48+
"github.com/google/trillian/merkle/hashers"
4649
_ "github.com/google/trillian/merkle/objhasher" // Register objhasher
4750
)
4851

@@ -141,13 +144,22 @@ func main() {
141144
// Insert handlers for other http paths here.
142145
mux := http.NewServeMux()
143146
mux.Handle("/", gwmux)
147+
logHasher, err := hashers.NewLogHasher(logTree.GetHashStrategy())
148+
if err != nil {
149+
glog.Fatalf("Could not initialize log hasher: %v", err)
150+
}
151+
logPubKey, err := der.UnmarshalPublicKey(logTree.GetPublicKey().GetDer())
152+
if err != nil {
153+
glog.Fatalf("Failed parsing Log public key: %v", err)
154+
}
155+
logVerifier := tlogcli.NewLogVerifier(logHasher, logPubKey)
144156

145-
// initialize the mutations API client and feed the responses it got
146-
// into the monitor:
147-
mon, err := cmon.New(logTree, mapTree, crypto.NewSHA256Signer(key), store)
157+
mon, err := cmon.New(logVerifier, mapTree, crypto.NewSHA256Signer(key), store)
148158
if err != nil {
149159
glog.Exitf("Failed to initialize monitor: %v", err)
150160
}
161+
// initialize the mutations API client and feed the responses it got
162+
// into the monitor:
151163
mutCli := client.New(mcc, *pollPeriod)
152164
responses, errs := mutCli.StartPolling(1)
153165
go func() {

core/client/kt/verify.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ func (v *Verifier) VerifyGetEntryResponse(ctx context.Context, userID, appID str
120120
// by removing the signature from the object.
121121
smr := *in.GetSmr()
122122
smr.Signature = nil // Remove the signature from the object to be verified.
123-
fmt.Println("CLIENT tcrypto.VerifyObject:")
124-
fmt.Println(v.mapPubKey)
125-
fmt.Println(smr)
126-
fmt.Println(in.GetSmr().GetSignature())
127123
if err := tcrypto.VerifyObject(v.mapPubKey, smr, in.GetSmr().GetSignature()); err != nil {
128124
Vlog.Printf("✗ Signed Map Head signature verification failed.")
129125
return fmt.Errorf("sig.Verify(SMR): %v", err)

core/monitor/monitor.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ import (
2727
"github.com/google/trillian"
2828
"github.com/google/trillian/client"
2929
tcrypto "github.com/google/trillian/crypto"
30-
"github.com/google/trillian/merkle"
31-
"github.com/google/trillian/merkle/hashers"
3230
"github.com/google/trillian/crypto/keys/der"
31+
"github.com/google/trillian/merkle/hashers"
3332
)
3433

3534
// Monitor holds the internal state for a monitor accessing the mutations API
3635
// and for verifying its responses.
3736
type Monitor struct {
3837
mapID int64
39-
logHasher hashers.LogHasher
4038
mapHasher hashers.MapHasher
41-
logPubKey crypto.PublicKey
4239
mapPubKey crypto.PublicKey
4340
logVerifier client.LogVerifier
4441
signer *tcrypto.Signer
@@ -52,7 +49,7 @@ func New(logverifierCli client.LogVerifier, mapTree *trillian.Tree, signer *tcry
5249
if err != nil {
5350
return nil, fmt.Errorf("Failed creating MapHasher: %v", err)
5451
}
55-
mapPubKey, err := der.UnmarshalPublicKey(mapTree.GetPublicKey().GetDer())
52+
mapPubKey, err := der.UnmarshalPublicKey(mapTree.GetPublicKey().GetDer())
5653
if err != nil {
5754
return nil, fmt.Errorf("Could not unmarshal map public key: %v", err)
5855
}

core/monitor/verify.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
7070
m.trusted = in.GetLogRoot()
7171
}
7272

73-
74-
// TODO(ismail): pass in a (trillian) logverifier instead
75-
// - create a set of fixed error messages so the caller can differentiate
76-
// between different error types (like below)
77-
// - also, create an equivalent map verifier (in trillian)
7873
if err := m.logVerifier.VerifyRoot(m.trusted, in.GetLogRoot(), in.GetLogConsistency()); err != nil {
7974
// this could be one of ErrInvalidLogSignature, ErrInvalidLogConsistencyProof
8075
errList = append(errList, err)
@@ -85,7 +80,7 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
8580
b, err := json.Marshal(in.GetSmr())
8681
if err != nil {
8782
glog.Errorf("json.Marshal(): %v", err)
88-
// Encoding error
83+
errList = append(errList, ErrInvalidMapSignature)
8984
}
9085
leafIndex := in.GetSmr().GetMapRevision()
9186
treeSize := in.GetLogRoot().GetTreeSize()
@@ -95,9 +90,7 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
9590
errList = append(errList, ErrInvalidLogInclusion)
9691
}
9792

98-
//
9993
// map verification
100-
//
10194

10295
// copy of singed map root
10396
smr := *in.GetSmr()
@@ -109,9 +102,7 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
109102
errList = append(errList, ErrInvalidMapSignature)
110103
}
111104

112-
//
113105
// mutations verification
114-
//
115106

116107
// we need the old root for verifying the inclusion of the old leafs in the
117108
// previous epoch. Storage always stores the mutations response independent
@@ -128,9 +119,7 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
128119
in.GetSmr().GetRootHash(), in.GetSmr().GetMapId()); len(err) > 0 {
129120
errList = append(errList, err...)
130121
}
131-
} else {
132-
// TODO oldRoot is the hash of the initial empty sparse merkle tree
133-
}
122+
} // TODO else oldRoot is the hash of the initial empty sparse merkle tree
134123

135124
return errList
136125
}

integration/monitor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121

2222
"github.com/google/keytransparency/core/monitor"
2323
"github.com/google/keytransparency/core/monitor/storage"
24-
"github.com/google/keytransparency/impl/monitor/client"
2524
kpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
25+
"github.com/google/keytransparency/impl/monitor/client"
2626
spb "github.com/google/keytransparency/impl/proto/keytransparency_v1_service"
2727
mupb "github.com/google/keytransparency/impl/proto/mutation_v1_service"
2828
"github.com/google/trillian/crypto"
@@ -54,14 +54,14 @@ func TestMonitorEmptyStart(t *testing.T) {
5454
if err != nil {
5555
t.Fatalf("Couldn't retrieve domain info: %v", err)
5656
}
57-
signer, err := pem.UnmarshalPrivateKey(monitorPrivKey, "")
57+
signer, err := pem.UnmarshalPrivateKey(monitorPrivKey, "")
5858
if err != nil {
5959
t.Fatalf("Couldn't create signer: %v", err)
6060
}
61-
logTree := resp.Log
61+
//logTree := resp.Log
6262
mapTree := resp.Map
6363
store := storage.New()
64-
mon, err := monitor.New(fake.NewFakeTrillianLogVerifier(), logTree, mapTree, crypto.NewSHA256Signer(signer), store)
64+
mon, err := monitor.New(fake.NewFakeTrillianLogVerifier(), mapTree, crypto.NewSHA256Signer(signer), store)
6565
if err != nil {
6666
t.Fatalf("Couldn't create monitor: %v", err)
6767
}

integration/testutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ import (
4343

4444
_ "github.com/mattn/go-sqlite3" // Use sqlite database for testing.
4545

46+
cmutation "github.com/google/keytransparency/core/mutation"
47+
"github.com/google/keytransparency/impl/mutation"
4648
pb "github.com/google/keytransparency/impl/proto/keytransparency_v1_service"
4749
mpb "github.com/google/keytransparency/impl/proto/mutation_v1_service"
48-
cmutation "github.com/google/keytransparency/core/mutation"
4950
stestonly "github.com/google/trillian/storage/testonly"
50-
"github.com/google/keytransparency/impl/mutation"
5151
)
5252

5353
// NewDB creates a new in-memory database for testing.

0 commit comments

Comments
 (0)