Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

(IGNORE) Update README.md #54

Merged
merged 7 commits into from
Sep 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 118 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# c2patool - C2PA command line tool

c2patool is a command line tool for working with C2PA [manifests](https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_manifests). Currently, the tool supports:
`c2patool` is a command line tool for working with C2PA [manifests](https://c2pa.org/specifications/specifications/1.0/specs/C2PA_Specification.html#_manifests) and media assets (image or video files).

Use the tool to:

- Read a JSON report of C2PA manifests in [supported file formats](#supported-file-formats).
- Read a low-level report of C2PA manifest data in [supported file formats](#supported-file-formats).
- Preview manifest data from a [manifest definition](#manifest-definition-file).
- Add a C2PA manifest to [supported file formats](#supported-file-formats).

## Installation

PREREQUISITE: Install [Rust](https://www.rust-lang.org/tools/install).

Enter this command to install or update the tool:

```shell
cargo install c2patool
```

### Updating

To ensure you have the latest version, enter this command:

```
c2patool -V
```

The tool will display the version installed. Compare the version number displayed with the latest release version shown in the [repository releases page](https://github.com/contentauth/c2patool/releases). To update to the latest version, use the installation command shown above.

- Reading a JSON report of C2PA manifests in [supported file formats](#supported-file-formats)
- Reading a low-level report of C2PA manifest data in [supported file formats](#supported-file-formats)
- Previewing manifest data from a [manifest definition](#manifest-definition-format)
- Adding a C2PA manifest to [supported file formats](#supported-file-formats)

## Supported file formats

The tool works with the following types of asset files (also referred to as _assets_).

| MIME type | extensions | read only |
| ----------------- | ----------- | --------- |
| `image/jpeg` | `jpg, jpeg` | |
Expand All @@ -21,127 +47,131 @@ c2patool is a command line tool for working with C2PA [manifests](https://c2pa.o
| `application/c2pa`| `c2pa` | X |
| `video/quicktime` | `mov` | |

## Installation
NOTE: Quicktime (`.mov`) format is not yet fully supported.

If you have [Rust](https://www.rust-lang.org/tools/install) installed, you can install or update c2patool using:
## Usage

```shell
cargo install c2patool
The tool's command-line syntax is:

```
c2patool [OPTIONS] [path]
```

## Usage
Where `<path>` is the path to the asset to read or embed a manifest into.

The following table describes the command-line options.

| CLI&nbsp;option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Short version | Argument | Description |
|-----|----|----|----|
| `--config` | `-c` | `<config>` | Specifies a manifest definition as a JSON string. See [Providing a manifest definition on the command line](#providing-a-manifest-definition-on-the-command-line). |
| `--detailed` | `-d` | N/A | Display detailed C2PA-formatted manifest data. See [Displaying a detailed manifest report](#displaying-a-detailed-manifest-report). |
| `--force` | `-f` | N/A | Force overwriting output file. See [Forced overwrite](#forced-overwrite). |
| `--help` | `-h` | N/A | Display CLI help information. |
| `--output` | `-o` | `<output_file>` | Specifies path to output file. See [Adding a manifest to an asset file](#adding-a-manifest-to-an-asset-file). |
| `--manifest` | `-m` | `<manifest_file>` | Specifies a manifest file to add to an asset file. See [Adding a manifest to an asset file](#adding-a-manifest-to-an-asset-file).
| `--parent` | `-p` | `<parent_file>` | Specifies path to parent file. See [Specifying a parent file](#specifying-a-parent-file). |
| `--remote` | `-r` | `<manifest_url>` | Specify URL for remote manifest available over HTTP. See [Generating a remote manifest](#generating-a-remote-manifest)|
| `--sidecar` | `-s` | N/A | Put manifest in external "sidecar" file with `.c2pa` extension. See [Generating an external manifest](#generating-an-external-manifest). |
| `--version` | `-V` | N/A | Display version information. |

### 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.
To display the manifest associated with an asset file, provide the path to the file as the argument; for example:

```shell
c2patool sample/C.jpg
```

### Detailed manifest report
The tool displays the manifest JSON to standard output (stdout).

To display a detailed report describing the internal C2PA format of manifests contained in the asset, use the `-d` option; for example, using one of the example images in the `sample` directory:

The `-d` or `--detailed` option will print a detailed report describing the internal C2PA format of manifests contained in the file in JSON format to stdout.
```shell
c2patool sample/C.jpg -d
c2patool -d sample/C.jpg
```

### Adding a manifest to a file

To add C2PA data to a file, use the `-m` or `--manifest` option and provide a manifest definition JSON file as the argument. The tool generates a new manifest using the values given in the file.

The file path must reference the asset to be signed.
The tool displays the detailed report to standard output (stdout).

The output file is specified on the command line via the `-o` or `--output` flag. If the output is the same as the source, it will be overwritten. Use this with caution. If no output is given you can preview the generated manifest but nothing is written.
### Adding a manifest to an asset file

The generated manifest store will also be reported in JSON format to stdout.
To add C2PA manifest data to a file, use the `--manifest` / `-m` option with a manifest JSON file as the option argument and the path to the asset file to be signed. Specify the output file as the argument to the `--output` / `-o` option. For example:

```shell
c2patool sample/image.jpg -m sample/test.json -o signed_image.jpg
```

A parent file can be specified with the `-p` or `--parent` option or in the manifest definition. The parent file represents the state of the asset before any edits were made.
The tool generates a new manifest using the values given in the file and displays the manifest store to standard output (stdout).

CAUTION: If the output file is the same as the source file, the tool will overwrite the source file.

If you do not use the `--output` / `-o` option, then the tool will display the generated manifest but will not save it to a file.

#### Specifying a parent file

A _parent file_ represents the state of the image before the current edits were made.

Specify a parent file as the argument to the `--parent` / `-p` option; for example:

```shell
c2patool sample/image.jpg -m sample/test.json -p sample/c.jpg -o signed_image.jpg
```

You can also specify a parent file in the manifest definition.

#### Forced overwrite
The tool will return an error if the output file already exists. The `-f` or `--force` flag may be used to override this behavior. Use this with caution.

The tool will return an error if the output file already exists. Use the `--force` / `-f` option to force overwriting the output file. For example:

```shell
c2patool image.jpg -m sample/test.json -f -o signed_image.jpg
c2patool sample/image.jpg -m sample/test.json -f -o signed_image.jpg
```

#### Manifest preview feature
### Previewing a manifest

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.
To display a preview of the generated manifest and ensure you've formatted the manifest definition correctly, provide the path to a manifest file as the argument with no other options or flags; for example:

```shell
c2patool image.jpg -m sample/test.json
c2patool sample/image.jpg -m sample/test.json
```

### Generating an external manifest

The `-s` or `--sidecar` option puts the manifest in an external sidecar file in the same location as the output file. The manifest will have the same output filename but with a ".c2pa" extension. The output file will be copied but untouched.
Use the `--sidecar` / `-s` option to put the manifest in an external sidecar file in the same location as the output file. The manifest will have the same output filename but with a `.c2pa` extension. The tool will copy the output file but the original will be untouched.

```shell
c2patool image.jpg -s -m sample/test.json -o signed_image.jpg
```
### Generating a remote manifest

The `-r` or `--remote` option places an http reference to manifest in the output file. The manifest is returned as an external sidecar file in the same location as the output file. The manifest will have the same output filename but with a ".c2pa" extension. The manifest should then be placed at the location specified by the `-r` option. When using remote manifests the remote URL should be publicly accessible to be most useful to users. When verifying an asset, remote manifests are automatically fetched.
Use the `--remote` / `-r` option to places an HTTP reference to the manifest in the output file. The manifest is returned as an external sidecar file in the same location as the output file with the same filename but with a `.c2pa` extension. Place the manifest at the location specified by the `-r` option. When using remote manifests the remote URL should be publicly accessible to be most useful to users. When verifying an asset, remote manifests are automatically fetched.

```shell
c2patool sample/image.jpg -r http://my_server/myasset.c2pa -m sample/test.json -o signed_image.jpg
```

In the example above c2patool will try to fetch the manifest for new_manifest.jpg from http://my_server/myasset.c2pa during validation.
In the example above, the tool will embed the URL http://my_server/myasset.c2pa in `signed_image.jpg` then fetch the manifest from that URL and save it to `signed_image.c2pa`.

Note: It is possible to combine the `-s` and `-r` options. When used together a manifest will be embedded in the output files and the remote reference will also be added.
If you use both the `-s` and `-r` options, the tool embeds a manifest in the output file and also adds the remote reference.

#### 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.

```json
{
"ta_url": "http://timestamp.digicert.com",

"claim_generator": "TestApp",
"assertions": [
{
"label": "stds.schema-org.CreativeWork",
"data": {
"@context": "https://schema.org",
"@type": "CreativeWork",
"author": [
{
"@type": "Person",
"name": "Joe Bloggs"
}
]
}
}
]
}
```
### Manifest definition on command line
### Providing a manifest definition on the command line

The [manifest definition](#manifest-definition-format) can also be passed on the command line as a string using the `-c` or `--config` option.
To provide the [manifest definition](#manifest-definition-file) in a command line argument instead of a file, use the `--config` / `-c` option.

In this example we are adding a custom assertion called "org.contentauth.test".
For example, the following command adds a custom assertion called "org.contentauth.test".

```shell
c2patool sample/image.json -c '{"assertions": [{"label": "org.contentauth.test", "data": {"my_key": "whatever I want"}}]}'
```

### Manifest definition format
## Manifest definition file

The manifest definition file is a JSON formatted file with a `.json` extension.
Relative file paths are interpreted as relative to the location of the definition file unless you specify a `base_path` field.

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.
### Schema

The schema for the manifest definition file is shown below.

The schema for this type is as follows:
```json
{
"$schema": "http://json-schema.org/draft-07/schema",
Expand Down Expand Up @@ -232,4 +262,28 @@ The schema for this type is as follows:
}
```

#### Example manifest definition file

Here's an example of a manifest definition that inserts a CreativeWork author assertion. Copy this JSON into a file to use as a test manifest.

```json
{
"ta_url": "http://timestamp.digicert.com",
"claim_generator": "TestApp",
"assertions": [
{
"label": "stds.schema-org.CreativeWork",
"data": {
"@context": "https://schema.org",
"@type": "CreativeWork",
"author": [
{
"@type": "Person",
"name": "Joe Bloggs"
}
]
}
}
]
}
```