Skip to content

Latest commit

 

History

History
129 lines (86 loc) · 7.71 KB

integration.md

File metadata and controls

129 lines (86 loc) · 7.71 KB

Host Integration Guide

This guide describes the host responsibilities required to turn a VPL trust decision into a safe native-plugin launch. VPL performs trust decisions; the host owns plugin discovery, user interaction, launch planning, path validation, and native loading.

1. Configure one process-wide instance

Configure the registry before any component calls VerifiedPluginLoadRegistry.get():

val config = VerifiedPluginLoadConfig(
    storageDirectory = File(context.filesDir, "verified-plugin-load"),
    trustListUrlPrefixes = mirrorPrefixes,
    trustListJsonSuffix = "trusted-authors.json",
    trustListSignatureSuffix = "trusted-authors.json.sig",
    networkTimeoutMillis = 5_000,
    maxTrustListBytes = 1_048_576
)
val vpl = VerifiedPluginLoadRegistry.configure(context, config)

The registry ensures that early verification and the final load guard use the same storage and configuration. If no instance was configured, get() creates a process-wide instance backed by filesDir/verified-plugin-load with remote updates disabled.

The three remote-update fields are all-or-nothing. Use an empty prefix list with null suffixes when the host should use only the signed local or bundled list.

2. Keep VPL work off the main thread

initialize(), refreshTrustList(), trust mutations, package inspection, and archive inspection may perform file, package-manager, cryptographic, or network work. Run them from a worker thread or the host's task system.

VerifiedPluginLoadBlocking exists for Java hosts without coroutine integration. Its methods block the calling thread until the suspend API returns and must not be called from the Android main thread.

VPL serializes initialization, inspection, refresh, and trust mutations on an internal lock. Hosts may call it from multiple worker threads, but should avoid redundant refreshes.

3. Initialize and refresh

Call initialize() once during process startup. It validates the local user-trust store and selects a signed trust list using this order:

  1. Current local pair.
  2. Previous verified pair.
  3. Signed list bundled with the library.

When a valid current list exists, initialization returns it and schedules a background refresh if mirrors are configured. When recovery selected a previous or bundled list, initialization performs one bounded full-download attempt before returning.

The host may call refreshTrustList() explicitly when its startup architecture needs to await an update attempt. A refresh failure does not erase the last valid signed list. Inspect TrustListRefreshResult and log or expose diagnostics as appropriate.

4. Discover every native plugin candidate

The host must cover every package whose files can affect native loading, including renderers, Vulkan drivers, native environment plugins, FFmpeg providers, or future plugin types. Deduplicate candidates by package name before prompting.

Do not treat an arbitrary filesystem path as a plugin identity. Each external native path must be attributable to an installed package returned by Android's package manager.

5. Inspect and handle the decision

Call inspectInstalledPackage(packageName) for installed plugins or inspectApkFile(file) for an archive that has not been installed.

Status Required host behavior
TRUSTED Create an authorization snapshot and continue the verification sequence.
PENDING_TRUST Show the registered author and certificate details. Offer author trust only when the trust action accepts that author.
UNTRUSTED Block by default. A host may offer explicit trust for a selected current certificate after a clear risk warning.
BANNED Block without a bypass. Display the signed-list reason when available.
VERIFICATION_FAILED Block without a trust prompt. Use diagnostic for a safe error explanation.

Never infer permission from diagnostic; load permission is represented only by status == TRUSTED or isLoadAllowed.

6. Record trust only after explicit confirmation

For a registered author:

val action = vpl.trustAuthor(authorUuid)

For one concrete current certificate:

val action = vpl.trustKeyHash(keyHash.value)

Check TrustActionResult.status. Do not assume the mutation succeeded. In particular, an author can be registered but not eligible for author-level trust, and a banned certificate cannot be trusted directly.

After every successful trust action, inspect the package again. Continue only if the fresh result is TRUSTED; then call toLoadAuthorization() on that fresh result. This binds the launch plan to the package name, APK path, version code, and complete set of current signing certificates observed after confirmation.

7. Verify candidates before all other launch work

Plugin verification should be the first launch stage. Do not download game components, modify the instance, build native environment variables, or start runtime preparation before every required plugin has either produced an authorization or stopped the launch.

Handle candidates sequentially when confirmation UI is needed. This keeps each decision bound to one package and avoids overlapping dialogs.

8. Re-verify at the final native-load boundary

Immediately before using a plugin native directory or loading a library:

  1. Inspect the installed package again.
  2. Require a fresh TRUSTED status.
  3. Reapply any host policy that restricts explicit certificate trust.
  4. Match the fresh package name, canonical APK path, version code, and complete current-certificate set against the stored PluginLoadAuthorization.
  5. Require the selected native directory to match the package manager's nativeLibraryDirectory.
  6. Canonicalize every library path and require it to remain inside that directory.
  7. Prevent user-controlled environment variables from replacing verified native paths or loader inputs.

Reject the launch when any field changed. Do not silently create a new authorization at the final boundary; that would bypass the user's source-bound confirmation.

9. Manage and revoke user trust

getUserTrustSnapshot() returns only user decisions:

  • trustedAuthorUuids: explicitly trusted registered authors.
  • trustedKeyHashes: explicitly trusted certificate fingerprints.
  • updatedAt: the last stored mutation time.
  • recoveredFromCorruption: whether the current file was invalid and recovery was attempted.

Use getTrustedAuthors() to map current author UUIDs to display information. Keep unknown or no-longer-listed UUIDs visible so the user can revoke stale records. Likewise, retain certificate records even when no installed plugin currently uses them.

Revoke records with revokeAuthorTrust() and revokeKeyHashTrust(). NOT_FOUND means the desired end state already holds. Other non-success statuses must be surfaced as failures. Revocation affects future checks; it does not unload native code already running in the process.

Host Review Checklist

  • One process-wide VPL instance is configured before first use.
  • VPL file, package, cryptographic, and network work runs off the main thread.
  • Every external native-plugin package is discovered and checked.
  • Verification is the first launch stage.
  • BANNED and VERIFICATION_FAILED have no bypass.
  • User confirmation names one author or one concrete current certificate.
  • A successful trust mutation is followed by fresh inspection.
  • Every candidate contributes a PluginLoadAuthorization to the launch plan.
  • The final native-load point re-inspects and compares the complete authorization.
  • Native directories and library paths are canonicalized and package-owned.
  • Custom environment variables cannot override verified native-load inputs.
  • Users can review and revoke manual author and certificate trust.