Skip to content

Commit ed95396

Browse files
authored
Merge pull request #25 from sergio-correia/trim-input
fix: trim base64 input before attempting decryption
2 parents e219f36 + 36afff2 commit ed95396

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
- name: Run integration tests
5757
run: |
5858
TCTI=swtpm: SKIP_CLEVIS=true cargo test -- --nocapture
59+
echo "### Shell integration tests" >&2
60+
TCTI=swtpm: SKIP_CLEVIS=true ./tests/integration-test.sh
5961
- name: Run policy tests
6062
run: |
6163
TCTI=swtpm: ./tests/test_policy

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ struct ClevisInner {
177177
}
178178

179179
fn perform_decrypt(input: Vec<u8>) -> Result<()> {
180-
let input = String::from_utf8(input).context("Error reading input")?;
180+
let input = String::from_utf8(input)
181+
.context("Error reading input")?
182+
.trim()
183+
.to_string();
181184
let hdr = josekit::jwt::decode_header(&input).context("Error decoding header")?;
182185
let hdr_clevis = hdr.claim("clevis").context("Error getting clevis claim")?;
183186
let hdr_clevis: ClevisInner =

tests/integration-test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
die() {
4+
echo "ERROR: ${1}" >&2
5+
exit 1
6+
}
7+
8+
PLAINTEXT=foobar
9+
jwe="$(echo "${PLAINTEXT}" | ./target/debug/clevis-pin-tpm2 encrypt {})"
10+
11+
dec="$(echo "$jwe" | ./target/debug/clevis-pin-tpm2 decrypt)" \
12+
|| die "Unable to decrypt JWE passed with newline added"
13+
14+
[ "${dec}" = "${PLAINTEXT}" ] \
15+
|| die "Decrypted JWE (${dec}) does not match PLAINTEXT (${PLAINTEXT})"

0 commit comments

Comments
 (0)