@@ -32,7 +32,6 @@ import (
3232
3333 "github.com/google/keytransparency/core/mutator/entry"
3434 ktpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
35- "fmt"
3635)
3736
3837var (
@@ -73,33 +72,15 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
7372
7473
7574 // TODO(ismail): pass in a (trillian) logverifier instead
76- // - create an equivalent map verifier (in trillian)
77- // between different error types (like below)
7875 // - create a set of fixed error messages so the caller can differentiate
79- if err := m .logVerifierCli .VerifyRoot (m .trusted , in .GetLogRoot (), in .GetLogInclusion ()); err != nil {
76+ // between different error types (like below)
77+ // - also, create an equivalent map verifier (in trillian)
78+ if err := m .logVerifier .VerifyRoot (m .trusted , in .GetLogRoot (), in .GetLogConsistency ()); err != nil {
79+ // this could be one of ErrInvalidLogSignature, ErrInvalidLogConsistencyProof
8080 errList = append (errList , err )
8181 }
82- logRoot := in .GetLogRoot ()
83- // Verify SignedLogRoot signature.
84- hash := tcrypto .HashLogRoot (* logRoot )
85- if err := tcrypto .Verify (m .logPubKey , hash , logRoot .GetSignature ()); err != nil {
86- glog .Infof ("couldn't verify signature on log root: %v: %v" , logRoot , err )
87- errList = append (errList , ErrInvalidLogSignature )
88- }
89-
90- if m .trusted != nil && m .trusted .GetTreeSize () > 0 {
91- // Verify consistency proof:
92- err := m .logVerifier .VerifyConsistencyProof (
93- m .trusted .TreeSize , logRoot .TreeSize ,
94- m .trusted .RootHash , logRoot .RootHash ,
95- in .GetLogConsistency ())
96- if err != nil {
97- errList = append (errList , ErrInvalidLogConsistencyProof )
98- }
99- } else {
100- // trust the first log root we see, don't verify anything yet
101- m .trusted = in .GetLogRoot ()
102- }
82+ // updated trusted log root
83+ m .trusted = in .GetLogRoot ()
10384
10485 b , err := json .Marshal (in .GetSmr ())
10586 if err != nil {
@@ -108,15 +89,9 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
10889 }
10990 leafIndex := in .GetSmr ().GetMapRevision ()
11091 treeSize := in .GetLogRoot ().GetTreeSize ()
111- leafHash := m .logHasher .HashLeaf (b )
112- err = m .logVerifier .VerifyInclusionProof (
113- leafIndex ,
114- treeSize ,
115- in .GetLogInclusion (),
116- in .GetLogRoot ().GetRootHash (),
117- leafHash )
92+ err = m .logVerifier .VerifyInclusionAtIndex (in .GetLogRoot (), b , leafIndex , in .GetLogInclusion ())
11893 if err != nil {
119- glog .Errorf ("m.logVerifier.VerifyInclusionProof ((%v, %v, _): %v" , leafIndex , treeSize , err )
94+ glog .Errorf ("m.logVerifier.VerifyInclusionAtIndex ((%v, %v, _): %v" , leafIndex , treeSize , err )
12095 errList = append (errList , ErrInvalidLogInclusion )
12196 }
12297
@@ -129,24 +104,20 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
129104 // reset to the state before it was signed:
130105 smr .Signature = nil
131106 // verify signature on map root:
132- fmt .Println ("tcrypto.VerifyObject:" )
133- fmt .Println (m .mapPubKey )
134- fmt .Println (smr )
135- fmt .Println (in .GetSmr ().GetSignature ())
136107 if err := tcrypto .VerifyObject (m .mapPubKey , smr , in .GetSmr ().GetSignature ()); err != nil {
137108 glog .Infof ("couldn't verify signature on map root: %v" , err )
138109 errList = append (errList , ErrInvalidMapSignature )
139110 }
140111
141112 //
142- // mutations verification:
113+ // mutations verification
143114 //
144115
145116 // we need the old root for verifying the inclusion of the old leafs in the
146117 // previous epoch. Storage always stores the mutations response independent
147118 // from if the checks succeeded or not.
148119 var oldRoot []byte
149- if m .store .LatestEpoch () > 0 {
120+ if m .store .LatestEpoch () > 1 {
150121 // retrieve the old root hash from storage!
151122 monRes , err := m .store .Get (in .Epoch - 1 )
152123 if err != nil {
@@ -158,7 +129,7 @@ func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error
158129 errList = append (errList , err ... )
159130 }
160131 } else {
161- // TODO oldRoot is the hash of the initial tree
132+ // TODO oldRoot is the hash of the initial empty sparse merkle tree
162133 }
163134
164135 return errList
0 commit comments