Skip to content

Commit f29d57e

Browse files
committed
Validate signing-algorithm immediately
Signed-off-by: Riccardo Schirone <[email protected]>
1 parent 417daab commit f29d57e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/cosign/cli/signblob.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"fmt"
2121
"os"
22+
"strings"
2223

2324
"github.com/sigstore/cosign/v2/cmd/cosign/cli/generate"
2425
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
@@ -66,6 +67,21 @@ func SignBlob() *cobra.Command {
6667
if options.NOf(o.Key, o.SecurityKey.Use) > 1 {
6768
return &options.KeyParseError{}
6869
}
70+
71+
// Check if the algorithm is in the list of supported algorithms
72+
supportedAlgorithms := cosign.GetSupportedAlgorithms()
73+
isValid := false
74+
for _, algo := range supportedAlgorithms {
75+
if algo == o.SigningAlgorithm {
76+
isValid = true
77+
break
78+
}
79+
}
80+
if !isValid {
81+
return fmt.Errorf("invalid signing algorithm: %s. Supported algorithms are: %s",
82+
o.SigningAlgorithm, strings.Join(supportedAlgorithms, ", "))
83+
}
84+
6985
return nil
7086
},
7187
RunE: func(_ *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)