Skip to content

Commit

Permalink
Don't require RFC3161 timestamp path if you are using protobuf bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Steindler <[email protected]>
  • Loading branch information
steiza committed Jul 1, 2024
1 parent 7a17dd3 commit 095856f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 12 additions & 9 deletions cmd/cosign/cli/attest/attest_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
defer cancelFn()
}

if c.TSAServerURL != "" && c.RFC3161TimestampPath == "" {
return errors.New("expected an rfc3161-timestamp path when using a TSA server")
if c.TSAServerURL != "" && c.RFC3161TimestampPath == "" && !c.ProtobufBundleFormat {
return errors.New("expected either protobuf bundle or an rfc3161-timestamp path when using a TSA server")
}

var artifact []byte
Expand Down Expand Up @@ -173,14 +173,17 @@ func (c *AttestBlobCommand) Exec(ctx context.Context, artifactPath string) error
if rfc3161Timestamp == nil {
return fmt.Errorf("rfc3161 timestamp is nil")
}
ts, err := json.Marshal(rfc3161Timestamp)
if err != nil {
return err
}
if err := os.WriteFile(c.RFC3161TimestampPath, ts, 0600); err != nil {
return fmt.Errorf("create RFC3161 timestamp file: %w", err)

if c.RFC3161TimestampPath != "" {
ts, err := json.Marshal(rfc3161Timestamp)
if err != nil {
return err
}
if err := os.WriteFile(c.RFC3161TimestampPath, ts, 0600); err != nil {
return fmt.Errorf("create RFC3161 timestamp file: %w", err)
}
fmt.Fprintln(os.Stderr, "RFC3161 timestamp bundle written to file ", c.RFC3161TimestampPath)
}
fmt.Fprintln(os.Stderr, "RFC3161 timestamp bundle written to file ", c.RFC3161TimestampPath)
}

rekorBytes, err := sv.Bytes(ctx)
Expand Down
21 changes: 12 additions & 9 deletions cmd/cosign/cli/sign/sign_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, payloadPath string
var timestampBytes []byte

if ko.TSAServerURL != "" {
if ko.RFC3161TimestampPath == "" {
return nil, fmt.Errorf("timestamp output path must be set")
if ko.RFC3161TimestampPath == "" && !ko.ProtobufBundleFormat {
return nil, fmt.Errorf("must use protobuf bundle or set timestamp output path")
}
var err error
if ko.TSAClientCACert == "" && ko.TSAClientCert == "" { // no mTLS params or custom CA
Expand All @@ -108,14 +108,17 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, payloadPath string
if rfc3161Timestamp == nil {
return nil, fmt.Errorf("rfc3161 timestamp is nil")
}
ts, err := json.Marshal(rfc3161Timestamp)
if err != nil {
return nil, err
}
if err := os.WriteFile(ko.RFC3161TimestampPath, ts, 0600); err != nil {
return nil, fmt.Errorf("create RFC3161 timestamp file: %w", err)

if ko.RFC3161TimestampPath != "" {
ts, err := json.Marshal(rfc3161Timestamp)
if err != nil {
return nil, err
}
if err := os.WriteFile(ko.RFC3161TimestampPath, ts, 0600); err != nil {
return nil, fmt.Errorf("create RFC3161 timestamp file: %w", err)
}
ui.Infof(ctx, "RFC3161 timestamp written to file %s\n", ko.RFC3161TimestampPath)
}
ui.Infof(ctx, "RFC3161 timestamp written to file %s\n", ko.RFC3161TimestampPath)
}
shouldUpload, err := ShouldUploadToTlog(ctx, ko, nil, tlogUpload)
if err != nil {
Expand Down

0 comments on commit 095856f

Please sign in to comment.