c2patool - C2PA command line tool
c2patool is a command line tool for working with C2PA manifests. Currently, the tool supports:
- Reading a JSON report of C2PA manifests in supported file formats
- Reading a low-level report of C2PA manifest data in supported file formats
- Previewing manifest data from a manifest definition
- Adding a C2PA manifest to supported file formats
Supported file formats
image/jpegimage/png
Installation
If you have Rust installed, you can install c2patool using:
cargo install c2patool
Or you can clone the repo and build:
git clone git@github.com:contentauth/c2patool.git
cargo build
Or you can use Homebrew on MacOS or Linux to install everything you need:
brew tap contentauth/tools
brew install c2patool
Usage
Displaying manifest data
Invoking the tool with a path to an asset will print a report describing the manifests contained in the file in JSON format to stdout.
c2patool image.jpg
Detailed manifest report
The -d option will print a detailed report describing the internal C2PA format of manifests contained in the file in JSON format to stdout.
c2patool image.jpg -d
Adding a manifest to a file
You can add C2PA data to a file by passing a manifest definition JSON file instead of an image. The tool will generate a new manifest using the values given in the definition.
A parent file and and output file should be specified. The parent file represents the state of the image before any edits were made. The parent file path can be set in the parent field of the manifest definition or on the command line via the -p/parent flag.
The output file is specified on the command line via the -o/output flag. The output file will be updated to contain a new manifest store bound to the output image, replacing any existing manifest data in that file. If you have any previous manifest data, it should be passed via the parent.
The generated manifest store will also be reported in JSON format to stdout.
c2patool sample/test.json -p original.jpg -o edited_image.jpg
Manifest preview feature
If the output file is not specified, the tool will generate a preview of the generated manifest. This can be used to make sure you have formatted the manifest definition correctly.
c2patool sample/test.json
Shortcut feature
If the output file does not exist, and a parent exists, the parent file will be copied to the output location and then updated.
c2patool sample/test.json -p original.jpg -o copy_of_original.jpg
No parent feature
If the output file exists and no parent is specified, the output file will be updated with a manifest created from the manifest definition only. Note that in this case, any previous manifest data in the output file will be replaced.
c2patool sample/test.json -o new_manifest.jpg
Example of a manifest definition file
Here's an example of a manifest definition that inserts a CreativeWork author assertion. If you copy this into a JSON file, you can use it as a test manifest definition.
Manifest definition on command line
The manifest definition can also be passed on the command line as a string using the -c or --config option.
In this example we are adding a custom assertion called "org.contentauth.test".
c2patool -c '{"assertions": [{"label": "org.contentauth.test", "data": {"my_key": "whatever I want"}}]}'
Manifest definition format
The manifest definition file is a JSON formatted file with a .json extension.
Any relative file paths will be treated as relative to the location of the definition file unless a base_path field is specified.
The schema for this type is as follows:
Appendix
Creating and using an X.509 certificate
You should be able to test creating your own manifests using pre-built certificates supplied with this tool. However, if you want to use your own generated certificates, you can specify the path to the cert files in the following configuration fields:
private_keysign_cert
If you are using a signing algorithm other than the default es256, you will need to specify it in the manfifest defnition field alg, which can be set to one of the following:
ps256ps384ps512es256es384es512ed25519
The specified algorithm must be compatible with values of private_key and sign_cert.
The key and cert can also be placed directly in the environment variables C2PA_PRIVATE_KEY and C2PA_SIGN_CERT. These two variables are used to set the private key and public certificates. For example, to sign with es256 signatures using the content of a private key file and certificate file, you would run:
set C2PA_PRIVATE_KEY=$(cat my_es256_private_key)
set C2PA_SIGN_CERT=$(cat my_es256_certs)
Both the private_key and sign_cert should be in PEM format. The sign_cert should contain a PEM certificate chain starting for the end-entity certificate used to sign the claim ending with the intermediate certificate before the root CA certificate. See the "sample" folder for example certificates.
To create your own temporary files for testing, you can execute the following command:
openssl req -new -newkey rsa:4096
-sigopt rsa_padding_mode:pss \
-days 180 \
-extensions v3_ca \
-addext "keyUsage = digitalSignature" \
-addext "extendedKeyUsage = emailProtection" \
-nodes -x509 -keyout private.key -out certs.pem -sha256
Note: You may need to update your openssl version if the above command does not work. You will likely need version 3.0 or later. You can check the version that is installed by typing openssl version.