Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --password-file to crypto jwe encrypt #1294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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