Removed key line offset bug and changed pin from clevis to zlevis.
This commit is contained in:
parent
03f5c95b33
commit
f573008075
2 changed files with 15 additions and 15 deletions
|
@ -64,36 +64,36 @@ fi
|
||||||
echo "$jhd" > "$tmp"/jhd
|
echo "$jhd" > "$tmp"/jhd
|
||||||
|
|
||||||
# Validate the JWE pin type
|
# Validate the JWE pin type
|
||||||
if [ "$(jose fmt -j- -Og clevis -g pin -u- < "$tmp"/jhd)" != "tpm2" ]; then
|
if [ "$(jose fmt -j- -Og zlevis -g pin -u- < "$tmp"/jhd)" != "tpm2" ]; then
|
||||||
echo "JWE pin mismatch" >&2
|
echo "JWE pin mismatch" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract required parameters from the JWE header
|
# Extract required parameters from the JWE header
|
||||||
if ! hash="$(jose fmt -j- -Og clevis -g tpm2 -g hash -Su- < "$tmp"/jhd)"; then
|
if ! hash="$(jose fmt -j- -Og zlevis -g tpm2 -g hash -Su- < "$tmp"/jhd)"; then
|
||||||
echo "JWE missing required 'hash' header parameter!" >&2
|
echo "JWE missing required 'hash' header parameter!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! key="$(jose fmt -j- -Og clevis -g tpm2 -g key -Su- < "$tmp"/jhd)"; then
|
if ! key="$(jose fmt -j- -Og zlevis -g tpm2 -g key -Su- < "$tmp"/jhd)"; then
|
||||||
echo "JWE missing required 'key' header parameter!" >&2
|
echo "JWE missing required 'key' header parameter!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! jwk_pub="$(jose fmt -j- -Og clevis -g tpm2 -g jwk_pub -Su- < "$tmp"/jhd)"; then
|
if ! jwk_pub="$(jose fmt -j- -Og zlevis -g tpm2 -g jwk_pub -Su- < "$tmp"/jhd)"; then
|
||||||
echo "JWE missing required 'jwk_pub' header parameter!" >&2
|
echo "JWE missing required 'jwk_pub' header parameter!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$jwk_pub" > "$tmp"/jwk_pub
|
echo "$jwk_pub" > "$tmp"/jwk_pub
|
||||||
if ! jwk_priv="$(jose fmt -j- -Og clevis -g tpm2 -g jwk_priv -Su- < "$tmp"/jhd)"; then
|
if ! jwk_priv="$(jose fmt -j- -Og zlevis -g tpm2 -g jwk_priv -Su- < "$tmp"/jhd)"; then
|
||||||
echo "JWE missing required 'jwk_priv' header parameter!" >&2
|
echo "JWE missing required 'jwk_priv' header parameter!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$jwk_priv" > "$tmp"/jwk_priv
|
echo "$jwk_priv" > "$tmp"/jwk_priv
|
||||||
|
|
||||||
# Handle optional PCR parameters
|
# Handle optional PCR parameters
|
||||||
pcr_ids="$(jose fmt -j- -Og clevis -g tpm2 -g pcr_ids -Su- < "$tmp"/jhd)" || true
|
pcr_ids="$(jose fmt -j- -Og zlevis -g tpm2 -g pcr_ids -Su- < "$tmp"/jhd)" || true
|
||||||
pcr_spec=""
|
pcr_spec=""
|
||||||
if [ -n "$pcr_ids" ]; then
|
if [ -n "$pcr_ids" ]; then
|
||||||
pcr_bank="$(jose fmt -j- -Og clevis -g tpm2 -g pcr_bank -Su- < "$tmp"/jhd)"
|
pcr_bank="$(jose fmt -j- -Og zlevis -g tpm2 -g pcr_bank -Su- < "$tmp"/jhd)"
|
||||||
pcr_spec="$pcr_bank:$pcr_ids"
|
pcr_spec="$pcr_bank:$pcr_ids"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -216,22 +216,22 @@ if ! jwk_priv="$(jose b64 enc -I "$tmp"/jwk.priv)"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Construct the JWE (JSON Web Encryption) structure
|
# Construct the JWE (JSON Web Encryption) structure
|
||||||
jwe='{"protected":{"clevis":{"pin":"tpm2","tpm2":{}}}}'
|
jwe='{"protected":{"zlevis":{"pin":"tpm2","tpm2":{}}}}'
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$hash" -s hash -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$hash" -s hash -UUUUo-)"
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$key" -s key -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$key" -s key -UUUUo-)"
|
||||||
|
|
||||||
# Include PCR bank and IDs in the JWE if they are provided
|
# Include PCR bank and IDs in the JWE if they are provided
|
||||||
if [ -n "$pcr_ids" ]; then
|
if [ -n "$pcr_ids" ]; then
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$pcr_bank" -s pcr_bank -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$pcr_bank" -s pcr_bank -UUUUo-)"
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$pcr_ids" -s pcr_ids -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$pcr_ids" -s pcr_ids -UUUUo-)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the Base64 encoded JWK public and private keys to the JWE
|
# Add the Base64 encoded JWK public and private keys to the JWE
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$jwk_pub" -s jwk_pub -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$jwk_pub" -s jwk_pub -UUUUo-)"
|
||||||
jwe="$(jose fmt -j "$jwe" -g protected -g clevis -g tpm2 -q "$jwk_priv" -s jwk_priv -UUUUo-)"
|
jwe="$(jose fmt -j "$jwe" -g protected -g zlevis -g tpm2 -q "$jwk_priv" -s jwk_priv -UUUUo-)"
|
||||||
|
|
||||||
# Output the final JWE
|
# Output the final JWE
|
||||||
(echo "$jwe$jwk"; /bin/cat) | jose jwe enc -i- -k- -I- -c
|
(echo "$jwe$jwk$(/bin/cat)") | jose jwe enc -i- -k- -I- -c
|
||||||
|
|
||||||
# Exit with the status of the last command
|
# Exit with the status of the last command
|
||||||
exit $?
|
exit $?
|
Loading…
Reference in a new issue