@@ -20,20 +20,25 @@ import (
20
20
"net/http"
21
21
"net/http/pprof"
22
22
"os"
23
+ "sort"
24
+ "strings"
23
25
"time"
24
26
25
27
homedir "github.com/mitchellh/go-homedir"
28
+ v1 "github.com/sigstore/protobuf-specs/gen/pb-go/common/v1"
26
29
"github.com/sigstore/rekor/pkg/log"
30
+ "github.com/sigstore/sigstore/pkg/signature"
27
31
"github.com/spf13/cobra"
28
32
"github.com/spf13/viper"
29
33
30
34
"sigs.k8s.io/release-utils/version"
31
35
)
32
36
33
37
var (
34
- cfgFile string
35
- logType string
36
- enablePprof bool
38
+ cfgFile string
39
+ logType string
40
+ enablePprof bool
41
+ clientSigningAlgorithms ClientSigningAlgorithmOptions
37
42
// these map to the operationId as defined in openapi.yaml file
38
43
operationIds = []string {
39
44
"searchIndex" ,
@@ -68,6 +73,64 @@ func Execute() {
68
73
}
69
74
}
70
75
76
+ type ClientSigningAlgorithmOptions []v1.KnownSignatureAlgorithm
77
+
78
+ func (sa * ClientSigningAlgorithmOptions ) String () string {
79
+ var algos []v1.KnownSignatureAlgorithm
80
+ if len (* sa ) == 0 {
81
+ algos = []v1.KnownSignatureAlgorithm {}
82
+ for keyAlgorithmId := range v1 .KnownSignatureAlgorithm_name {
83
+ if keyAlgorithmId == 0 {
84
+ continue
85
+ }
86
+ algos = append (algos , v1 .KnownSignatureAlgorithm (keyAlgorithmId ))
87
+ }
88
+ } else {
89
+ algos = []v1.KnownSignatureAlgorithm (* sa )
90
+ }
91
+ algos_str := []string {}
92
+ for _ , algo := range algos {
93
+ algo_str , err := signature .FormatSignatureAlgorithmFlag (algo )
94
+ if err != nil {
95
+ panic (err )
96
+ }
97
+ algos_str = append (algos_str , * algo_str )
98
+ }
99
+ return strings .Join (algos_str , "," )
100
+ }
101
+
102
+ func (sa * ClientSigningAlgorithmOptions ) Set (s string ) error {
103
+ algos := strings .Split (s , "," )
104
+ options := []v1.KnownSignatureAlgorithm {}
105
+ for _ , algo := range algos {
106
+ signatureAlgorithm , err := signature .ParseSignatureAlgorithmFlag (algo )
107
+ if err != nil {
108
+ return err
109
+ }
110
+ options = append (options , signatureAlgorithm )
111
+ }
112
+ * sa = ClientSigningAlgorithmOptions (options )
113
+ return nil
114
+ }
115
+
116
+ func (sa * ClientSigningAlgorithmOptions ) Type () string {
117
+ return "stringSlice"
118
+ }
119
+
120
+ func (sa * ClientSigningAlgorithmOptions ) Value () []v1.KnownSignatureAlgorithm {
121
+ if len (* sa ) == 0 {
122
+ algos := []v1.KnownSignatureAlgorithm {}
123
+ for keyAlgorithmId := range v1 .KnownSignatureAlgorithm_name {
124
+ if keyAlgorithmId == 0 {
125
+ continue
126
+ }
127
+ algos = append (algos , v1 .KnownSignatureAlgorithm (keyAlgorithmId ))
128
+ }
129
+ return algos
130
+ }
131
+ return []v1.KnownSignatureAlgorithm (* sa )
132
+ }
133
+
71
134
func init () {
72
135
cobra .OnInitialize (initConfig )
73
136
@@ -131,6 +194,21 @@ Memory and file-based signers should only be used for testing.`)
131
194
rootCmd .PersistentFlags ().Int ("search_index.mysql.max_open_connections" , 0 , "maximum open connections" )
132
195
rootCmd .PersistentFlags ().Int ("search_index.mysql.max_idle_connections" , 0 , "maximum idle connections" )
133
196
197
+ keyAlgorithmTypes := []string {}
198
+ for keyAlgorithmId := range v1 .KnownSignatureAlgorithm_name {
199
+ if keyAlgorithmId == 0 {
200
+ continue
201
+ }
202
+ keyFlag , err := signature .FormatSignatureAlgorithmFlag (v1 .KnownSignatureAlgorithm (keyAlgorithmId ))
203
+ if err != nil {
204
+ panic (err )
205
+ }
206
+ keyAlgorithmTypes = append (keyAlgorithmTypes , * keyFlag )
207
+ }
208
+ sort .Strings (keyAlgorithmTypes )
209
+ keyAlgorithmHelp := fmt .Sprintf ("signing algorithm to use for signing/hashing (allowed %s)" , strings .Join (keyAlgorithmTypes , ", " ))
210
+ rootCmd .PersistentFlags ().Var (& clientSigningAlgorithms , "client-signing-algorithms" , keyAlgorithmHelp )
211
+
134
212
if err := viper .BindPFlags (rootCmd .PersistentFlags ()); err != nil {
135
213
log .Logger .Fatal (err )
136
214
}
0 commit comments