Skip to content

Commit e781ba8

Browse files
committed
Add --password-file to crypto jwe encrypt
Matches the already existing flag for `crypto jwe decrypt`. While here fix usage string for the existing flag since it deals with decryption.
1 parent b436480 commit e781ba8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

command/crypto/jwe/decrypt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ one of the JWKs in the JWK Set.`,
5050
},
5151
cli.StringFlag{
5252
Name: "password-file",
53-
Usage: `The path to the <file> containing the password to encrypt the keys.`,
53+
Usage: `The path to the <file> containing the password to decrypt the keys.`,
5454
},
5555
},
5656
}

command/crypto/jwe/encrypt.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ parameter is ignored by JWE implementations, but may be processed by
151151
applications that use JWE.`,
152152
},
153153
flags.SubtleHidden,
154+
cli.StringFlag{
155+
Name: "password-file",
156+
Usage: `The path to the <file> containing the password to encrypt the keys.`,
157+
},
154158
},
155159
}
156160
}
@@ -188,6 +192,7 @@ func encryptAction(ctx *cli.Context) error {
188192
typ := ctx.String("typ")
189193
cty := ctx.String("cty")
190194
isSubtle := ctx.Bool("subtle")
195+
passwordFile := ctx.String("password-file")
191196

192197
switch {
193198
case isPBES2 && key != "":
@@ -224,7 +229,17 @@ func encryptAction(ctx *cli.Context) error {
224229
case jwks != "":
225230
jwk, err = jose.ReadKeySet(jwks, options...)
226231
case isPBES2:
227-
pbes2Key, err = ui.PromptPassword("Please enter the password to encrypt the content encryption key")
232+
var password string
233+
if passwordFile != "" {
234+
password, err = utils.ReadStringPasswordFromFile(passwordFile)
235+
if err != nil {
236+
return err
237+
}
238+
}
239+
pbes2Key, err =
240+
ui.PromptPassword(
241+
"Please enter the password to encrypt the content encryption key",
242+
ui.WithValue(password))
228243
default:
229244
return errs.RequiredOrFlag(ctx, "key", "jwks")
230245
}

0 commit comments

Comments
 (0)