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

Commit a0c9404

Browse files
committed
Minor cleanup
1 parent 4c8831b commit a0c9404

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

core/monitor/monitor.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
package monitor
17+
18+
type Monitor struct {
19+
20+
}

core/monitor/verify.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
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.
1918
package monitor
2019

2120
import (
@@ -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

4040
var (
@@ -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

impl/monitor/monitor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func (s *Server) pollMutations(ctx context.Context, opts ...grpc.CallOption) ([]
146146
}
147147
respSmr := resp.GetSmr()
148148
var monitorResp *mopb.GetMonitoringResponse
149+
150+
// TODO(Ismail): let the verification method in core directly return the response
149151
switch err := cmon.VerifyResponse(s.logPubKey, s.mapPubKey, resp, mutations); err {
150152
// TODO(ismail): return proper data for failure cases:
151153
case cmon.ErrInvalidMutation:

0 commit comments

Comments
 (0)