Skip to content

Commit

Permalink
Add --password-file to crypto jwe encrypt
Browse files Browse the repository at this point in the history
Matches the already existing flag for `crypto jwe decrypt`.

While here fix usage string for the existing flag since it deals with
decryption.
  • Loading branch information
eest committed Oct 20, 2024
1 parent b436480 commit e781ba8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion command/crypto/jwe/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ one of the JWKs in the JWK Set.`,
},
cli.StringFlag{
Name: "password-file",
Usage: `The path to the <file> containing the password to encrypt the keys.`,
Usage: `The path to the <file> containing the password to decrypt the keys.`,
},
},
}
Expand Down
17 changes: 16 additions & 1 deletion command/crypto/jwe/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ parameter is ignored by JWE implementations, but may be processed by
applications that use JWE.`,
},
flags.SubtleHidden,
cli.StringFlag{
Name: "password-file",
Usage: `The path to the <file> containing the password to encrypt the keys.`,
},
},
}
}
Expand Down Expand Up @@ -188,6 +192,7 @@ func encryptAction(ctx *cli.Context) error {
typ := ctx.String("typ")
cty := ctx.String("cty")
isSubtle := ctx.Bool("subtle")
passwordFile := ctx.String("password-file")

switch {
case isPBES2 && key != "":
Expand Down Expand Up @@ -224,7 +229,17 @@ func encryptAction(ctx *cli.Context) error {
case jwks != "":
jwk, err = jose.ReadKeySet(jwks, options...)
case isPBES2:
pbes2Key, err = ui.PromptPassword("Please enter the password to encrypt the content encryption key")
var password string
if passwordFile != "" {
password, err = utils.ReadStringPasswordFromFile(passwordFile)
if err != nil {
return err
}
}
pbes2Key, err =
ui.PromptPassword(
"Please enter the password to encrypt the content encryption key",
ui.WithValue(password))
default:
return errs.RequiredOrFlag(ctx, "key", "jwks")
}
Expand Down

0 comments on commit e781ba8

Please sign in to comment.