Skip to content

Commit

Permalink
feat: add: --password-file option for step crypto jwe decrypt
Browse files Browse the repository at this point in the history
The `encryptedKey` generated by `--type=jwk` in `step ca provisioner add` is in PBES2 format.
This is hard-coded and difficult to change.
Therefore, in the implementation before this commit, after the key to decrypt is entered in the standard input, the executor must interactively enter the password specified when generated in the standard input.
The `--key` option and others cannot be used at this time because of formatting problems.
However, trying to do this programmatically is difficult, as the format of `ui.PromptPassword` is too specific for manual execution, or reading stderr output, etc., and trying to add additional standard input passwords in a programmatic and automatic way is very It was very difficult.
Therefore, I added the `--password-file` command line argument to provide an alternative that does not require an interactive operation.
Since there was no problem reading the password file when generating it, I decided that there was no harm in reading the password file when decrypting it, and it was a natural implementation.
  • Loading branch information
ncaq committed Nov 3, 2023
1 parent 75d7a7b commit 822c29b
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 822c29b

Please sign in to comment.