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

Add decode_payload script to extract and verify update payloads #23

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

pothos
Copy link
Member

@pothos pothos commented Jun 15, 2023

For payloads created with the delta_generator we have no tool to decode them again.
Add a standalone bash script that relies on protoc to decode the update payloads, extract the payload and optionally the secondary kernel payload, and verify the signature.

How to use

./decode_payload ~/kinvolk/coreos-overlay/coreos-base/coreos-au-key/files/official-v2.pub.pem /var/tmp/flatcar_production_update.gz /var/tmp/flatcar_production_update.bin-decoded
./decode_payload ~/kinvolk/coreos-overlay/coreos-base/coreos-au-key/files/developer-v1.pub.pem /var/tmp/flatcar_test_update-oem-azure.gz /var/tmp/oem-azure.raw-decoded

Testing done

For prod:
Used https://update.release.flatcar-linux.net/amd64-usr/3510.2.2/flatcar_production_update.gz and compared to https://stable.release.flatcar-linux.net/amd64-usr/3510.2.2/flatcar_production_update.bin.bz2

For dev:
Also used Stable but the flatcar_test_update.gz

Sysext case for dev (from bincache):
Used flatcar_test_update-oem-azure.gz and compared to oem-azure.raw
The prod case wasn't tested!

@pothos pothos requested a review from a team June 15, 2023 20:44
decode_payload Outdated Show resolved Hide resolved
decode_payload Outdated Show resolved Hide resolved
@pothos
Copy link
Member Author

pothos commented Jun 16, 2023

The format is documented in https://github.com/flatcar/update_engine/blob/flatcar-master/src/update_engine/update_metadata.proto but I will add more comments about how offsets are calculated and the parsing of the output.

"data:"*)
SIGDATA=$(echo "${LINE}" | cut -d '"' -f 2- | head -c-2 | sed 's/%/%%/g')
# This is a workaround for the dev-key vs prod-key case: sed '/signatures {/d' | sed '/ version: 2/d'
SIGHEX=$(printf -- "${SIGDATA}" | sed '/signatures {/d' | sed '/ version: 2/d' | openssl rsautl -verify -pubin -inkey "${PUBKEY}" -raw | tail -c 32 | od -An -vtx1 -w1024 | tr -d ' ')
Copy link
Contributor

@tormath1 tormath1 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openssl rsautl is deprecated from OpenSSL 3.x (https://www.openssl.org/docs/man3.0/man1/openssl-rsautl.html):

This command has been deprecated. The openssl-pkeyutl(1) command should be used instead.

What about something like this:

Suggested change
SIGHEX=$(printf -- "${SIGDATA}" | sed '/signatures {/d' | sed '/ version: 2/d' | openssl rsautl -verify -pubin -inkey "${PUBKEY}" -raw | tail -c 32 | od -An -vtx1 -w1024 | tr -d ' ')
SIGHEX=$(printf -- "${SIGDATA}" | sed '/signatures {/d' | sed '/ version: 2/d' | openssl pkeyutl -pkeyopt digest:sha256 -pkeyopt rsa_padding_mode:pkcs1 -verify -pubin -inkey "${PUBKEY}" | tail -c 32 | od -An -vtx1 -w1024 | tr -d ' ')

(not tested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hoped there was an easier way to get the hash but so far I couldn't find it.

decode_payload Show resolved Hide resolved
Comment on lines +116 to +133
# This is a workaround for the dev-key vs prod-key case: sed '/signatures {/d' | sed '/ version: 2/d'
SIGHEX=$(printf -- "${SIGDATA}" | sed '/signatures {/d' | sed '/ version: 2/d' | openssl rsautl -verify -pubin -inkey "${PUBKEY}" -raw | tail -c 32 | od -An -vtx1 -w1024 | tr -d ' ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's signatures { then won't the closing } mess anything up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very strange, I don't know why this even appears for the dev-key case

For payloads created with the delta_generator we have no tool to decode
them again.
Add a standalone bash script that relies on protoc to decode the update
payloads, extract the payload and optionally the secondary kernel
payload, and verify the signature.
@pothos
Copy link
Member Author

pothos commented Jun 22, 2023

I'll merge now, it's mainly for validation and testing, not used in the Flatcar image.

@pothos pothos merged commit 48894a9 into flatcar-master Jun 22, 2023
@pothos pothos deleted the kai/decode-helper branch June 22, 2023 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants