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

support metadata signature verification using otacerts.zip #33

Closed
wants to merge 3 commits into from

Conversation

inthewaves
Copy link
Member

@inthewaves inthewaves commented Apr 29, 2021

Closes #7

Needs to be looked at with GrapheneOS/script#8

This PR adds metadata signature verification. It also verifies the new added device model
field in the metadata as noted in #7.

For RSA, we sign using RSASSA-PSS as recommended for new applications in PKCS #`1
v2.2 (RFC 8017) [1]. SHA256withRSA/PSS is supported on Android [2].

Test: With a self-hosted server, a GeneralSecurityException is thrown in
Service when the metadata doesn't match with the original contents, and
no GeneralSecurityException when it matches.

Test: The following steps were done successfully with an RSA-2048
release key and then repeated with an RSA-4096 release key and an
ECDSA release key (generated from development/tools/make_key):

  1. Flash latest factory zip and boot the OS and have the
    latest version also on the server
  2. Check for updates on the server (sargo-stable) with a correct
    signature to get the "targetBuildDate: ... not higher than
    sourceBuildDate" message
  3. Edit sargo-stable on the server to something different, and check
    again for updates in the app. The logcat shows
    java.security.GeneralSecurityException: verifier.verify returned false
  4. Repeat steps 2-3 for the beta and testing channels
  5. Upload a newer release with the metadata altered from the correct
    value; the same exception from step 3 shows up
  6. Change metadata to correct value; the update downloads and installs
    correctly.

Test: A previous version of the Updater app was able to download and
verify the new metadata format without issues.

[1] https://tools.ietf.org/html/rfc8017#section-8
[2] https://developer.android.com/reference/java/security/Signature

@inthewaves inthewaves changed the title verify metadata signature using otacerts.zip support metadata signature verification using otacerts.zip Apr 29, 2021
@inthewaves inthewaves force-pushed the metadata-sigs branch 2 times, most recently from a89aa3b to c7138a2 Compare April 29, 2021 16:31
@inthewaves inthewaves force-pushed the metadata-sigs branch 9 times, most recently from 0dfdf95 to 3eceea9 Compare May 1, 2021 20:20
inthewaves added 2 commits May 2, 2021 21:47
We sign using RSASSA-PSS as recommended for new applications in PKCS # 1
v2.2 (RFC 8017) [1]. SHA256withRSA/PSS is supported on Android [2].

Test: With a self-hosted server, a GeneralSecurityException is thrown in
Service when the metadata doesn't match with the original contents, and
no GeneralSecurityException is thrown when it matches.

Test: The following steps were done successfully with an RSA-2048
release key and then repeated with an RSA-4096 release key:
1. Flash latest factory zip and boot the OS and have the
latest version also on the server
2. Check for updates on the server (sargo-stable) with a correct
signature to get the "targetBuildDate: ... not higher than
sourceBuildDate" message
3. Edit sargo-stable on the server to something different, and check
again for updates in the app. The logcat shows
"java.security.GeneralSecurityException: verifier.verify returned false"
4. Repeat steps 2-3 for the beta and testing channels
5. Upload a newer release with the metadata altered from the correct
value; the same exception from step 3 shows up
6. Change metadata to correct value; the update downloads and installs
correctly.

Test: In Direct Boot mode, the Updater app was able to download
metadata, verify the metadata, download OTA packages, and install
updates.

[1] https://tools.ietf.org/html/rfc8017#section-8
[2] https://developer.android.com/reference/java/security/Signature
The actual GrapheneOS `releasekeys` are RSA keys right now, but for
completeness, this change will accommodate usages of an ECDSA
`releasekey` as generated by `development/tools/make_key`.

Test: Ran through a full update check then download and install cycle
with an EC key, and also tested that editing the metadata without
resigning causes a GeneralSecurityException.
@inthewaves inthewaves force-pushed the metadata-sigs branch 4 times, most recently from 13db00a to 406504e Compare May 3, 2021 21:01
Test: A previous version of the Updater app was able to downloadn and
verify the new metadata format without issues.
@thestinger thestinger force-pushed the 11 branch 7 times, most recently from c73677a to 2db5319 Compare June 27, 2021 23:36
@thestinger thestinger force-pushed the 11 branch 21 times, most recently from 30f62db to b9a0a26 Compare July 25, 2021 01:16
@thestinger thestinger force-pushed the 11 branch 6 times, most recently from 889d87d to 3040c65 Compare August 2, 2021 18:26
@thestinger thestinger deleted the branch GrapheneOS:11 October 26, 2021 12:09
@thestinger thestinger closed this Oct 26, 2021
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.

sign channel metadata to enforce release channel name
2 participants