@@ -73,13 +73,11 @@ var (
73
73
when use PEM/DER certificate file.` ))
74
74
pCertFormat = flags .String ("cert-format" , string (lib .CertKeyFormatPEM ), prettify (`
75
75
cert Format of given input (PEM, DER, PKCS12; heuristic if missing).` ))
76
- pass = flags .String ("pass" , "" , prettify (`
77
- Pass phrase for the key ` ))
76
+ certPass = flags .String ("pass" , "" , prettify (`
77
+ Pass phrase for the PKCS12 cert ` ))
78
78
key = flags .String ("key" , "" , prettify (`
79
79
File containing client private key, to present to the server. Not valid
80
80
with -plaintext option. Must also provide -cert option.` ))
81
- pKeyFormat = flags .String ("key-format" , string (lib .CertKeyFormatPEM ), prettify (`
82
- key Format of given input (PEM, DER; heuristic if missing).` ))
83
81
84
82
// ALTS Options
85
83
usealts = flags .Bool ("alts" , false , prettify (`
@@ -300,7 +298,7 @@ func main() {
300
298
usetls := ! * plaintext && ! * usealts
301
299
cacertFormat := lib .NewCertificateKeyFormat (* pCACertFormat )
302
300
certFormat := lib .NewCertificateKeyFormat (* pCertFormat )
303
- keyFormat := lib .NewCertificateKeyFormat ( * pKeyFormat )
301
+ keyFormat := lib .CertKeyFormatPEM
304
302
305
303
// Do extra validation on arguments and figure out what user asked us to do.
306
304
if * connectTimeout < 0 {
@@ -330,55 +328,45 @@ func main() {
330
328
331
329
if usetls {
332
330
if * cacert != "" {
333
- if cacertFormat .IsNone () {
334
- guessFormat , err := lib .GuessFormatForFile (* cacert , "" )
335
- if err != nil {
336
- fail (nil , "Fail to guess file format of -key err: %s" , err )
337
- }
338
- cacertFormat .Set (guessFormat )
331
+ guessFormat , err := lib .GuessFormatForFile (* cacert , cacertFormat )
332
+ if err != nil {
333
+ fail (nil , "Fail to guess file format of -key err: %s" , err )
339
334
}
340
- switch cacertFormat {
335
+ switch guessFormat {
341
336
case lib .CertKeyFormatPEM , lib .CertKeyFormatDER :
342
- // do nothing
337
+ cacertFormat = guessFormat
343
338
default :
344
- fail (nil , "The -cacert-format %s not support." , keyFormat )
339
+ fail (nil , "The -cacert-format %s not support." , cacertFormat )
345
340
}
346
341
}
347
342
if * cert != "" {
348
- if certFormat .IsNone () {
349
- guessFormat , err := lib .GuessFormatForFile (* cert , "" )
350
- if err != nil {
351
- fail (nil , "Fail to guess file format of -cert err: %s" , err )
352
- }
353
- certFormat .Set (guessFormat )
343
+ guessFormat , err := lib .GuessFormatForFile (* cert , certFormat )
344
+ if err != nil {
345
+ fail (nil , "Fail to guess file format of -cert err: %s" , err )
354
346
}
355
347
356
- switch certFormat {
348
+ switch guessFormat {
357
349
case lib .CertKeyFormatPEM , lib .CertKeyFormatDER :
358
350
if * cert == "" || * key == "" {
359
351
fail (nil , "The -cert and -key arguments must be used together and both be present." )
360
352
}
353
+ certFormat = guessFormat
361
354
case lib .CertKeyFormatPKCS12 :
362
- // do nothing
355
+ certFormat = guessFormat
363
356
default :
364
357
fail (nil , "The -cert-format %s not support." , certFormat )
365
358
}
366
359
}
367
- if * key != "" {
368
- if keyFormat .IsNone () {
369
- guessFormat , err := lib .GuessFormatForFile (* key , "" )
370
- if err != nil {
371
- fail (nil , "Fail to guess file format of -key err: %s" , err )
372
- }
373
- keyFormat .Set (guessFormat )
374
- }
375
- switch keyFormat {
376
- case lib .CertKeyFormatPEM , lib .CertKeyFormatDER :
377
- if * cert == "" || * key == "" {
378
- fail (nil , "The -cert and -key arguments must be used together and both be present." )
379
- }
360
+ if * certPass != "" {
361
+ switch certFormat {
362
+ case lib .CertKeyFormatPKCS12 :
380
363
default :
381
- fail (nil , "The -key-format %s not support." , keyFormat )
364
+ fail (nil , "The -pass argument is only supported when -cert-type is PKCS12." )
365
+ }
366
+ }
367
+ if * key != "" {
368
+ if * cert == "" || * key == "" {
369
+ fail (nil , "The -cert and -key arguments must be used together and both be present." )
382
370
}
383
371
}
384
372
@@ -518,7 +506,7 @@ func main() {
518
506
}
519
507
creds = alts .NewClientCreds (clientOptions )
520
508
} else if usetls {
521
- tlsConf , err := lib .ClientTLSConfigV2 (* insecure , * cacert , cacertFormat , * cert , certFormat , * key , keyFormat , * pass )
509
+ tlsConf , err := lib .ClientTLSConfigV2 (* insecure , * cacert , cacertFormat , * cert , certFormat , * key , keyFormat , * certPass )
522
510
if err != nil {
523
511
fail (err , "Failed to create TLS config" )
524
512
}
0 commit comments