Skip to content

Commit

Permalink
feat: sign will log entry Id
Browse files Browse the repository at this point in the history
Signed-off-by: peter_wu <peteeelol@gmail.com>
  • Loading branch information
goatwu1993 committed Nov 21, 2024
1 parent d4b65ad commit b81025b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion internal/pkg/cosign/rekor/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import (
"io"
"os"

"github.com/go-openapi/runtime"
"github.com/sigstore/cosign/v2/internal/pkg/cosign"
"github.com/sigstore/cosign/v2/internal/ui"
cosignv1 "github.com/sigstore/cosign/v2/pkg/cosign"
cbundle "github.com/sigstore/cosign/v2/pkg/cosign/bundle"
"github.com/sigstore/cosign/v2/pkg/oci"
"github.com/sigstore/cosign/v2/pkg/oci/mutate"
"github.com/sigstore/rekor/pkg/generated/client/entries"

"github.com/sigstore/rekor/pkg/generated/client"
"github.com/sigstore/rekor/pkg/generated/models"
Expand All @@ -54,6 +57,35 @@ type signerWrapper struct {

var _ cosign.Signer = (*signerWrapper)(nil)

type loggingRekorEntry struct {
inner entries.ClientService
}

func (l *loggingRekorEntry) CreateLogEntry(params *entries.CreateLogEntryParams, opts ...entries.ClientOption) (*entries.CreateLogEntryCreated, error) {
entry, err := l.inner.CreateLogEntry(params, opts...)
if err != nil {
return nil, err
}
ui.Infof(params.Context, "tlog entry created with entryId: %s", entry.ETag)
return entry, nil
}

func (l *loggingRekorEntry) GetLogEntryByIndex(params *entries.GetLogEntryByIndexParams, opts ...entries.ClientOption) (*entries.GetLogEntryByIndexOK, error) {
return l.inner.GetLogEntryByIndex(params, opts...)
}

func (l *loggingRekorEntry) GetLogEntryByUUID(params *entries.GetLogEntryByUUIDParams, opts ...entries.ClientOption) (*entries.GetLogEntryByUUIDOK, error) {
return l.inner.GetLogEntryByUUID(params, opts...)
}

func (l *loggingRekorEntry) SearchLogQuery(params *entries.SearchLogQueryParams, opts ...entries.ClientOption) (*entries.SearchLogQueryOK, error) {
return l.inner.SearchLogQuery(params, opts...)
}

func (l *loggingRekorEntry) SetTransport(transport runtime.ClientTransport) {
l.inner.SetTransport(transport)
}

// Sign implements `cosign.Signer`
func (rs *signerWrapper) Sign(ctx context.Context, payload io.Reader) (oci.Signature, crypto.PublicKey, error) {
sig, pub, err := rs.inner.Sign(ctx, payload)
Expand Down Expand Up @@ -89,8 +121,15 @@ func (rs *signerWrapper) Sign(ctx context.Context, payload io.Reader) (oci.Signa
if err != nil {
return nil, nil, err
}
loggingRClient := client.Rekor{
Entries: &loggingRekorEntry{inner: rs.rClient.Entries},
Index: rs.rClient.Index,
Pubkey: rs.rClient.Pubkey,
Tlog: rs.rClient.Tlog,
Transport: rs.rClient.Transport,
}

bundle, err := uploadToTlog(rekorBytes, rs.rClient, func(r *client.Rekor, b []byte) (*models.LogEntryAnon, error) {
bundle, err := uploadToTlog(rekorBytes, &loggingRClient, func(r *client.Rekor, b []byte) (*models.LogEntryAnon, error) {
checkSum := sha256.New()
if _, err := checkSum.Write(payloadBytes); err != nil {
return nil, err
Expand Down

0 comments on commit b81025b

Please sign in to comment.