Skip to content

Commit 8002de8

Browse files
committed
Encoding Public Key when no cert is present in sign-blob request
Signed-off-by: Tommy Dalton <[email protected]>
1 parent ade0d32 commit 8002de8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/cosign/cli/sign/sign_blob.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/sigstore/cosign/v2/internal/ui"
3636
"github.com/sigstore/cosign/v2/pkg/cosign"
3737
cbundle "github.com/sigstore/cosign/v2/pkg/cosign/bundle"
38+
sigs "github.com/sigstore/cosign/v2/pkg/signature"
3839
protobundle "github.com/sigstore/protobuf-specs/gen/pb-go/bundle/v1"
3940
protocommon "github.com/sigstore/protobuf-specs/gen/pb-go/common/v1"
4041
"github.com/sigstore/rekor/pkg/generated/models"
@@ -45,7 +46,7 @@ import (
4546
// nolint
4647
func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, payloadPath string, b64 bool, outputSignature string, outputCertificate string, tlogUpload bool) ([]byte, error) {
4748
var payload internal.HashReader
48-
49+
var err error
4950
ctx, cancel := context.WithTimeout(context.Background(), ro.Timeout)
5051
defer cancel()
5152

@@ -240,7 +241,17 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, payloadPath string
240241
return nil, fmt.Errorf("create certificate file: %w", err)
241242
}
242243
ui.Infof(ctx, "Wrote certificate to file %s", outputCertificate)
244+
} else {
245+
pemBytes, err := sigs.PublicKeyPem(sv, signatureoptions.WithContext(ctx))
246+
if err != nil {
247+
return nil, err
248+
}
249+
if err := os.WriteFile(outputCertificate, pemBytes, 0600); err != nil {
250+
return nil, err
251+
}
252+
return pemBytes, nil
243253
}
254+
244255
}
245256

246257
return sig, nil

0 commit comments

Comments
 (0)