1414
1515// Package monitor implements the monitor service. A monitor repeatedly polls a
1616// key-transparency server's Mutations API and signs Map Roots if it could
17- // reconstruct
18- // clients can query.
17+ // reconstruct clients can query.
1918package monitor
2019
2120import (
@@ -35,6 +34,7 @@ import (
3534
3635 "github.com/google/keytransparency/core/mutator/entry"
3736 ktpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
37+ mopb "github.com/google/keytransparency/core/proto/monitor_v1_types"
3838)
3939
4040var (
@@ -56,16 +56,21 @@ var (
5656// Additionally to the response it takes a complete list of mutations. The list
5757// of received mutations may differ from those included in the initial response
5858// because of the max. page size.
59- func VerifyResponse (logPubKey , mapPubKey crypto.PublicKey , resp * ktpb.GetMutationsResponse , allMuts []* ktpb.Mutation ) error {
59+ func VerifyResponse (logPubKey , mapPubKey crypto.PublicKey , getMutResp * ktpb.GetMutationsResponse , allMuts []* ktpb.Mutation ) * mopb.GetMonitoringResponse {
60+ resp := new (mopb.GetMonitoringResponse )
61+ resp .Smr = * getMutResp .Smr
62+ // reset map
63+ resp .Smr .Signature = nil
64+ sig := getMutResp .GetSmr ().GetSignature ()
6065 // verify signature on map root:
61- if err := tcrypto .VerifyObject (mapPubKey , resp .GetSmr (), resp . GetSmr (). GetSignature () ); err != nil {
66+ if err := tcrypto .VerifyObject (mapPubKey , resp .Smr , sig ); err != nil {
6267 glog .Errorf ("couldn't verify signature on map root: %v" , err )
6368 return ErrInvalidMapSignature
6469 }
6570
6671 // verify signature on log-root:
67- hash := tcrypto .HashLogRoot (* resp .GetLogRoot ())
68- if err := tcrypto .Verify (logPubKey , hash , resp .GetLogRoot ().GetSignature ()); err != nil {
72+ hash := tcrypto .HashLogRoot (* getMutResp .GetLogRoot ())
73+ if err := tcrypto .Verify (logPubKey , hash , getMutResp .GetLogRoot ().GetSignature ()); err != nil {
6974 return ErrInvalidLogSignature
7075 }
7176 //hasher, err := hashers.NewLogHasher(trillian.HashStrategy_OBJECT_RFC6962_SHA256)
@@ -77,7 +82,7 @@ func VerifyResponse(logPubKey, mapPubKey crypto.PublicKey, resp *ktpb.GetMutatio
7782 // logVerifier.VerifyInclusionProof()
7883
7984 // mapID := resp.GetSmr().GetMapId()
80- if err := verifyMutations (allMuts , resp .GetSmr ().GetRootHash (), resp .GetSmr ().GetMapId ()); err != nil {
85+ if err := verifyMutations (allMuts , getMutResp .GetSmr ().GetRootHash (), getMutResp .GetSmr ().GetMapId ()); err != nil {
8186 return err
8287 }
8388
@@ -102,21 +107,21 @@ func verifyMutations(muts []*ktpb.Mutation, expectedRoot []byte, mapID int64) er
102107 if err != nil {
103108 return ErrInvalidMutation
104109 }
110+
111+ // compute the new leaf
105112 newLeaf , err := mutator .Mutate (leafVal , m .GetUpdate ())
106113 if err != nil {
107114 // TODO(ismail): collect all data to reproduce this (expectedRoot, oldLeaf, and mutation)
108115 return ErrInvalidMutation
109116 }
110-
111117 index := m .GetProof ().GetLeaf ().GetIndex ()
112-
113118 newLeafnID := storage .NewNodeIDFromPrefixSuffix (index , storage.Suffix {}, hasher .BitLen ())
114- newLeafH := hasher .HashLeaf (mapID , index , newLeaf )
119+ newLeafHash := hasher .HashLeaf (mapID , index , newLeaf )
115120 newLeaves = append (newLeaves , merkle.HStar2LeafHash {
116121 Index : newLeafnID .BigInt (),
117- LeafHash : newLeafH ,
122+ LeafHash : newLeafHash ,
118123 })
119-
124+ // store the proof hashes locally to recompute the tree below:
120125 sibIDs := newLeafnID .Siblings ()
121126 for level , proof := range m .GetProof ().GetInclusion () {
122127 pID := sibIDs [level ]
@@ -131,8 +136,7 @@ func verifyMutations(muts []*ktpb.Mutation, expectedRoot []byte, mapID int64) er
131136 }
132137 }
133138 }
134- // TODO write get function that returns old proof nodes by index and level
135- // compute the new leaf and store the intermediate hashes locally.
139+
136140 // compute the new root using local intermediate hashes from epoch e.
137141 // verify rootHash
138142
0 commit comments