Skip to content

feat: Add tsa_headers to Signer.from_callback - #371

Open
dfradehubs wants to merge 1 commit into
contentauth:mainfrom
dfradehubs:feat/signer-tsa-headers
Open

dfradehubs wants to merge 1 commit into
contentauth:mainfrom
dfradehubs:feat/signer-tsa-headers

Conversation

@dfradehubs

Copy link
Copy Markdown

Changes in this pull request

Adds an optional tsa_headers argument to Signer.from_callback, for time stamp authorities that authenticate clients (usually an API key header, e.g. Trufo's production TSA requires X-API-Key). Without it, a Python signer backed by a remote key (Cloud KMS, HSM) cannot get trusted timestamps without a local proxy that adds the header.

signer = c2pa.Signer.from_callback(
    sign, c2pa.C2paSigningAlg.ES256, certs, "https://tsa.example/",
    tsa_headers={"X-API-Key": api_key},
)
  • Each header goes through the new C API function c2pa_signer_with_tsa_header (feat: Add c2pa_signer_with_tsa_header to send headers with time stamp requests c2pa-rs#3112), which wraps the native signer.
  • The binding is optional. With a native library that does not export the function yet (the current c2pa-v0.92.2), the module imports and everything works as today; only tsa_headers raises a clear C2paError. That way this can be merged before or with the native version bump.
  • If a native call fails, the signer that was not consumed is freed and the error is raised.

Closes #370.

Depends on contentauth/c2pa-rs#3112 for the native function. Once a c2pa-rs release includes it, c2pa-native-version.txt can be bumped (here or in a follow-up).

Tests

  • Without native support: tsa_headers raises C2paError.
  • With a stand-in native function: each header is passed, UTF-8 encoded, in order.
  • On a failed native call: the error is raised and the unconsumed signer is freed exactly once.
  • Native test: skipped unless the loaded library exports the function. I ran it against c2pa_c_ffi built from feat: Add c2pa_signer_with_tsa_header to send headers with time stamp requests c2pa-rs#3112 (C2PA_LIBRARY_NAME): it passes. End to end against a local TSA, the X-API-Key header arrives on every attempt.
  • Full suite: 470 passed, 1 skipped (that native test, with the published library). flake8 clean.

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

Time stamp authorities on the C2PA TSA trust list usually require an API key
header. Signer.from_callback only took a TSA URL, so a signer backed by a
remote key (Cloud KMS, HSM) could not get trusted timestamps without a local
proxy that adds the header.

tsa_headers is applied through the new C API function
c2pa_signer_with_tsa_header (contentauth/c2pa-rs#3112), one call per header.
The binding is optional: with a native library that does not export it yet,
everything else works and tsa_headers raises a clear C2paError. On a failed
call the signer that was not consumed is freed.

Closes contentauth#370

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.

Signer.from_callback: support TSA request headers (API key for trusted TSAs)

1 participant