Skip to content

Commit

Permalink
SCTFE
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Sep 3, 2024
1 parent 18e3f3d commit bd0e1c3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions ct_only.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

// Storage described the expected functions from Tessera storage implementations.
type Storage interface {
// Add should duably assign an index to the provided Entry, and return it.
// Add should duably assign an index to the provided Entry, returning a future to access that value.
//
// Implementations MUST call MarshalBundleData method on the entry before persisting/integrating it.
Add(context.Context, *Entry) (uint64, error)
Add(context.Context, *Entry) IndexFuture
}

// NewCertificateTransparencySequencedWriter returns a function which knows how to add a CT-specific entry type to the log.
Expand All @@ -38,8 +38,8 @@ type Storage interface {
// b) is not compatible with the https://c2sp.org/tlog-tiles API which we _very strongly_ encourage you to use instead.
//
// Returns the assigned index in the log, or an error.
func NewCertificateTransparencySequencedWriter(s Storage) func(context.Context, *ctonly.Entry) (uint64, error) {
return func(ctx context.Context, e *ctonly.Entry) (uint64, error) {
func NewCertificateTransparencySequencedWriter(s Storage) func(context.Context, *ctonly.Entry) IndexFuture {
return func(ctx context.Context, e *ctonly.Entry) IndexFuture {
return s.Add(ctx, convertCTEntry(e))
}
}
Expand Down
2 changes: 1 addition & 1 deletion personalities/sctfe/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
}

klog.V(2).Infof("%s: %s => storage.Add", li.LogOrigin, method)
idx, err := li.storage.Add(ctx, entry)
idx, err := li.storage.Add(ctx, entry)()
if err != nil {
if errors.Is(err, tessera.ErrPushback) {
w.Header().Add("Retry-After", "1")
Expand Down
6 changes: 3 additions & 3 deletions personalities/sctfe/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestAddChainWhitespace(t *testing.T) {
t.Run(test.descr, func(t *testing.T) {
if test.want == http.StatusOK {
info.storage.EXPECT().AddIssuerChain(deadlineMatcher(), cmpMatcher{leafChain[1:]}).Return(nil)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(rsp, nil)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(func() (uint64, error) { return rsp, nil })
}

recorder := httptest.NewRecorder()
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestAddChain(t *testing.T) {
req, leafChain := parseChain(t, false, test.chain, info.roots.RawCertificates()[0])
rsp := uint64(0)
info.storage.EXPECT().AddIssuerChain(deadlineMatcher(), cmpMatcher{leafChain[1:]}).Return(nil)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(rsp, test.err)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(func() (uint64, error) { return rsp, test.err })
}

recorder := makeAddChainRequest(t, info.li, chain)
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestAddPrechain(t *testing.T) {
req, leafChain := parseChain(t, true, test.chain, info.roots.RawCertificates()[0])
rsp := uint64(0)
info.storage.EXPECT().AddIssuerChain(deadlineMatcher(), cmpMatcher{leafChain[1:]}).Return(nil)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(rsp, test.err)
info.storage.EXPECT().Add(deadlineMatcher(), cmpMatcher{req}).Return(func() (uint64, error) { return rsp, test.err })
}

recorder := makeAddPrechainRequest(t, info.li, chain)
Expand Down
8 changes: 4 additions & 4 deletions personalities/sctfe/mockstorage/mock_ct_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions personalities/sctfe/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const (

// Storage provides all the storage primitives necessary to write to a ct-static-api log.
type Storage interface {
// Add assigns an index to the provided Entry, stages the entry for integration, and return it the assigned index.
Add(context.Context, *ctonly.Entry) (uint64, error)
// Add assigns an index to the provided Entry, stages the entry for integration, and returns a future for the assigned index.
Add(context.Context, *ctonly.Entry) tessera.IndexFuture
// AddIssuerChain stores every the chain certificate in a content-addressable store under their sha256 hash.
AddIssuerChain(context.Context, []*x509.Certificate) error
}
Expand All @@ -54,7 +54,7 @@ type IssuerStorage interface {

// CTStorage implements Storage.
type CTStorage struct {
storeData func(context.Context, *ctonly.Entry) (uint64, error)
storeData func(context.Context, *ctonly.Entry) tessera.IndexFuture
storeIssuers func(context.Context, []KV) error
}

Expand All @@ -68,7 +68,7 @@ func NewCTSTorage(logStorage tessera.Storage, issuerStorage IssuerStorage) (*CTS
}

// Add stores CT entries.
func (cts *CTStorage) Add(ctx context.Context, entry *ctonly.Entry) (uint64, error) {
func (cts *CTStorage) Add(ctx context.Context, entry *ctonly.Entry) tessera.IndexFuture {
// TODO(phboneff): add deduplication and chain storage
return cts.storeData(ctx, entry)
}
Expand Down

0 comments on commit bd0e1c3

Please sign in to comment.