Skip to content

Commit 8d30716

Browse files
committed
Encoding Public Key when no cert is present in sign-blob request
Signed-off-by: Tommy Dalton <tdalton@redhat.com>
1 parent fce8b6d commit 8d30716

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cmd/cosign/cli/sign/sign_blob.go

Lines changed: 11 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"
@@ -46,7 +47,6 @@ import (
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
4849
var err error
49-
5050
ctx, cancel := context.WithTimeout(context.Background(), ro.Timeout)
5151
defer cancel()
5252

@@ -244,7 +244,17 @@ func SignBlobCmd(ro *options.RootOptions, ko options.KeyOpts, payloadPath string
244244
return nil, fmt.Errorf("create certificate file: %w", err)
245245
}
246246
ui.Infof(ctx, "Wrote certificate to file %s", outputCertificate)
247+
} else {
248+
pemBytes, err := sigs.PublicKeyPem(sv, signatureoptions.WithContext(ctx))
249+
if err != nil {
250+
return nil, err
251+
}
252+
if err := os.WriteFile(outputCertificate, pemBytes, 0600); err != nil {
253+
return nil, err
254+
}
255+
return pemBytes, nil
247256
}
257+
248258
}
249259

250260
return sig, nil

0 commit comments

Comments
 (0)