Skip to content

gmscompat: add scoped recoverable keystore permission + recovery keystore cleanup on GmsCore data clears - #428

Open
inthewaves wants to merge 8 commits into
GrapheneOS:17from
inthewaves:gms-recoverykeystore
Open

gmscompat: add scoped recoverable keystore permission + recovery keystore cleanup on GmsCore data clears#428
inthewaves wants to merge 8 commits into
GrapheneOS:17from
inthewaves:gms-recoverykeystore

Conversation

@inthewaves

Copy link
Copy Markdown
Member

No description provided.

Let the GmsCompat package flag grant RECOVER_KEYSTORE_GMSCORE to Play services and accept it only
for the account keychain RecoveryController methods used for setup, sync, generated keys, status,
snapshots and restore sessions.

We keep remaining functions like direct raw key import and remote lockscreen validation behind the
existing privileged permissions.
RecoverableKeyStore identifies recovery agent state by Android user ID and recovery agent UID. It
removes that state when an Android user is removed, but has no equivalent cleanup for app data
removal. On the stock OS, Package Manager restores GmsCore's saved app ID when updates are
uninstalled, so it normally keeps the same UID. On GrapheneOS, sandboxed GmsCore can be fully
uninstalled; a later installation is a fresh install and may receive a new UID. Also, clearing its
storage keeps the UID but discards the app state associated with its recoverable keystore entries.

After successful app data removal for GmsCore installed as a user app, remove its database rows,
snapshot, listener and pending snapshot state, recovery sessions and application keys. Preserve
system apps and DELETE_KEEP_DATA flows such as package replacement and archiving.

Delete agent-owned rows by user ID and UID using each table's schema contract and one transaction.
Enumerate the internal alias prefix so restored application keys without database rows are included,
and serialize cleanup with pending key sync work. Keep the per-user platform keys because they are
shared by all recovery agents for the user.
Verify LockSettings serializes cleanup with key sync work and removes sessions, listeners,
snapshots, internal Android Keystore aliases and only the matching recovery agent database rows.

Keep regression coverage for the existing removed Android user cleanup path, including its
database-backed key enumeration and user-wide database removal.

Test: atest FrameworksServicesTests:ApplicationKeyStorageTest
Test: atest FrameworksServicesTests:RecoverableKeyStoreManagerTest
Test: atest FrameworksServicesTests:RecoverySnapshotListenersStorageTest
Test: atest FrameworksServicesTests:CleanupManagerTest
Test: atest FrameworksServicesTests:RecoverableKeyStoreDbTest
… Find Hub

When RECOVER_KEYSTORE_GMSCORE is not granted, ask GmsCompat to show a notification linking to
its recovery keystore permission screen.

Require a visible com.google AccountManager account before notifying during passkey use. The same
FIDO activities are used during initial Google account sign-in, before Play services has an
account whose account keychain could use the permission. If the account query fails, skip the
optional notification.
Derive the LSKF hash immediately before it is used to protect the recovery key and zeroize it
afterward instead of retaining it while recoverable keys are loaded and encrypted.

Destroy secrets when an explicitly closed recovery session is removed. Zeroization clears only
the current movable array and cannot erase copies made by the runtime. Trailing underscores mark
owned locals that must not be used after zeroization.

After key sync enters the cryptographic path, run best effort garbage collection once the task
releases its credential to shorten retention of unreachable Java objects and associated native
contexts. This does not guarantee that stale heap copies or native temporary data are overwritten.

Test: atest FrameworksServicesTests:KeySyncTaskTest
Test: atest FrameworksServicesTests:RecoverySessionStorageTest
Allow GmsCompat to inform users if Bluetooth auto-off is on, since it might affect Find Hub
functionality that they might want.
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