Skip to content

[encryption] fix MGF1 digest for Keystore-backed keys - #453

Open
capcom6 wants to merge 2 commits into
masterfrom
encryption/mgf1-digest-fix
Open

capcom6 wants to merge 2 commits into
masterfrom
encryption/mgf1-digest-fix

Conversation

@capcom6

@capcom6 capcom6 commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge based on the current changes and resolved review threads.

Summary

The PR uses MGF1-SHA-1 with RSA-OAEP-SHA-256 for Android Keystore-backed keys and adds instrumented coverage across three Android API levels. There are no changes since the previous review and no new findings.

Reviews (9) · Last reviewed commit: "[ci] add instrumented tests for encrypti..." · Reviewed by Greptile

Comment thread .github/workflows/instrumented-tests.yml Outdated
Comment thread .github/workflows/instrumented-tests.yml Outdated
Comment thread .github/workflows/instrumented-tests.yml Outdated
Comment thread .github/workflows/instrumented-tests.yml
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Pull request artifacts

file commit
app-release.apk 7d31764
app-release.aab 7d31764
app-insecure.apk 7d31764
app-insecure.aab 7d31764

@capcom6
capcom6 force-pushed the encryption/mgf1-digest-fix branch 2 times, most recently from 4304489 to 91bd260 Compare October 7, 2026 10:45
Comment thread CHANGELOG.md
@capcom6
capcom6 force-pushed the encryption/mgf1-digest-fix branch from 91bd260 to 14ea3f4 Compare October 12, 2026 01:30
Comment thread .github/workflows/instrumented-tests.yml Outdated
Comment thread .github/workflows/instrumented-tests.yml Outdated
Device-paired E2E could not decrypt on any Android version. The OAEP
parameters requested MGF1-SHA-256, but Android Keystore authorises only
SHA-1 for MGF1 unless the key is created with setMgf1Digests, which is
API 35+ and unavailable to this module (compileSdk 33). Every decrypt
attempt failed:

- below API 35: InvalidAlgorithmParameterException: Unsupported MGF1
  digest: SHA-256. Only SHA-1 supported
- API 35 and newer: KeyStoreException: INCOMPATIBLE_MGF_DIGEST

Pin MGF1 to SHA-1 on both encrypt and decrypt and hoist the digests into
named constants so the two paths cannot drift. The OAEP digest stays
SHA-256.

Verified with RSAEncryptionProviderTest on API 25, 30 and 36 (2/2 each);
all three failed before this change.
No workflow ran connectedAndroidTest - build-apk.yml only runs
`./gradlew test` - so RSAEncryptionProviderTest never executed in CI.
That is how the MGF1 regression shipped in v1.77.0: the round-trip test
that would have caught it passes on a developer machine only because
nothing automated it.

Run the suite on API 25, 30 and 35. Those levels cover the pre-M
KeyPairGeneratorSpec branch, the Keystore1 provider, and the first level
where Keystore2 enforces the MGF1 digest against the key's authorised
set.
@capcom6
capcom6 force-pushed the encryption/mgf1-digest-fix branch from f3cc5ae to 7d31764 Compare October 15, 2026 01:25

This branch has not been deployed

No deployments
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.

1 participant