-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trim base64 input before attempting decryption
As the decryption input is base64-encoded, we can safely trim leading and trailing whitespace from it. If the input has a newline, it will fail validation, e.g: ``` jwe="$(echo "foobar" | clevis-pin-tpm2 encrypt {})" echo "${jwe}" | clevis-pin-tpm2 decrypt Error: Error decrypting JWE Caused by: 0: Invalid JWE format: Invalid byte 10, offset 22. 1: Invalid byte 10, offset 22. ``` Also include additional integration tests written in shell script. Signed-off-by: Sergio Correia <[email protected]>
- Loading branch information
1 parent
e219f36
commit 36afff2
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})" |