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

fix: trim base64 input before attempting decryption #25

Merged
merged 1 commit into from
May 2, 2024
Merged
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: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
- name: Run integration tests
run: |
TCTI=swtpm: SKIP_CLEVIS=true cargo test -- --nocapture
echo "### Shell integration tests" >&2
TCTI=swtpm: SKIP_CLEVIS=true ./tests/integration-test.sh
- name: Run policy tests
run: |
TCTI=swtpm: ./tests/test_policy
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ struct ClevisInner {
}

fn perform_decrypt(input: Vec<u8>) -> Result<()> {
let input = String::from_utf8(input).context("Error reading input")?;
let input = String::from_utf8(input)
.context("Error reading input")?
.trim()
.to_string();
let hdr = josekit::jwt::decode_header(&input).context("Error decoding header")?;
let hdr_clevis = hdr.claim("clevis").context("Error getting clevis claim")?;
let hdr_clevis: ClevisInner =
Expand Down
15 changes: 15 additions & 0 deletions tests/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

die() {
echo "ERROR: ${1}" >&2
exit 1
}

PLAINTEXT=foobar
jwe="$(echo "${PLAINTEXT}" | ./target/debug/clevis-pin-tpm2 encrypt {})"

dec="$(echo "$jwe" | ./target/debug/clevis-pin-tpm2 decrypt)" \
|| die "Unable to decrypt JWE passed with newline added"

[ "${dec}" = "${PLAINTEXT}" ] \
|| die "Decrypted JWE (${dec}) does not match PLAINTEXT (${PLAINTEXT})"