Skip to content

Commit

Permalink
Merge pull request #25 from sergio-correia/trim-input
Browse files Browse the repository at this point in the history
fix: trim base64 input before attempting decryption
  • Loading branch information
nullr0ute authored May 2, 2024
2 parents e219f36 + 36afff2 commit ed95396
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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})"

0 comments on commit ed95396

Please sign in to comment.