Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/keytransparency-client/cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ func (m mapHeads) Less(i, j int) bool { return m[i].MapRevision < m[j].MapRevisi
func init() {
RootCmd.AddCommand(histCmd)

histCmd.PersistentFlags().Int64Var(&start, "start", 0, "Start epoch")
histCmd.PersistentFlags().Int64Var(&start, "start", 1, "Start epoch")
histCmd.PersistentFlags().Int64Var(&end, "end", 0, "End epoch")
}
16 changes: 11 additions & 5 deletions cmd/keytransparency-client/grpcc/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ func min(x, y int32) int32 {

// ListHistory returns a list of profiles starting and ending at given epochs.
// It also filters out all identical consecutive profiles.
// Epochs start at 1.
func (c *Client) ListHistory(ctx context.Context, userID, appID string, start, end int64, opts ...grpc.CallOption) (map[*trillian.SignedMapRoot][]byte, error) {
if start <= 0 {
return nil, fmt.Errorf("start=%v, want > 0", start)
if start < 0 {
return nil, fmt.Errorf("start=%v, want >= 0", start)
}
var currentProfile []byte
profiles := make(map[*trillian.SignedMapRoot][]byte)
for start <= end {
epochsReceived := int64(0)
epochsWant := end - start + 1
for epochsReceived < epochsWant {
resp, err := c.cli.ListEntryHistory(ctx, &tpb.ListEntryHistoryRequest{
UserId: userID,
AppId: appID,
Expand All @@ -187,6 +188,7 @@ func (c *Client) ListHistory(ctx context.Context, userID, appID string, start, e
if err != nil {
return nil, err
}
epochsReceived += int64(len(resp.GetValues()))

for i, v := range resp.GetValues() {
Vlog.Printf("Processing entry for %v, epoch %v", userID, start+int64(i))
Expand All @@ -207,11 +209,15 @@ func (c *Client) ListHistory(ctx context.Context, userID, appID string, start, e
currentProfile = profile
}
if resp.NextStart == 0 {
return nil, ErrIncomplete // No more data.
break // No more data.
}
start = resp.NextStart // Fetch the next block of results.
}

if epochsReceived < epochsWant {
return nil, ErrIncomplete
}

return profiles, nil
}

Expand Down
11 changes: 9 additions & 2 deletions core/fake/trillian_log_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import (
"google.golang.org/grpc"
)

type logServer struct{}
type logServer struct {
treeSize int64
}

// NewFakeTrillianLogClient returns a fake trillian log client.
func NewFakeTrillianLogClient() trillian.TrillianLogClient {
return &logServer{}
}

func (l *logServer) QueueLeaf(ctx context.Context, in *trillian.QueueLeafRequest, opts ...grpc.CallOption) (*trillian.QueueLeafResponse, error) {
l.treeSize++
return nil, nil
}

Expand All @@ -48,7 +51,11 @@ func (l *logServer) GetConsistencyProof(ctx context.Context, in *trillian.GetCon
}

func (l *logServer) GetLatestSignedLogRoot(ctx context.Context, in *trillian.GetLatestSignedLogRootRequest, opts ...grpc.CallOption) (*trillian.GetLatestSignedLogRootResponse, error) {
return &trillian.GetLatestSignedLogRootResponse{}, nil
return &trillian.GetLatestSignedLogRootResponse{
SignedLogRoot: &trillian.SignedLogRoot{
TreeSize: l.treeSize,
},
}, nil
}

func (l *logServer) GetSequencedLeafCount(ctx context.Context, in *trillian.GetSequencedLeafCountRequest, opts ...grpc.CallOption) (*trillian.GetSequencedLeafCountResponse, error) {
Expand Down
6 changes: 4 additions & 2 deletions core/keyserver/keyserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const (
defaultPageSize = 16
// Maximum allowed requested page size to prevent DOS.
maxPageSize = 16
// If no epoch is provided default to epoch 1.
defaultStartEpoch = 1
)

// Server holds internal state for the key server.
Expand Down Expand Up @@ -101,6 +99,10 @@ func (s *Server) GetEntry(ctx context.Context, in *tpb.GetEntryRequest) (*tpb.Ge

func (s *Server) getEntry(ctx context.Context, userID, appID string, firstTreeSize, epoch int64) (*tpb.GetEntryResponse, error) {
index, proof := s.vrf.Evaluate(vrf.UniqueID(userID, appID))
if epoch == 0 {
return nil, grpc.Errorf(codes.InvalidArgument,
"Epoch 0 is inavlid. The first map revision is epoch 1.")
}

getResp, err := s.tmap.GetLeaves(ctx, &trillian.GetMapLeavesRequest{
MapId: s.mapID,
Expand Down
6 changes: 0 additions & 6 deletions core/keyserver/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ func validateListEntryHistoryRequest(in *tpb.ListEntryHistoryRequest, currentEpo
if in.Start < 0 || in.Start > currentEpoch {
return ErrInvalidStart
}
// TODO(ismail): make epochs consistently start from 0 and provide a function
// such that callers don't need convert between starting 0 and 1.
// Ensure a valid start epoch is provided if the Start parameter is not set.
if in.Start == 0 {
in.Start = defaultStartEpoch
}

switch {
case in.PageSize < 0:
Expand Down
1 change: 1 addition & 0 deletions core/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (s *Signer) Initialize(ctx context.Context) error {
// add the empty map root to the log.
if logRoot.GetSignedLogRoot().GetTreeSize() == 0 &&
mapRoot.GetMapRoot().GetMapRevision() == 0 {
glog.Infof("Initializing Trillian Log with empty map root")
if err := queueLogLeaf(ctx, s.tlog, s.logID, mapRoot.GetMapRoot()); err != nil {
return err
}
Expand Down
26 changes: 15 additions & 11 deletions integration/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ func NewEnv(t *testing.T) *Env {
t.Fatalf("CreateTree(): %v", err)
}
mapID := tree.TreeId
if _, err := mapEnv.MapClient.SetLeaves(ctx, &trillian.SetMapLeavesRequest{
MapId: mapID,
Leaves: nil,
MapperData: &trillian.MapperMetadata{
HighestFullyCompletedSeq: 0,
},
}); err != nil {
t.Fatalf("SetLeaves(): %v", err)
}

mapPubKey, err := der.UnmarshalPublicKey(tree.GetPublicKey().GetDer())
if err != nil {
Expand Down Expand Up @@ -186,10 +177,23 @@ func NewEnv(t *testing.T) *Env {
if err != nil {
t.Fatalf("Dial(%v) = %v", addr, err)
}
client := grpcc.New(cc, vrfPub, mapPubKey, coniks.Default,
fake.NewFakeTrillianLogVerifier())
client := grpcc.New(cc, vrfPub, mapPubKey, coniks.Default, fake.NewFakeTrillianLogVerifier())
client.RetryCount = 0

// Mimic first sequence event
if err := signer.Initialize(ctx); err != nil {
t.Fatalf("signer.Initialize() = %v", err)
}
if _, err := mapEnv.MapClient.SetLeaves(ctx, &trillian.SetMapLeavesRequest{
MapId: mapID,
Leaves: nil,
MapperData: &trillian.MapperMetadata{
HighestFullyCompletedSeq: 0,
},
}); err != nil {
t.Fatalf("SetLeaves(): %v", err)
}

return &Env{
mapEnv: mapEnv,
GRPCServer: s,
Expand Down