-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attestation/Blob signing and verification using a RFC3161 time-stamping server #2464
Changes from all commits
47be791
de64e54
5ea599a
c8b930b
cbd56f5
3367200
b969b8b
749f796
3f6115b
1a0f088
954fd50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ import ( | |
"github.com/sigstore/cosign/cmd/cosign/cli/rekor" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/sign" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/upload" | ||
"github.com/sigstore/cosign/internal/pkg/cosign/tsa" | ||
"github.com/sigstore/sigstore/pkg/cryptoutils" | ||
tsaclient "github.com/sigstore/timestamp-authority/pkg/client" | ||
|
||
"github.com/sigstore/cosign/pkg/cosign" | ||
cremote "github.com/sigstore/cosign/pkg/cosign/remote" | ||
|
@@ -192,6 +194,7 @@ func signPolicy() *cobra.Command { | |
OIDCRedirectURL: o.OIDC.RedirectURL, | ||
OIDCProvider: o.OIDC.Provider, | ||
SkipConfirmation: o.SkipConfirmation, | ||
TSAServerURL: o.TSAServerURL, | ||
} | ||
sv, err := sign.SignerFromKeyOpts(ctx, "", "", ko) | ||
|
||
|
@@ -260,8 +263,20 @@ func signPolicy() *cobra.Command { | |
return err | ||
} | ||
|
||
if o.TSAServerURL != "" { | ||
clientTSA, err := tsaclient.GetTimestampClient(o.TSAServerURL) | ||
if err != nil { | ||
return fmt.Errorf("failed to create TSA client: %w", err) | ||
} | ||
// Here we get the response from the timestamped authority server | ||
_, err = tsa.GetTimestampedSignature(signed.Signed, clientTSA) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit for style: |
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Upload to rekor | ||
if sign.ShouldUploadToTlog(ctx, ko, ref, ko.SkipConfirmation, o.TlogUpload, "") { | ||
if sign.ShouldUploadToTlog(ctx, ko, ref, o.TlogUpload) { | ||
// TODO: Refactor with sign.go | ||
rekorBytes := sv.Cert | ||
rekorClient, err := rekor.NewClient(o.Rekor.URL) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,9 @@ import ( | |
"os" | ||
"path/filepath" | ||
|
||
"github.com/sigstore/cosign/internal/pkg/cosign/tsa" | ||
cbundle "github.com/sigstore/cosign/pkg/cosign/bundle" | ||
tsaclient "github.com/sigstore/timestamp-authority/pkg/client" | ||
|
||
"github.com/sigstore/cosign/cmd/cosign/cli/options" | ||
"github.com/sigstore/cosign/cmd/cosign/cli/rekor" | ||
|
@@ -65,7 +67,21 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.Re | |
|
||
signedPayload := cosign.LocalSignedPayload{} | ||
|
||
if ShouldUploadToTlog(ctx, ko, nil, ko.SkipConfirmation, tlogUpload, "") { | ||
if ko.TSAServerURL != "" { | ||
clientTSA, err := tsaclient.GetTimestampClient(ko.TSAServerURL) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create TSA client: %w", err) | ||
} | ||
b64Sig := []byte(base64.StdEncoding.EncodeToString(sig)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we document somewhere that we're generating a timestamp over the base64 signature, not the raw bytes? This was somewhat discussed in sigstore/timestamp-authority#116 - Cosign is being opinionated in using the base64-encoded sig, which I agree with, just think we should be explicit about this. Update the SPEC docs for the OCI annotations? |
||
|
||
respBytes, err := tsa.GetTimestampedSignature(b64Sig, clientTSA) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
signedPayload.RFC3161Timestamp = cbundle.TimestampToRFC3161Timestamp(respBytes) | ||
} | ||
if ShouldUploadToTlog(ctx, ko, nil, tlogUpload) { | ||
rekorBytes, err = sv.Bytes(ctx) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -82,6 +98,20 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.Re | |
signedPayload.Bundle = cbundle.EntryToBundle(entry) | ||
} | ||
|
||
// if bundle is specified, just do that and ignore the rest | ||
if ko.RFC3161TimestampPath != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we require that if |
||
signedPayload.Base64Signature = base64.StdEncoding.EncodeToString(sig) | ||
|
||
contents, err := json.Marshal(signedPayload) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be writing |
||
if err != nil { | ||
return nil, err | ||
} | ||
if err := os.WriteFile(ko.RFC3161TimestampPath, contents, 0600); err != nil { | ||
return nil, fmt.Errorf("create rfc3161 timestamp file: %w", err) | ||
} | ||
fmt.Printf("RF3161 timestamp bundle wrote in the file %s\n", ko.RFC3161TimestampPath) | ||
} | ||
|
||
// if bundle is specified, just do that and ignore the rest | ||
if ko.BundlePath != "" { | ||
signedPayload.Base64Signature = base64.StdEncoding.EncodeToString(sig) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description needs to be updated, this was copied from BundlePath.