Skip to main content

Numbers C2PA tool

Project description

numbers-c2pa

Setup

Install Rust

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install c2patool

Download the prebuilt binary for your platform:

# For macOS (Universal Binary - Apple Silicon & Intel)
curl -L -o c2patool.zip https://github.com/contentauth/c2pa-rs/releases/download/c2patool-v0.26.1/c2patool-v0.26.1-universal-apple-darwin.zip
unzip c2patool.zip
chmod +x c2patool/c2patool
cp c2patool/c2patool ~/.local/bin/  # or any directory in your PATH

# For Linux
curl -L -o c2patool.tar.gz https://github.com/contentauth/c2pa-rs/releases/download/c2patool-v0.26.1/c2patool-v0.26.1-x86_64-unknown-linux-gnu.tar.gz
tar -xzf c2patool.tar.gz
chmod +x c2patool/c2patool
cp c2patool/c2patool ~/.local/bin/

# For Windows
# Download: https://github.com/contentauth/c2pa-rs/releases/download/c2patool-v0.26.1/c2patool-v0.26.1-x86_64-pc-windows-msvc.zip
# Extract and add c2patool.exe to your PATH

# Verify installation
c2patool --version  # Should show: c2patool 0.26.1

Alternatively, build from source (requires Rust):

$ cargo install c2patool --version 0.26.1

Install numbers-c2pa

$ python3 -m pip install git+https://github.com/numbersprotocol/numbers-c2pa.git

Usage

C2PA Injection

from datetime import datetime

from numbers_c2pa import create_c2pa_manifest, inject_file

if __name__ == '__main__':
    with open('examples/es256_private.key') as f:
        private_key = f.read()
    with open('examples/es256_certs.pem') as f:
        sign_cert = f.read()
    manifest = create_c2pa_manifest(
        nid='this is nid',
        creator_public_key='this is creator public key',
        asset_hash='this is sha256hash',
        date_created=datetime.now(),
        location_created='123.123, 45.45',
        date_captured=None,
    )
    inject_file(
        'examples/numbers.png',
        'examples/numbers-c2pa.png',
        manifest=manifest,
        parent_path='examples/numbers.png',
        private_key=private_key,
        sign_cert=sign_cert,
    )
    # examples/numbers-c2pa.png will be created
    # Upload file to https://verify.contentauthenticity.org/inspect to view C2PA data

Read C2PA data

from numbers_c2pa import read_c2pa_file

if __name__ == '__main__':
    c2pa_json = read_c2pa_file('examples/numbers-c2pa.png')
    print(c2pa_json)

Create self-signed certificate with intermediate CA

According to c2patool readme:

Both the private_key and sign_cert must be in PEM format. The sign_cert must contain a PEM certificate chain starting with 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.

Using a intermediate CA certificate is required.

Updated steps

Create end-entity and intermediate private keys

openssl ecparam -genkey -name prime256v1 -noout -out intermediate_ca.key
openssl ecparam -genkey -name prime256v1 -noout -out end_entity.key

Create intermediate cert

openssl req -x509 -new -key intermediate_ca.key -out intermediate_ca.crt -subj "/CN=Numbers Intermediate CA" -days 365 -sha256

Create end_entity_csr.conf file

[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = v3_req
distinguished_name = dn

[ dn ]
C = US
ST = California
L = San Fransisco
O = Numbers Protocol
OU = Numbers Protocol
CN = Numbers Protocol

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = timeStamping
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = numbersprotocol.io
DNS.2 = www.numbersprotocol.io

Create end-entity CSR

openssl req -new -key end_entity.key -out end_entity.csr -config end_entity_csr.conf

Create end-entity certificate

openssl x509 -req -in end_entity.csr -CA intermediate_ca.crt -CAkey intermediate_ca.key -out end_entity.crt -days 365 -CAcreateserial -extfile end_entity_csr.conf -extensions v3_req -sha256

Combine certificate chain

cat end_entity.crt intermediate_ca.crt > certificate_chain.pem

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numbers_c2pa-0.4.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numbers_c2pa-0.4.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file numbers_c2pa-0.4.1.tar.gz.

File metadata

  • Download URL: numbers_c2pa-0.4.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for numbers_c2pa-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9f7e1512d89fa897f7c9a4bc976b89ecbd219fccb3d75303568c8a58e003683e
MD5 cd7332a73a87813fc7481cf3b921e40a
BLAKE2b-256 173c64d3f3df07d7c3745b580c72c3ec2136604f2cf141d0c0e117abf7e473be

See more details on using hashes here.

File details

Details for the file numbers_c2pa-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: numbers_c2pa-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for numbers_c2pa-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc16f41a67b0c94611b3aeb684aebe9018fc8711e06507f5294970b8e975398f
MD5 03ee88c5de5c531f87f1dc18c7cf597f
BLAKE2b-256 0f95f72e268ac0b4b567261a01c719825b7578e6d273bc5c5815327191657faa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page