@@ -43,6 +43,9 @@ const (
43
43
// Client authentication valid for defaults
44
44
defaultClientAuthValidFor = time .Hour * 24 * 365 * 1 // 1 years
45
45
defaultClientAuthCAValidFor = time .Hour * 24 * 365 * 15 // 15 years
46
+ // TLS curve defaults
47
+ defaultTLSCurve = "P256"
48
+ defaultClientAuthCurve = "P521"
46
49
)
47
50
48
51
var (
@@ -148,11 +151,11 @@ type createCAOptions struct {
148
151
ecdsaCurve string
149
152
}
150
153
151
- func (o * createCAOptions ) ConfigureFlags (f * pflag.FlagSet , defaultFName string , defaultValidFor time.Duration ) {
154
+ func (o * createCAOptions ) ConfigureFlags (f * pflag.FlagSet , defaultFName string , defaultValidFor time.Duration , defaultCurve string ) {
152
155
f .StringVar (& o .certFile , "cert" , defaultFName + ".crt" , "Filename of the generated CA certificate" )
153
156
f .StringVar (& o .keyFile , "key" , defaultFName + ".key" , "Filename of the generated CA private key" )
154
157
f .DurationVar (& o .validFor , "validfor" , defaultValidFor , "Lifetime of the certificate until expiration" )
155
- f .StringVar (& o .ecdsaCurve , "curve" , "P521" , "ECDSA curve used for private key" )
158
+ f .StringVar (& o .ecdsaCurve , "curve" , defaultCurve , "ECDSA curve used for private key" )
156
159
}
157
160
158
161
func (o * createCAOptions ) CreateCA () {
@@ -184,13 +187,13 @@ type createCertificateBaseOptions struct {
184
187
ecdsaCurve string
185
188
}
186
189
187
- func (o * createCertificateBaseOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration ) {
190
+ func (o * createCertificateBaseOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration , defaultCurve string ) {
188
191
f .StringVar (& o .caCertFile , "cacert" , defaultCAFName + ".crt" , "File containing TLS CA certificate" )
189
192
f .StringVar (& o .caKeyFile , "cakey" , defaultCAFName + ".key" , "File containing TLS CA private key" )
190
193
f .StringSliceVar (& o .hosts , "host" , nil , "Host name to include in the certificate" )
191
194
f .StringSliceVar (& o .emailAddresses , "email" , nil , "Email address to include in the certificate" )
192
195
f .DurationVar (& o .validFor , "validfor" , defaultValidFor , "Lifetime of the certificate until expiration" )
193
- f .StringVar (& o .ecdsaCurve , "curve" , "P521" , "ECDSA curve used for private key" )
196
+ f .StringVar (& o .ecdsaCurve , "curve" , defaultCurve , "ECDSA curve used for private key" )
194
197
}
195
198
196
199
// Create a certificate from given options.
@@ -206,8 +209,8 @@ func (o *createCertificateBaseOptions) CreateCertificate(isClientAuth bool) (str
206
209
207
210
// Create certificate
208
211
options := certificates.CreateCertificateOptions {
209
- Hosts : o .hosts ,
210
- EmailAddresses : o .emailAddresses ,
212
+ Hosts : removeEmptyStrings ( o .hosts ) ,
213
+ EmailAddresses : removeEmptyStrings ( o .emailAddresses ) ,
211
214
ValidFor : o .validFor ,
212
215
ECDSACurve : o .ecdsaCurve ,
213
216
IsClientAuth : isClientAuth ,
@@ -225,8 +228,8 @@ type createKeyFileOptions struct {
225
228
keyFile string
226
229
}
227
230
228
- func (o * createKeyFileOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration ) {
229
- o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor )
231
+ func (o * createKeyFileOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration , defaultCurve string ) {
232
+ o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor , defaultCurve )
230
233
f .StringVar (& o .keyFile , "keyfile" , defaultFName + ".keyfile" , "Filename of keyfile to generate" )
231
234
}
232
235
@@ -247,8 +250,8 @@ type createCertificateOptions struct {
247
250
keyFile string
248
251
}
249
252
250
- func (o * createCertificateOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration ) {
251
- o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor )
253
+ func (o * createCertificateOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration , defaultCurve string ) {
254
+ o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor , defaultCurve )
252
255
f .StringVar (& o .certFile , "cert" , defaultFName + ".crt" , "Filename of the generated certificate" )
253
256
f .StringVar (& o .keyFile , "key" , defaultFName + ".key" , "Filename of the generated private key" )
254
257
}
@@ -272,8 +275,8 @@ type createKeystoreOptions struct {
272
275
alias string
273
276
}
274
277
275
- func (o * createKeystoreOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration ) {
276
- o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor )
278
+ func (o * createKeystoreOptions ) ConfigureFlags (f * pflag.FlagSet , defaultCAFName , defaultFName string , defaultValidFor time.Duration , defaultCurve string ) {
279
+ o .createCertificateBaseOptions .ConfigureFlags (f , defaultCAFName , defaultFName , defaultValidFor , defaultCurve )
277
280
f .StringVar (& o .keystoreFile , "keystore" , defaultFName + ".jks" , "Filename of the generated keystore" )
278
281
f .StringVar (& o .keystorePassword , "keystore-password" , "" , "Password of the generated keystore" )
279
282
f .StringVar (& o .alias , "alias" , "" , "Aliases use to store the certificate under in the keystore" )
@@ -317,12 +320,12 @@ func AddCommands(cmd *cobra.Command, logFatalFunc func(error, string), showUsage
317
320
cmdCreateClientAuth .AddCommand (cmdCreateClientAuthKeyFile )
318
321
319
322
createOptions .jwtsecret .ConfigureFlags (cmdCreateJWTSecret .Flags ())
320
- createOptions .tls .ca .ConfigureFlags (cmdCreateTLSCA .Flags (), "tls-ca" , defaultTLSCAValidFor )
321
- createOptions .tls .keyFile .ConfigureFlags (cmdCreateTLSKeyFile .Flags (), "tls-ca" , "tls" , defaultTLSValidFor )
322
- createOptions .tls .certificate .ConfigureFlags (cmdCreateTLSCertificate .Flags (), "tls-ca" , "tls" , defaultTLSValidFor )
323
- createOptions .tls .keystore .ConfigureFlags (cmdCreateTLSKeystore .Flags (), "tls-ca" , "tls" , defaultTLSValidFor )
324
- createOptions .clientAuth .ca .ConfigureFlags (cmdCreateClientAuthCA .Flags (), "client-auth-ca" , defaultClientAuthCAValidFor )
325
- createOptions .clientAuth .keyFile .ConfigureFlags (cmdCreateClientAuthKeyFile .Flags (), "client-auth-ca" , "client-auth" , defaultClientAuthValidFor )
323
+ createOptions .tls .ca .ConfigureFlags (cmdCreateTLSCA .Flags (), "tls-ca" , defaultTLSCAValidFor , defaultTLSCurve )
324
+ createOptions .tls .keyFile .ConfigureFlags (cmdCreateTLSKeyFile .Flags (), "tls-ca" , "tls" , defaultTLSValidFor , defaultTLSCurve )
325
+ createOptions .tls .certificate .ConfigureFlags (cmdCreateTLSCertificate .Flags (), "tls-ca" , "tls" , defaultTLSValidFor , defaultTLSCurve )
326
+ createOptions .tls .keystore .ConfigureFlags (cmdCreateTLSKeystore .Flags (), "tls-ca" , "tls" , defaultTLSValidFor , defaultTLSCurve )
327
+ createOptions .clientAuth .ca .ConfigureFlags (cmdCreateClientAuthCA .Flags (), "client-auth-ca" , defaultClientAuthCAValidFor , defaultClientAuthCurve )
328
+ createOptions .clientAuth .keyFile .ConfigureFlags (cmdCreateClientAuthKeyFile .Flags (), "client-auth-ca" , "client-auth" , defaultClientAuthValidFor , defaultClientAuthCurve )
326
329
}
327
330
328
331
// Cobra run function using the usage of the given command
@@ -401,3 +404,14 @@ func mustReadFile(filename string, flagName string) string {
401
404
}
402
405
return string (content )
403
406
}
407
+
408
+ // removeEmptyStrings returns the given slice without all empty entries removed.
409
+ func removeEmptyStrings (slice []string ) []string {
410
+ result := make ([]string , 0 , len (slice ))
411
+ for _ , x := range slice {
412
+ if x != "" {
413
+ result = append (result , x )
414
+ }
415
+ }
416
+ return result
417
+ }
0 commit comments