Prove where an image came from (C2PA / Stage P)¶
Attach "provenance" that follows the C2PA standard [1] to an image taken with a camera, and sign it electronically. Next, make a blurred Tier 2 image. The Tier 2 image keeps its link to the original but does not contain the camera ID or the unblurred image. You will see this by running the programs.
What you'll do: sign a captured image with provenance. See that the provenance of the Tier 2 blurred image no longer carries information that points to a person, and that tampering is detected
Prerequisites: Python 3.10 or later. The publisher, the blockchain, and the phone wallet are not used
Keep running: nothing needs to be running. Only Python programs are used
What you need: a PC (a USB webcam or built-in camera is optional)
Time required: approx. 30–40 minutes
Where this page belongs
- This is the fourth page of 2.5 in Part 2 (Hands-on).
- This hands-on runs P0 (the first step) of the C2PA provenance pipeline — provenance for camera footage and sensor data (Stage P design spec) on your own machine.
- The C2PA mechanism and terms are explained in §2 "C2PA basics" of the design spec. The idea of Tiers 1–3 was covered in Tier the response by trust (DataUserVC / Stage T).
- Previous page: Tier by semantic level (VLM and semantic representation / Stage T)
- Next page: Connect provenance to the publisher and the chain (C2PA / Stage P, P1 and P2). It builds this into the publisher (P1 and P2).
Goal¶
Sharing surveillance-camera images as crime leads or disaster information requires being able to answer "is this image real?". In this hands-on, you attach provenance (a manifest) describing "who took it, when, how, and how it was processed" to an image and sign it. The recipient can validate that provenance and judge for themselves whether the image is genuine. The page also covers a second problem: the provenance itself can leak information that points to a person, and how to prevent that.
What this page covers¶
- How to attach provenance to an image, sign it, and validate it
- The difference between the validation results
ValidandTrusted - That the provenance of a blurred image, by default, carries a thumbnail of the original and the camera ID, and how to remove them (redaction)
- That changing even one byte of the image is caught by validation
Common pitfalls¶
Validmeans "the signature and hashes are correct"; it says nothing about whether the signer can be trusted. Only after you register a trusted certificate authority (CA) does the result becomeTrusted- The certificate and key made in this hands-on are for local experiments only. They cannot be used in production, and other people's validators show them as an "untrusted signer"
- A webcam may return black frames right after it opens. The program waits up to about 3 seconds for a bright frame
- Captured images and keys are saved under
out/andcerts/. Both are ignored by git, so they cannot be committed by mistake
Required environment¶
- You have the course repository
~/program/Blockchain_IoT_Marketplace(Environment Setup) - Python 3.10 or later is available
- To capture with a webcam (§6), the PC can use the camera. On macOS, allow camera access for the terminal app you use (System Settings → Privacy & Security → Camera)
Exercise programs¶
- Certificate program (make_test_certs.py)
- Signing and validation program (p0_sign_verify.py)
- Exercise guide (README)
p0_sign_verify.py signs a captured image, makes a Tier 2 blurred image, validates both in one run, and prints the result of 11 checks as PASS / FAIL.
Shortest path¶
These 4 steps are enough at first.
- Create a virtual environment (venv) and install the C2PA SDK (§1)
- Create the test certificate (§2)
- Run signing and validation once with the image the program draws, and see
all checks passed(§3) - Print the provenance and see with your own eyes that the camera ID is gone from the Tier 2 image (§4)
Next branches:
- To try by hand that tampering is detected: go to §5
- To try with a real camera image: go to §6
1. Setup¶
At the top of the course repository, create a virtual environment and install the Python version of the C2PA SDK (Software Development Kit, a library used from programs; c2pa-python [2]), Pillow for images, and cryptography for keys.
cd ~/program/Blockchain_IoT_Marketplace
python3 -m venv .venv
source .venv/bin/activate
python -m pip install c2pa-python pillow cryptography
If .venv already exists, run only python -m pip install ... after source .venv/bin/activate. A .venv created with uv or a similar tool may print No module named pip; in that case, run python -m ensurepip and try again, as described in "Troubleshooting". In a newly opened terminal, before the commands from §2 on, move to the top of the course repository and then activate the virtual environment. The commands from §2 on name files with paths relative to the top of the course repository.
cd ~/program/Blockchain_IoT_Marketplace
source .venv/bin/activate
We write python -m pip install instead of pip install because, depending on how the virtual environment was created, it may have no pip command, and another pip already on the PC gets called instead. python -m pip always installs into the virtual environment's Python.
Check whether it is installed.
python -c "import c2pa; print(c2pa.sdk_version())"
Success if a version number such as 0.91.3 is printed (the number depends on when you install).
2. Create the test certificate¶
A C2PA signature requires a certificate issued by a certificate authority (CA). In production you get a certificate from a CA approved by C2PA, but in this hands-on you create your own CA and use it to issue a certificate for the gateway (the device that signs next to the camera).
python examples/hands_on/c2pa_provenance/make_test_certs.py
It prints the following (the path depends on your environment).
wrote .../examples/hands_on/c2pa_provenance/certs/ca.pem, chain.pem, gw.key (CN=iw3ip-gateway), publisher_chain.pem, publisher.key (CN=iw3ip-publisher)
The three files this page uses are:
| File | Content | Role |
|---|---|---|
ca.pem |
Certificate of your own CA | The validator registers it as "I trust this CA" |
chain.pem |
Gateway certificate and CA certificate | Embedded in the image with the signature to show who signed |
gw.key |
Gateway private key | Used for signing. Never give it to anyone |
publisher_chain.pem and publisher.key are the publisher's certificate (CN iw3ip-publisher) and private key, issued by the same CA. This page does not use them; on Connect provenance to the publisher and the chain (C2PA / Stage P, P1 and P2), the publisher uses them to sign the Tier 2 image. On this page, the Tier 2 image is also signed with the gateway key.
The following diagram shows how the certificates and the signature relate. If the validator registers ca.pem as a trusted CA, a signature made with a certificate that CA issued becomes Trusted. If not, a correct signature only reaches Valid.
flowchart LR
CA["Your own CA<br>(ca.pem)"] -->|"issues"| GW["Gateway certificate<br>(chain.pem, key gw.key)"]
CA -->|"issues"| PB["Publisher certificate<br>(used on the next page)"]
GW -->|"signs"| IMG["Provenance of capture.jpg"]
V["Validator"] -->|"registers as a trusted CA"| CA
V -->|"validates"| IMG
The certificate name (CN) is iw3ip-gateway and does not contain the camera ID (cam01), because the certificate name cannot be redacted even from the blurred image made later (§4).
3. Run signing and validation once¶
Run everything once with a park scene the program draws (a person and a plastic bottle).
python examples/hands_on/c2pa_provenance/p0_sign_verify.py
On success it prints the following. The version numbers on the first line depend on your environment (you may see, for example, c2pa-python 0.38.2 / c2pa-rs 0.91.6).
c2pa-python 0.38.1 / c2pa-rs 0.91.3
[PASS] capture without trust anchor is Valid + untrusted (Valid)
[PASS] capture with test CA is Trusted (Trusted)
[PASS] custom assertions are in the capture manifest (c2pa.actions.v2, jp.ertl.iw3ip.capture, jp.ertl.iw3ip.sensor)
[PASS] Tier 2 derivative is Trusted (Trusted)
[PASS] capture/sensor assertions are redacted (leaked=[])
[PASS] no unblurred thumbnail via the ingredient
[PASS] capture manifest thumbnail is redacted
[PASS] capture title has no camera ID (capture.jpg)
[PASS] signer certificate name has no camera ID (iw3ip-gateway)
[PASS] camera ID appears nowhere in the Tier 2 bytes (0 hit(s))
[PASS] one flipped byte makes the derivative Invalid (Invalid)
outputs: .../out/capture.jpg, .../out/tier2.jpg
all checks passed
The program works as shown in the following diagram.
flowchart LR
IMG["Image\n(dummy / file / camera)"] --> SIGN["Attach provenance and sign\ncapture.jpg"]
SIGN --> V1["Validate\nValid / Trusted"]
SIGN --> BLUR["Blur and redact part of the provenance\ntier2.jpg"]
BLUR --> V2["Check for leaks and validate"]
V2 --> TAMP["Change one byte and validate\nInvalid"]
At each step in the diagram, the program does the following:
- Sign the captured image: attach provenance stating that it was captured (
c2pa.actions), the camera ID and capture time (jp.ertl.iw3ip.capture), and sensor readings (jp.ertl.iw3ip.sensor), sign it with the gateway key, and save it asout/capture.jpg - Validate: without registering the CA, the result is
Valid(the signature is correct, but whether to trust the signer is unknown); withca.pemregistered, it isTrusted(checks 1–2). It also checks that the custom assertions (jp.ertl.iw3ip.captureandjp.ertl.iw3ip.sensor) are in the provenance (check 3) - Make the Tier 2 blurred image: blur the whole image, attach provenance that references the original as an "ingredient", and save it as
out/tier2.jpg. At this point, the thumbnail, camera ID, and sensor readings are redacted from the original's provenance - Check for leaks: check whether the Tier 2 image validates as
Trusted(check 4). Next, check that the thumbnail of the original, the camera ID, and the sensor readings are not left in the provenance of the Tier 2 image (checks 5–10) - Try tampering: change one byte of the Tier 2 image, validate it, and check whether it becomes
Invalid(check 11)
The two saved images look like this (left: the captured image; right: the blurred Tier 2 image). The right one only looks blurred, but it contains part of the left image's provenance. §4 prints what is inside.

About the blur
The program in this hands-on blurs the whole image without detecting faces. Blurring only faces was covered by the face blur in Tier by semantic level (VLM and semantic representation / Stage T).
4. Look inside the provenance¶
Now look at the provenance with your own eyes. The following command reads the provenance of both images and prints the manifests and assertions they contain.
python - <<'EOF'
import json
import c2pa
for name in ["capture", "tier2"]:
path = f"examples/hands_on/c2pa_provenance/out/{name}.jpg"
store = json.loads(c2pa.Reader(path).json())
print(f"=== {name}.jpg")
for label, m in store["manifests"].items():
mark = "(this file)" if label == store["active_manifest"] else "(ingredient)"
print(" ", mark, "title:", m.get("title"), "| signer:", m["signature_info"].get("common_name"))
print(" assertions:", [a["label"] for a in m["assertions"]])
for a in m["assertions"]:
if a["label"] == "jp.ertl.iw3ip.capture":
print(" camera:", a["data"])
EOF
It prints the following ((this file) and (ingredient) may appear in either order).
=== capture.jpg
(this file) title: capture.jpg | signer: iw3ip-gateway
assertions: ['c2pa.actions.v2', 'jp.ertl.iw3ip.capture', 'jp.ertl.iw3ip.sensor']
camera: {'camera_id': 'cam01', 'captured_at': '...', 'gateway_did': 'did:jwk:<gateway>'}
=== tier2.jpg
(ingredient) title: capture.jpg | signer: iw3ip-gateway
assertions: ['c2pa.actions.v2']
(this file) title: tier2.jpg | signer: iw3ip-gateway
assertions: ['c2pa.actions.v2', 'jp.ertl.iw3ip.derivation']
Look at three things:
- The provenance of
capture.jpgcontains the camera ID (cam01) and the capture time tier2.jpgcontains the original's provenance as(ingredient), which shows that "this image was made from the original"- However, only
c2pa.actions.v2(the record that it was captured) remains in(ingredient); the camera ID and sensor readings were redacted. Even so,tier2.jpgstill validates asTrusted
The signature survives redaction because the original's signature covers the hashes of its assertions. What is signed is the "claim", a list of those hashes. Removing an assertion's content changes neither the claim nor its signature (see the diagram). See §5.3 of the design spec for details.
flowchart LR
SIG["Signature of the capture<br>(iw3ip-gateway)"] -->|"signs"| CL["Claim<br>hashes of each assertion<br>and of the pixel data"]
CL -.->|"hash"| A1["c2pa.actions<br>(kept)"]
CL -.->|"hash"| A2["jp.ertl.iw3ip.capture<br>(content redacted)"]
CL -.->|"hash"| A3["jp.ertl.iw3ip.sensor<br>(content redacted)"]
classDef removed fill:#fde2e2,stroke:#c0392b,color:#7b241c
class A2,A3 removed
The title and signer of (ingredient) cannot be redacted and remain. That is why the captured image's title (capture.jpg) and the certificate name (iw3ip-gateway) do not contain the camera ID.
5. Try tampering¶
Try by hand what check 11 of §3 did. Make tampered.jpg by changing one byte of the pixel data of tier2.jpg, and validate it next to the original.
python - <<'EOF'
import c2pa
out = "examples/hands_on/c2pa_provenance/out/"
data = bytearray(open(out + "tier2.jpg", "rb").read())
data[-10] ^= 0xFF
open(out + "tampered.jpg", "wb").write(data)
for name in ["tier2.jpg", "tampered.jpg"]:
reader = c2pa.Reader(out + name)
codes = [s["code"] for s in reader.get_validation_results()["activeManifest"]["failure"]]
print(name, reader.get_validation_state(), codes)
EOF
It prints:
tier2.jpg Valid ['signingCredential.untrusted']
tampered.jpg Invalid ['signingCredential.untrusted', 'assertion.dataHash.mismatch']
This command validates without registering the CA, so even the original is Valid (signingCredential.untrusted) rather than Trusted. The tampered image additionally shows assertion.dataHash.mismatch (the pixel-data hash does not match) and becomes Invalid.
A one-byte difference that the eye cannot see is still caught by validating the provenance.
6. Capture with a webcam¶
Run the same checks with a real camera image. Install OpenCV as well, then run with --webcam.
python -m pip install "opencv-python<5"
python examples/hands_on/c2pa_provenance/p0_sign_verify.py --webcam
Success if, as in §3, all 11 checks are PASS and all checks passed is printed. Open the captured image and the blurred image to look at them (on macOS).
open examples/hands_on/c2pa_provenance/out/capture.jpg examples/hands_on/c2pa_provenance/out/tier2.jpg
To use an image file of your own, pass --image <file path> instead of --webcam (JPEG or PNG).
Success criteria¶
- In §3, all 11 checks are
PASSandall checks passedis printed - In §4,
jp.ertl.iw3ip.captureis absent from the(ingredient)oftier2.jpg - In §5,
tampered.jpgisInvalid
What this hands-on cannot show¶
What C2PA guarantees is "this signer signed this content", not "what the image shows is true". In this hands-on, the camera and the gateway (the signing program) are on the same PC. With a real surveillance camera, if the footage is swapped between the camera and the gateway, C2PA cannot detect it. See §4 "Trust boundaries" of the design spec for this limitation and how to think about countermeasures.
Troubleshooting¶
- Symptom:
ModuleNotFoundError: No module named 'c2pa' - Check: did you activate the virtual environment (
source ~/program/Blockchain_IoT_Marketplace/.venv/bin/activate)? - Check: did you run
python -m pip install c2pa-python pillow cryptographyfrom §1? - Symptom:
No module named pip - Check: this happens when
.venvwas created by a method that does not include pip, such as uv. Runpython -m ensurepip, then runpython -m pip install ...again - Symptom:
.../certs/chain.pem not found; run make_test_certs.py first - Check: did you run
make_test_certs.pyfrom §2? - Symptom:
[FAIL] signer certificate name has no camera ID (iw3ip-gateway-cam01; rerun make_test_certs.py) - Check: a certificate made by an older version of
make_test_certs.pyis left over. Runmake_test_certs.pyagain - Symptom:
webcam capture failed (no camera access, or every frame was black) - Check (macOS): under System Settings → Privacy & Security → Camera, is the terminal app you use allowed? Restart the terminal after allowing it
- Check: is another app using the camera? Is the lens covered, or is the room too dark?
- Check: did you try another camera with
--camera-index 1or similar? - Symptom:
ModuleNotFoundError: No module named 'cv2' - Check: did you run
python -m pip install "opencv-python<5"from §6?
Next steps¶
Next is Connect provenance to the publisher and the chain (C2PA / Stage P, P1 and P2). You send the signed image to the publisher and record the provenance on the chain.
- The next page uses the virtual environment (
.venv) made in §1 of this page. The certificates are made again in §1 of the next page. - §2 of the next page starts a Hardhat node on port 8545. If a Hardhat node started earlier (for example in 2.4) is still running, stop it first with Ctrl+C.
- §3 of the next page restarts the publisher with the C2PA settings.
References¶
[1] C2PA, "C2PA Technical Specification, Version 2.3," https://spec.c2pa.org/specifications/specifications/2.3/specs/C2PA_Specification.html
[2] Content Authenticity Initiative, "c2pa-python: Python binding for c2pa-rs library," GitHub, https://github.com/contentauth/c2pa-python