Skip to content

feat!: adopt c2pa-swift 0.1.0 and c2pa-android 0.1.2 - #5

Closed
redaranj wants to merge 24 commits into
feature/gp-323from
feature/gp-49
Closed

redaranj wants to merge 24 commits into
feature/gp-323from
feature/gp-49

Conversation

@redaranj

@redaranj redaranj commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #4, the mirror copy of guardianproject#6 (GP-323).

This brings c2pa-flutter up to date with c2pa-swift v0.1.0 (c2pa-rs 0.92.0) and c2pa-android 0.1.2 (c2pa-rs 0.92.2). Both are the latest releases, and main on each repo matches its release. #6 moved the plugin to 0.0.9, since when the SDKs have shipped about 40 commits each, many of them breaking.

What changed upstream, and what this does about it

Both SDKs made the same big shift. Global settings are gone, and all configuration now lives on a context. A context can also carry a signer, a progress callback, cancellation, and an HTTP resolver. The plugin is rebuilt around that model.

Contexts

  • C2paContext.create(settings:, signer:, onProgress:, httpResolver:) and context.cancel().
  • Progress arrives as C2paProgress (14 phases plus unknown).
  • NativeHttpResolver uses URLSession on iOS and OkHttp on Android. CallbackHttpResolver routes every SDK request (remote manifests, OCSP, timestamps) through Dart.
  • C2pa.loadSettings still works. The plugin keeps those settings and applies them, through a context, to every reader and builder it creates without one.

Builder

  • sign() without a signer uses the context signer. That includes a signer defined in settings, which is the only way the SDKs accept a settings signer now.
  • New signFile(), which streams both files natively.
  • New setBasePath(), plus ingredient archives: writeIngredientArchive() and addIngredientFromArchive().
  • The new embeddable flow: needsPlaceholder, placeholder, setDataHashExclusions, updateHashFromBytes/File, signEmbeddable, hashType, and BMFF setFixedSizeMerkle/hashMdatBytes.
  • C2pa.composeManifest() replaces formatEmbeddable. createHashedPlaceholder and signHashedEmbeddable are removed, along with the SDK calls they wrapped.

Reader

  • readCrJsonFromFile/Bytes.
  • readFileWithManifest/readBytesWithManifest for sidecar and remote manifests.
  • readFragment for fragmented BMFF (Android only).
  • An optional context on reads.
  • MIME type lists now come from the SDKs.
  • readIngredientFromFile and ReaderOptions.dataDir are removed, because both SDKs removed them.

Signers

  • New CawgIdentitySigner, which wraps Signer.withCawgIdentity and can nest callback signers.

iOS gaps closed

  • createCSR, importKey (EC keys, via CryptoKit) and enrollHardwareKey are implemented. They were NOT_IMPLEMENTED_IOS.
  • The IPTC source types c2pa-swift doesn't model (empty, trainedAlgorithmicData, computationalCapture) are now recorded through an explicit c2pa.created action. Before, they silently fell back to digitalCapture. This was the original GP-49 note.

Where the SDKs differ

The Dart API exposes the union of the two SDKs. Where one side lacks a feature, it fails with a clear NOT_IMPLEMENTED_<PLATFORM> error. The README has the full table:

  • readFragment: Android only.
  • createSelfSignedCertificateChain: iOS only.
  • readWith*Manifest ignores the context on Android, which has no context-aware form.
  • Android needs builder.generate_c2pa_archive for ingredient archives.

Native rewrite

Both plugins are rewritten in place of the old copy-paste handlers. Each platform now has four files: dispatch, support, signer factory, and key management.

  • One serial background worker per plugin runs every SDK call in the order Dart sent it. Callback signers, progress and Dart HTTP resolvers call back to the main thread while the worker waits, so nothing blocks the UI or deadlocks. dispose is queued behind any call still running, which fixes the use-after-free that PR #7 found. contextCancel bypasses the queue so it can reach a running operation.
  • Fixes from PR #7's findings:
    • Android destinations open with WRITE, so an existing file is truncated.
    • Missing source and ingredient files throw instead of being created empty.
    • The missing iOS MIME types are added.
    • Dart ManifestBuilder.signFile is exposed.
  • Other fixes:
    • addIngredientFromFile sent filePath while both native sides read path, so it never worked.
    • Android readFileDetailed/readBytesDetailed ignored detailed.
    • Android action parameters were stringified.
    • A context's callback signer was unregistered after the first call.

Build and CI

  • SwiftPM now points at github.com/contentauth/c2pa-swift 0.1.0; the old c2pa-ios URL redirects, and the package identity changed with it.
  • c2pa-swift declares Swift tools 6.3, so iOS needs Xcode 26.4+. The iOS CI jobs move to macos-26 with latest-stable Xcode and a version floor check.
  • Android adds okhttp and kotlinx-coroutines at compile time. c2pa-android's AAR requires compileSdk 36.
  • CI now runs on every pull request, so stacked PRs get checked. The iOS integration test files run as separate verbose steps.

Tests

  • Unit tests: 296, up from 263.

    • test/sdk_sync_method_channel_test.dart checks argument shapes and the ordering of queued builder configuration. It also covers nested CAWG callback ids, progress and httpResolve dispatch, and that a context's signer callback lives until the context is disposed.
    • test/sdk_sync_api_test.dart covers the facade against the mock.
  • Integration (example/integration_test/sdk_sync_test.dart): 20 tests on a device or emulator. They cover:

    • context signing, both explicit and settings-defined
    • progress and cancel
    • the full placeholder → exclusions → hash → signEmbeddable round trip
    • composeManifest
    • sidecar manifests, and a Dart HTTP resolver serving a remote manifest
    • ingredient archive export and import
    • crJSON
    • CAWG signing
    • signFile over a larger leftover file
    • a missing ingredient file
    • computationalCapture

    All 42 integration tests pass on both Android and iOS. That's the 22 existing plus these 20.

For review

  • CI is fully green on mirror run 45923965581:
    • Analyze, Unit Tests, Build Android, Build iOS (Xcode 26.6 on macos-26) and Publish Check all pass.
    • Integration tests pass on Android (42/42) and iOS (22 existing plus 20 SDK sync).
  • iOS simulator flake: on hosted simulators, flutter test intermittently launches the app and then waits forever at "Waiting for VM Service port to be available...". This is flutter's tool, not the plugin: Update to official c2pa 0.0.9 releases (mirror of #6) #4's own branch and origin main (as PR #7 reported) hit it too. .github/scripts/ios-integration-test.sh detects that stall (the log sitting on that line for 3 minutes), then kills and retries the attempt, up to 3 times. Any other failure is final. Update to official c2pa 0.0.9 releases (mirror of #6) #4 doesn't have this wrapper, so its iOS integration job can still time out on that flake.
  • No Swift toolchain for iOS locally: the Swift sources were type-checked on Linux against stub C2PA/Flutter/Security/CryptoKit modules that copy the exact v0.1.0 signatures. That harness reproduces the Stream ambiguity CI hit before the fix.
  • Commits are unsigned (Darren away overnight). Re-sign before promoting.
  • PR #7 (hm21) can be closed against this. Everything it fixed is covered here, by the serial worker, the stream modes and signFile.

@redaranj
redaranj added this pull request to stack #6 November 26, 2026 22:21
Move both native SDKs to their current releases and rebuild the plugin
around the context-scoped model they now share.

- Dependencies: com.github.contentauth:c2pa-android 0.1.2 (plus okhttp
  and coroutines it needs at compile time) and
  github.com/contentauth/c2pa-swift 0.1.0 (the c2pa-ios URL redirects).
- Both SDKs dropped global settings. loadSettings is now emulated: the
  plugin keeps default settings and builds a context from them for every
  reader and builder created without one.
- Contexts gain a signer, a progress callback, cancellation and an HTTP
  resolver (the platform client or a Dart callback).
- Builders gain context signing, setBasePath, ingredient archives,
  signFile, and the new embeddable flow: needsPlaceholder, placeholder,
  setDataHashExclusions, updateHashFrom*, signEmbeddable, hashType and
  the BMFF setFixedSizeMerkle/hashMdatBytes. composeManifest replaces
  formatEmbeddable; createHashedPlaceholder and signHashedEmbeddable are
  gone with the SDK calls they wrapped.
- Readers gain crJSON, external-manifest reading, fragmented BMFF
  reading (Android only) and SDK-reported MIME types; readIngredientFile
  and the dataDir parameters are removed upstream.
- New CawgIdentitySigner wraps Signer.withCawgIdentity.
- Native calls run in order on one background worker per plugin, so
  callback signers, progress and Dart HTTP resolvers never block the main
  thread and builderDispose cannot free a builder still in use.
- Android opens destinations with WRITE (truncating) and sources with
  createIfNeeded=false; iOS gains createCSR, importKey (EC keys) and
  enrollHardwareKey, and records IPTC source types c2pa-swift lacks via
  an explicit c2pa.created action.
- CI iOS jobs move to macos-26 with Xcode 26.4+, which c2pa-swift needs.
Stacked PRs target another PR's branch rather than main or develop, so the branch filter skipped CI for them entirely.
Method channel tests pin argument shapes, the ordering of queued builder configuration, nested CAWG callback ids, and the native-to-Dart progress, HTTP resolver and context signer callbacks, including that a context's signer callback lives until the context is disposed. Facade tests cover the same APIs against the mock platform.
Rewrite the README for the current API (it still described a SignerInfo API that no longer exists), add the 0.1.0 changelog with its breaking changes, list the remaining Android/iOS differences, and bump the version to 0.1.0.
Foundation's Stream (NSStream) made every type annotation naming the C2PA Stream ambiguous, so the iOS plugin failed to compile. A scoped 'import class C2PA.Stream' prefers the SDK type; qualifying it as C2PA.Stream is not an option because the C2PA enum shadows the module name.

Also fix the signFile truncation test: the fixture JPEG is 415 bytes, so four times its size was smaller than any signed output. It now overwrites a 1 MB leftover file.
Xcode's Swift compiler crashed ('failed to produce diagnostic') on the ternary that built the progress closure. Declare the progress and HTTP resolver closures as explicitly typed locals, and replace a 'try' inside a ternary in readCrJson, which Swift rejects.
The iOS integration job intermittently hangs on hosted runners after the Xcode build without starting a test (also seen on main and on #6's branch here). Running each file as its own step with a verbose log and printing its tail makes the next hang diagnosable instead of a silent 30-minute timeout.

Also discard the unused SecItemDelete result in KeyManagement.importKey.
DartBridge held the FlutterMethodChannel weakly, but nothing else owns the channel created in register, so it was released immediately. Callback signers, progress events and Dart HTTP resolvers then never reached Dart: the iOS integration run showed a context callback signer called 0 times, no progress events, and the remote-manifest resolver failing.
The verbose log of the hung runs ends at 'Waiting for VM Service port to be available...' right after the app launches: flutter never sees the VM service announcement in the simulator log. A wrapper now kills an attempt that stalls there and retries up to three times; any other failure is reported at once.
Killing flutter test makes it print shutdown output after the stalled line, so checking the log tail after the kill never recognised the stall. Watch the log instead: when its last line has been 'Waiting for VM Service port' for three minutes, mark the attempt stalled, kill it and retry.
- Every native failure now arrives as a sealed C2paException:
  manifest not found, cancelled, SDK error, invalid argument,
  unsupported, key error, or platform error.
- Reading an asset without a manifest throws
  C2paManifestNotFoundException, as both native SDKs do. The read
  methods return non-nullable types.
- Builder calls run in call order even when not awaited. setIntent,
  setNoEmbed, setRemoteUrl and addAction now return futures.
- dispose() returns a future on builders, settings and contexts.
  Finalizers release handles that are garbage collected undisposed.
- ManifestStoreInfo reads validation_state, so ValidationStatus gains
  trusted.
- An unknown signature algorithm parses as null instead of es256.
- enrollHardwareKey returns HardwareKeyEnrollment.
- C2paSettings.setValue takes any JSON value.
- Removed readManifestFromFileWithContext. Pass the context through
  ReaderOptions instead.
- Enable strict casts, inference and raw types, plus the
  unawaited_futures, discarded_futures and avoid_dynamic_calls lints.
- iOS builders created without a context, the loadSettings base, and
  SettingsSigner settings now carry the created_assertion_labels that
  c2pa-android's Builder.fromJson applies. The same manifest now
  records the same assertions as created on both platforms.
- createKey makes P-256, P-384 or P-521 software keys for es256, es384
  and es512. Hardware keys require es256. Any other algorithm is an
  invalid argument instead of being silently ignored.
- iOS keychain items are tagged with the alias string, the form
  c2pa-swift's keychain signer, CSR and public-key export look up.
- exportPublicKey on iOS wraps the EC point in a SubjectPublicKeyInfo.
  c2pa-swift's exportPublicKeyPEM returns the bare X9.63 point under a
  PUBLIC KEY label. Android already returns SPKI.
- IngredientInfo.activeManifest carries the ingredient's manifest
  label from the SDK's active_manifest. A manifest field that is not
  a map no longer throws.
- RemoteSigner is immutable and const like the other signers.
- New sdk_parity_test covers:
  - all seven signing algorithms
  - real ES256 callback signatures in raw and DER form
  - BMFF signing and fragmented Merkle hashing
  - embeddable error paths
  - cancellation and disposal while a sign runs
  - HTTP resolver failures
  - key import, export, CSR and keystore signing
  - createKey curves
  - settings through setValue and TOML
  - default created-assertion labels
  - reserve sizes
  - remote signer failure
  - CAWG with a callback claim signer
  - concurrent signs
- reader_test reads a third-party signed JPEG (thumbnail, crJSON,
  embedded state) and expects unsigned assets to throw
  C2paManifestNotFoundException.
- error_handling_test asserts typed exceptions instead of
  "null or throws".
- roundtrip_test checks a real edit-intent chain.
- oom_test runs on Android only, where its helper channel exists.
- Fixtures copied from the c2pa-android test resources: the Adobe CI
  JPEG, video1.mp4 and key pairs for es384, es512, ps256/384/512 and
  ed25519.
- CI runs every integration file on both platforms.
- iOS deleteKey returned early on c2pa-swift's deleteSecureEnclaveKey,
  which reports success even when nothing matched. Keychain keys were
  never deleted. It now deletes by tag, which covers both kinds of
  key.
- ManifestInfo.claimGenerator falls back to claim_generator_info. It
  was null for every v2 claim c2pa-rs 0.92 writes.
- C2paSettings.setValue documents that object values must go through
  updateFromString. c2pa-android rejects them.
c2pa-rs 0.92 rejects a c2pa.created action without a digitalSourceType,
and a manifest whose first action is neither created nor opened. The
integration files that never ran in CI predated both rules.

- Test manifests now declare a source type and use
  claim_generator_info.
- The empty-assertions case now expects the rejection.
- Expectations name the typed exceptions instead of PlatformException.
- The Merkle flow now sets a create intent.
- Settings signers are set through updateFromString.
pigeons/c2pa_api.dart now defines the Dart/native interface, and
Pigeon 27.3.0 (the newest release that supports Dart 3.10) generates
typed bindings for Dart, Kotlin and Swift. Messages are typed: signers
are a sealed hierarchy, and results, HTTP requests, data-hash
exclusions and certificate configs are classes. Algorithm, intent,
read format, resolver mode and hash type are enums. This removes the
stringly typed maps behind earlier argument-name mismatches.

- PigeonC2pa replaces MethodChannelC2pa as the default C2paPlatform.
  It implements the generated C2paFlutterApi for sign, progress and
  resolveHttp callbacks, and maps PlatformException to C2paException.
- Both native plugins implement the generated C2paHostApi. The lanes
  are unchanged: a serial worker for SDK calls, a separate pool for
  key management, and an immediate contextCancel.
- Native errors map to the same codes as before.
- Android and iOS now reject an out-of-range HTTP resolver status.
- CertificateConfig.email reaches iOS certificate generation; the
  old channel sent it under a key iOS never read.
- The channel unit tests become c2pa_pigeon_test, which drives
  PigeonC2pa through a fake host API.
- `make pigeon` regenerates the bindings, and CI fails if they drift
  from the definition.
Divine mobile, the plugin's main consumer, builds with Flutter 3.47.9
(Dart 3.13.7) and requires sdk ^3.13.0. The plugin now requires the
same toolchain, and CI pins Flutter 3.47.9.

- Pigeon moves from 27.3.0 to 30.0.2, the newest release that is at
  least two weeks old. Pigeon 28 changed @async to generate Kotlin
  suspend and Swift async methods. The native plugins run calls on
  their own serial worker and reply through callbacks, so the
  definition now uses @asynccallback, and the generated native
  signatures are unchanged. The Dart FlutterApi.progress now returns
  a Future.
- The bindings are regenerated, and lib/ and test/ are reformatted
  with the Dart 3.13.7 formatter that CI runs; the language-version
  bump changes the tall-style layout.
The Flutter 3.47.9 build restored DerivedData from a 3.38.6 build through
the restore-key prefix, and Xcode rejected its precompiled modules because
the Flutter headers had changed. With the Flutter version in both the key
and the restore-key prefix, a toolchain change starts from an empty cache.
flutter pub get on Flutter 3.47 adds build/, android/ and ios/ to the
example's analyzer excludes. CI left that edit uncommitted, and the
publish dry-run then failed on a modified checked-in file.
…date

- README:
  - the Flutter 3.47 / Dart 3.13 requirement
  - commit pinning
  - a key-management example
  - the trust-anchor condition for a trusted status
  - two more platform differences: hardware keys in the simulator, and
    object values in setValue
  - a development section covering the Pigeon workflow, tests and CI
- The example README replaces the Flutter template with the app's
  screens and a guide to the integration test files.
- CHANGELOG:
  - setValue no longer claims to accept maps
  - lists the C2paPlatform interface changes
  - moves the certificate email fix under Fixed
  - adds the HTTP status check and the const RemoteSigner
- API docs:
  - name c2pa-swift 0.1.0 and c2pa-android 0.1.2 instead of the old
    c2pa-ios / c2pa-android 0.0.9
  - list SettingsSigner and CawgIdentitySigner in the library overview
  - fix the doc references that did not resolve
@redaranj

Copy link
Copy Markdown
Owner Author

Promoted to guardianproject#8

@redaranj redaranj closed this Nov 27, 2026
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