Skip to content

Commit d089e5d

Browse files
author
dlorenc
authored
Cleanup some initialization/flag parsing in rekor-server. (#433)
This is in preparation for supporting multiple logIDs (for sharding). Signed-off-by: Dan Lorenc <dlorenc@google.com>
1 parent 11a91be commit d089e5d

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

pkg/api/api.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"time"
2626

2727
"github.com/google/trillian"
28-
"github.com/google/trillian/client"
2928
radix "github.com/mediocregopher/radix/v4"
3029
"github.com/pkg/errors"
3130
"github.com/spf13/viper"
@@ -61,7 +60,6 @@ type API struct {
6160
tsaSigner signature.Signer // the signer to use for timestamping
6261
certChain []*x509.Certificate // timestamping cert chain
6362
certChainPem string // PEM encoded timestamping cert chain
64-
verifier *client.LogVerifier
6563
}
6664

6765
func NewAPI() (*API, error) {
@@ -85,13 +83,6 @@ func NewAPI() (*API, error) {
8583
tLogID = t.TreeId
8684
}
8785

88-
t, err := logAdminClient.GetTree(ctx, &trillian.GetTreeRequest{
89-
TreeId: tLogID,
90-
})
91-
if err != nil {
92-
return nil, errors.Wrap(err, "get tree")
93-
}
94-
9586
rekorSigner, err := signer.New(ctx, viper.GetString("rekor_server.signer"))
9687
if err != nil {
9788
return nil, errors.Wrap(err, "getting new signer")
@@ -108,11 +99,6 @@ func NewAPI() (*API, error) {
10899

109100
pubkey := cryptoutils.PEMEncode(cryptoutils.PublicKeyPEMType, b)
110101

111-
verifier, err := client.NewLogVerifierFromTree(t)
112-
if err != nil {
113-
return nil, errors.Wrap(err, "new verifier")
114-
}
115-
116102
// Use an in-memory key for timestamping
117103
tsaSigner, err := signer.New(ctx, signer.MemoryScheme)
118104
if err != nil {
@@ -146,15 +132,17 @@ func NewAPI() (*API, error) {
146132
}
147133

148134
return &API{
149-
logClient: logClient,
150-
logID: tLogID,
151-
pubkey: string(pubkey),
152-
pubkeyHash: hex.EncodeToString(pubkeyHashBytes[:]),
153-
signer: rekorSigner,
135+
// Transparency Log Stuff
136+
logClient: logClient,
137+
logID: tLogID,
138+
// Signing/verifying fields
139+
pubkey: string(pubkey),
140+
pubkeyHash: hex.EncodeToString(pubkeyHashBytes[:]),
141+
signer: rekorSigner,
142+
// TSA signing stuff
154143
tsaSigner: tsaSigner,
155144
certChain: certChain,
156145
certChainPem: string(certChainPem),
157-
verifier: verifier,
158146
}, nil
159147
}
160148

pkg/api/timestamp.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"net/http"
2525

2626
"github.com/go-openapi/runtime/middleware"
27-
"github.com/pkg/errors"
2827
"github.com/sassoftware/relic/lib/pkcs9"
2928
"github.com/sigstore/rekor/pkg/generated/restapi/operations/entries"
3029
"github.com/sigstore/rekor/pkg/generated/restapi/operations/timestamp"
@@ -47,11 +46,6 @@ func RequestFromRekor(ctx context.Context, req pkcs9.TimeStampReq) ([]byte, erro
4746
}
4847

4948
func TimestampResponseHandler(params timestamp.GetTimestampResponseParams) middleware.Responder {
50-
// Fail early if we don't haven't configured rekor with a certificate for timestamping.
51-
if len(api.certChain) == 0 {
52-
return handleRekorAPIError(params, http.StatusNotImplemented, errors.New("rekor is not configured to serve timestamps"), "")
53-
}
54-
5549
// TODO: Add support for in-house JSON based timestamp response.
5650
requestBytes, err := ioutil.ReadAll(params.Request)
5751
if err != nil {
@@ -96,8 +90,5 @@ func TimestampResponseHandler(params timestamp.GetTimestampResponseParams) middl
9690
}
9791

9892
func GetTimestampCertChainHandler(params timestamp.GetTimestampCertChainParams) middleware.Responder {
99-
if len(api.certChain) == 0 {
100-
return handleRekorAPIError(params, http.StatusNotFound, errors.New("rekor is not configured with a timestamping certificate"), "")
101-
}
10293
return timestamp.NewGetTimestampCertChainOK().WithPayload(api.certChainPem)
10394
}

pkg/api/trillian_client.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/google/trillian/merkle/logverifier"
2525
"github.com/google/trillian/merkle/rfc6962/hasher"
26+
rfc6962 "github.com/google/trillian/merkle/rfc6962/hasher"
2627
"github.com/pkg/errors"
2728

2829
"google.golang.org/grpc/codes"
@@ -35,18 +36,16 @@ import (
3536
)
3637

3738
type TrillianClient struct {
38-
client trillian.TrillianLogClient
39-
logID int64
40-
context context.Context
41-
verifier *client.LogVerifier
39+
client trillian.TrillianLogClient
40+
logID int64
41+
context context.Context
4242
}
4343

4444
func NewTrillianClient(ctx context.Context) TrillianClient {
4545
return TrillianClient{
46-
client: api.logClient,
47-
logID: api.logID,
48-
context: ctx,
49-
verifier: api.verifier,
46+
client: api.logClient,
47+
logID: api.logID,
48+
context: ctx,
5049
}
5150
}
5251

@@ -102,7 +101,8 @@ func (t *TrillianClient) addLeaf(byteValue []byte) *Response {
102101
getAddResult: resp,
103102
}
104103
}
105-
logClient := client.New(t.logID, t.client, t.verifier, root)
104+
v := client.NewLogVerifier(rfc6962.DefaultHasher)
105+
logClient := client.New(t.logID, t.client, v, root)
106106

107107
waitForInclusion := func(ctx context.Context, leafHash []byte) *Response {
108108
if logClient.MinMergeDelay > 0 {
@@ -252,8 +252,10 @@ func (t *TrillianClient) getProofByHash(hashValue []byte) *Response {
252252
})
253253

254254
if resp != nil {
255+
v := client.NewLogVerifier(rfc6962.DefaultHasher)
255256
for _, proof := range resp.Proof {
256-
if err := t.verifier.VerifyInclusionByHash(&root, hashValue, proof); err != nil {
257+
258+
if err := v.VerifyInclusionByHash(&root, hashValue, proof); err != nil {
257259
return &Response{
258260
status: status.Code(err),
259261
err: err,

0 commit comments

Comments
 (0)