Skip to content

Commit 2d6da67

Browse files
committed
address comments
1 parent 80b9ff1 commit 2d6da67

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

cmd/aws/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func newAWSStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
170170
return nil, fmt.Errorf("failed to initialize AWS issuer storage: %v", err)
171171
}
172172

173-
return storage.NewCTStorage(appender, issuerStorage, reader)
173+
return storage.NewCTStorage(ctx, appender, issuerStorage, reader)
174174
}
175175

176176
type timestampFlag struct {

cmd/gcp/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func newGCPStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
184184
return nil, fmt.Errorf("failed to initialize GCP issuer storage: %v", err)
185185
}
186186

187-
return storage.NewCTStorage(appender, issuerStorage, reader)
187+
return storage.NewCTStorage(ctx, appender, issuerStorage, reader)
188188
}
189189

190190
type timestampFlag struct {

internal/ct/handlers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func newPOSIXStorageFunc(t *testing.T, root string) storage.CreateStorage {
185185
klog.Fatalf("failed to initialize InMemory issuer storage: %v", err)
186186
}
187187

188-
s, err := storage.NewCTStorage(appender, issuerStorage, reader)
188+
s, err := storage.NewCTStorage(t.Context(), appender, issuerStorage, reader)
189189
if err != nil {
190190
klog.Fatalf("Failed to initialize CTStorage: %v", err)
191191
}

internal/types/staticct/staticct.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ type Entry struct {
166166
LeafIndex uint64
167167
}
168168

169+
// UnmarshalText implements encoding/TextUnmarshaler and reads EntryBundles
170+
// which are encoded using the Static CT API spec.
171+
func UnmarshalTimestamp(raw []byte) (uint64, error) {
172+
s := cryptobyte.String(raw)
173+
var t uint64
174+
175+
if !s.ReadUint64(&t) || t > math.MaxInt64 {
176+
return 0, fmt.Errorf("invalid data tile: timestamp can't be extracted")
177+
}
178+
if t > math.MaxInt64 {
179+
return 0, fmt.Errorf("invalid data tile: timestamp %d > math.MaxInt64", t)
180+
}
181+
return t, nil
182+
}
183+
169184
// UnmarshalText implements encoding/TextUnmarshaler and reads EntryBundles
170185
// which are encoded using the Static CT API spec.
171186
func (t *Entry) UnmarshalText(raw []byte) error {

storage/storage.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ type CTStorage struct {
6060
storeData func(context.Context, *ctonly.Entry) tessera.IndexFuture
6161
storeIssuers func(context.Context, []KV) error
6262
reader tessera.LogReader
63+
awaiter *tessera.PublicationAwaiter
6364
}
6465

6566
// NewCTStorage instantiates a CTStorage object.
66-
func NewCTStorage(logStorage *tessera.Appender, issuerStorage IssuerStorage, reader tessera.LogReader) (*CTStorage, error) {
67+
func NewCTStorage(ctx context.Context, logStorage *tessera.Appender, issuerStorage IssuerStorage, reader tessera.LogReader) (*CTStorage, error) {
68+
awaiter := tessera.NewPublicationAwaiter(ctx, reader.ReadCheckpoint, 200*time.Millisecond)
6769
ctStorage := &CTStorage{
6870
storeData: tessera.NewCertificateTransparencyAppender(logStorage),
6971
storeIssuers: cachedStoreIssuers(issuerStorage),
7072
reader: reader,
73+
awaiter: awaiter,
7174
}
7275
return ctStorage, nil
7376
}
@@ -81,8 +84,7 @@ func (cts *CTStorage) dedupFuture(ctx context.Context, f tessera.IndexFuture) (i
8184
ctx, span := tracer.Start(ctx, "tesseract.storage.dedupFuture")
8285
defer span.End()
8386

84-
awaiter := tessera.NewPublicationAwaiter(ctx, cts.reader.ReadCheckpoint, 10*time.Millisecond)
85-
idx, cpRaw, err := awaiter.Await(ctx, f)
87+
idx, cpRaw, err := cts.awaiter.Await(ctx, f)
8688
if err != nil {
8789
return 0, 0, fmt.Errorf("error waiting for Tessera future and its integration: %v", err)
8890
}
@@ -112,14 +114,15 @@ func (cts *CTStorage) dedupFuture(ctx context.Context, f tessera.IndexFuture) (i
112114

113115
eIdx := idx.Index % layout.EntryBundleWidth
114116
if uint64(len(eb.Entries)) < eIdx {
115-
return 0, 0, fmt.Errorf("failed to read entry %d in entry bundle %d", eIdx, eBIdx)
117+
return 0, 0, fmt.Errorf("entry bundle at index %d has only %d entries, but wanted at least %d", eBIdx, eIdx, eBIdx)
116118
}
117119
e := staticct.Entry{}
118-
if err := e.UnmarshalText([]byte(eb.Entries[eIdx])); err != nil {
119-
return 0, 0, fmt.Errorf("failed to unmarshal entry %d in entry bundle %d: %v", eIdx, eBIdx, e)
120+
t, err := staticct.UnmarshalTimestamp([]byte(eb.Entries[eIdx]))
121+
if err != nil {
122+
return 0, 0, fmt.Errorf("failed to extract timestamp from entry %d in entry bundle %d: %v", eIdx, eBIdx, e)
120123
}
121124

122-
return idx.Index, e.Timestamp, nil
125+
return idx.Index, t, nil
123126
}
124127

125128
// Add stores CT entries.

0 commit comments

Comments
 (0)