Skip to content

jwe encrypt: add --password-file flag for PBES2#1657

Open
tashian wants to merge 1 commit into
masterfrom
jwe-encrypt-password-file
Open

jwe encrypt: add --password-file flag for PBES2#1657
tashian wants to merge 1 commit into
masterfrom
jwe-encrypt-password-file

Conversation

@tashian

@tashian tashian commented Jun 22, 2026

Copy link
Copy Markdown
Member

Problem

step crypto jwe decrypt accepts --password-file, but step crypto jwe encrypt does not. Both commands support the PBES2 password-based key algorithms (PBES2-HS256+A128KW, PBES2-HS384+A192KW, PBES2-HS512+A256KW), where the password is the key material. Because encrypt could only read the password interactively from the TTY, encrypting with a shared password was impossible to automate — even though decrypting already was.

Fix

Mirror the existing decrypt implementation:

  • Add a --password-file flag to jwe encrypt.
  • In the PBES2 branch, read the password from the file via utils.ReadStringPasswordFromFile and seed the prompt with ui.WithValue(...). When the flag is omitted, behavior is unchanged (interactive prompt).
  • Advertise the flag in the command UsageText.

This parallels command/crypto/jwe/decrypt.go exactly. No tests were added because the jwe command package has no existing unit or integration tests to parallel.

Testing

Manual round-trip, fully non-interactive:

$ printf 'hunter2' > pw.txt
$ echo "The message" | step crypto jwe encrypt --alg PBES2-HS256+A128KW --password-file pw.txt > msg.json
$ step crypto jwe decrypt --password-file pw.txt < msg.json
The message

go build ./... and go vet ./command/crypto/jwe/ pass.

🤖 Generated with Claude Code

step crypto jwe decrypt already accepts --password-file, but the matching
encrypt command did not, so encrypting with a PBES2 (password-based) algorithm
could only read the password interactively from the TTY. This made automation
impossible.

Mirror decrypt: add the --password-file flag and seed the password prompt from
the file via ui.WithValue when it is set, falling back to the interactive
prompt otherwise.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the needs triage Waiting for discussion / prioritization by team label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs triage Waiting for discussion / prioritization by team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants