@@ -33,7 +33,7 @@ func createCommand() cli.Command {
3333 UsageText : `**step crypto jwk create** <public-jwk-file> <private-jwk-file>
3434 [**--kty**=<type>] [**--alg**=<algorithm>] [**--use**=<use>]
3535 [**--size**=<size>] [**--crv**=<curve>] [**--kid**=<kid>]
36- [**--from-pem**=<pem-file>]` ,
36+ [**--from-pem**=<pem-file>] [**--password-file**=<file>] ` ,
3737 Description : `**step crypto jwk create** generates a new JWK (JSON Web Key) or constructs a
3838JWK from an existing key. The generated JWK conforms to RFC7517 and can be used
3939to sign and encrypt data using JWT, JWS, and JWE.
@@ -393,28 +393,28 @@ related.`,
393393 Usage : `Create a JWK representing the key encoded in an
394394existing <pem-file> instead of creating a new key.` ,
395395 },
396- cli.BoolFlag {
397- Name : "no-password" ,
398- Usage : `Do not ask for a password to encrypt the JWK. Sensitive
399- key material will be written to disk unencrypted. This is not
400- recommended. Requires **--insecure** flag.` ,
401- },
396+ flags .PasswordFile ,
397+ flags .NoPassword ,
402398 flags .Subtle ,
403399 flags .Insecure ,
404400 flags .Force ,
405401 },
406402 }
407403}
408404
409- func createAction (ctx * cli.Context ) error {
405+ func createAction (ctx * cli.Context ) ( err error ) {
410406 // require public and private files
411407 if err := errs .NumberOfArguments (ctx , 2 ); err != nil {
412408 return err
413409 }
414410
415411 // Use password to protect private JWK by default
416412 usePassword := true
413+ passwordFile := ctx .String ("password-file" )
417414 if ctx .Bool ("no-password" ) {
415+ if len (passwordFile ) > 0 {
416+ return errs .IncompatibleFlag (ctx , "no-password" , "password-file" )
417+ }
418418 if ctx .Bool ("insecure" ) {
419419 usePassword = false
420420 } else {
@@ -428,6 +428,15 @@ func createAction(ctx *cli.Context) error {
428428 return errs .EqualArguments (ctx , "public-jwk-file" , "private-jwk-file" )
429429 }
430430
431+ // Read password if necessary
432+ var password string
433+ if len (passwordFile ) > 0 {
434+ password , err = utils .ReadStringPasswordFromFile (passwordFile )
435+ if err != nil {
436+ return err
437+ }
438+ }
439+
431440 kty := ctx .String ("kty" )
432441 crv := ctx .String ("crv" )
433442 alg := ctx .String ("alg" )
@@ -476,7 +485,6 @@ func createAction(ctx *cli.Context) error {
476485 }
477486
478487 // Generate or read secrets
479- var err error
480488 var jwk * jose.JSONWebKey
481489 switch {
482490 case pemFile != "" :
@@ -539,7 +547,7 @@ func createAction(ctx *cli.Context) error {
539547 var rcpt jose.Recipient
540548 // Generate JWE encryption key.
541549 if jose .SupportsPBKDF2 {
542- key , err := ui .PromptPassword ("Please enter the password to encrypt the private JWK" )
550+ key , err := ui .PromptPassword ("Please enter the password to encrypt the private JWK" , ui . WithValue ( password ) )
543551 if err != nil {
544552 return errors .Wrap (err , "error reading password" )
545553 }
0 commit comments