Skip to content

Commit

Permalink
Merge pull request #1060 from ncaq/add-password-file-for-step-crypto-…
Browse files Browse the repository at this point in the history
…jwe-decrypt

feat: add: --password-file option for step crypto jwe decrypt
  • Loading branch information
maraino authored Nov 28, 2023
2 parents 5d33840 + 822c29b commit 8865323
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion command/crypto/jwe/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ used with **--key** the <kid> value must match the **"kid"** member of the JWK.
used with **--jwks** (a JWK Set) the KID value must match the **"kid"** member of
one of the JWKs in the JWK Set.`,
},
cli.StringFlag{
Name: "password-file",

Check failure on line 51 in command/crypto/jwe/decrypt.go

View workflow job for this annotation

GitHub Actions / ci / lint / lint

File is not `goimports`-ed (goimports)
Usage: `The path to the <file> containing the password to encrypt the keys.`,
},
},
}
}
Expand All @@ -64,6 +68,7 @@ func decryptAction(ctx *cli.Context) error {
key := ctx.String("key")
jwks := ctx.String("jwks")
kid := ctx.String("kid")
passwordFile := ctx.String("password-file")

obj, err := jose.ParseEncrypted(string(data))
if err != nil {
Expand Down Expand Up @@ -107,7 +112,17 @@ func decryptAction(ctx *cli.Context) error {
case jwks != "":
jwk, err = jose.ReadKeySet(jwks, options...)
case isPBES2:
pbes2Key, err = ui.PromptPassword("Please enter the password to decrypt the content encryption key")
var password string
if len(passwordFile) > 0 {
password, err = utils.ReadStringPasswordFromFile(passwordFile)
if err != nil {
return err
}
}
pbes2Key, err =
ui.PromptPassword(
"Please enter the password to decrypt the content encryption key",
ui.WithValue(password))
default:
return errs.RequiredOrFlag(ctx, "key", "jwk")
}
Expand Down

0 comments on commit 8865323

Please sign in to comment.