contentauth / c2pa-rs

Rust SDK for the core C2PA (Coalition for Content Provenance and Authenticity) specification
Other
128 stars 56 forks source link

Add canon raw 3 to the list of filetypes in bmff_io.rs #469

Open MTRNord opened 5 months ago

MTRNord commented 5 months ago

Hi :)

I locally out of interested tested the code with cr3 files, and it seems like just adding it to the list works considering there are mostly just canon specific tags in it. Would be nice to add it to the list of filetypes :)

If you need some test file for CI I am happy to provide one of my images at any licence required.

Locally I tried this with appending cr3 to https://github.com/contentauth/c2pa-rs/blob/main/sdk/src/asset_handlers/bmff_io.rs#L68

This with the example spits out:

{
  "active_manifest": "urn:uuid:f704df0d-0b4c-4a55-8bb9-8f733d275bf7",
  "manifests": {
    "urn:uuid:f704df0d-0b4c-4a55-8bb9-8f733d275bf7": {
      "claim_generator": "test_app/0.1 c2pa-rs/0.32.1",
      "title": "test.CR3",
      "format": "application/octet-stream",
      "instance_id": "xmp:iid:c6eb9786-c66c-4d44-a2e4-de88f65c4bf7",
      "ingredients": [
        {
          "title": "IMG_7123.CR3",
          "format": "application/octet-stream",
          "instance_id": "xmp:iid:4a48f08d-79f3-43fc-837b-54dce02cf49e",
          "relationship": "parentOf"
        }
      ],
      "assertions": [
        {
          "label": "c2pa.actions",
          "data": {
            "actions": [
              {
                "action": "c2pa.placed",
                "parameters": {
                  "identifier": "xmp:iid:4a48f08d-79f3-43fc-837b-54dce02cf49e"
                }
              }
            ]
          }
        },
        {
          "label": "stds.schema-org.CreativeWork",
          "data": {
            "@context": "http://schema.org/",
            "@type": "CreativeWork",
            "author": [
              {
                "@type": "Person",
                "name": "me"
              }
            ]
          },
          "kind": "Json"
        },
        {
          "label": "stds.exif",
          "data": {
            "@context": {
              "exif": "http://ns.adobe.com/exif/1.0/"
            },
            "exif:GPSLatitude": "39,21.102N",
            "exif:GPSTimeStamp": "2019-09-22T18:22:57Z",
            "exif:GPSLongitude": "74,26.5737W",
            "exif:GPSAltitudeRef": 0,
            "exif:GPSVersionID": "2.2.0.0",
            "exif:GPSAltitude": "100963/29890"
          },
          "kind": "Json"
        },
        {
          "label": "c2pa.hash.bmff.v2",
          "data": {
            "exclusions": [
              {
                "xpath": "/uuid",
                "length": null,
                "data": [
                  {
                    "offset": 8,
                    "value": [
                      216,
                      254,
                      195,
                      214,
                      27,
                      14,
                      72,
                      60,
                      146,
                      151,
                      88,
                      40,
                      135,
                      126,
                      196,
                      129
                    ]
                  }
                ],
                "subset": null,
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/ftyp",
                "length": null,
                "data": null,
                "subset": null,
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/meta/iloc",
                "length": null,
                "data": null,
                "subset": null,
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/mfra/tfra",
                "length": null,
                "data": null,
                "subset": null,
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/moov/trak/mdia/minf/stbl/stco",
                "length": null,
                "data": null,
                "subset": [
                  {
                    "offset": 16,
                    "length": 0
                  }
                ],
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/moov/trak/mdia/minf/stbl/co64",
                "length": null,
                "data": null,
                "subset": [
                  {
                    "offset": 16,
                    "length": 0
                  }
                ],
                "version": null,
                "flags": null,
                "exact": null
              },
              {
                "xpath": "/moof/traf/tfhd",
                "length": null,
                "data": null,
                "subset": [
                  {
                    "offset": 16,
                    "length": 8
                  }
                ],
                "version": null,
                "flags": [
                  1,
                  0,
                  0
                ],
                "exact": null
              },
              {
                "xpath": "/moof/traf/trun",
                "length": null,
                "data": null,
                "subset": [
                  {
                    "offset": 16,
                    "length": 4
                  }
                ],
                "version": null,
                "flags": [
                  1,
                  0,
                  0
                ],
                "exact": null
              }
            ],
            "alg": "sha256",
            "hash": "0TX4dZONswNJhSxhWrrdjhb6SEbQbjDQQYHvjfqO//0=",
            "name": "jumbf manifest"
          }
        }
      ],
      "signature_info": {
        "alg": "Es256",
        "issuer": "C2PA Test Signing Cert",
        "cert_serial_number": "640229841392226413189608867977836244731148734950"
      },
      "label": "urn:uuid:f704df0d-0b4c-4a55-8bb9-8f733d275bf7"
    }
  }
}

manifest_label: urn:uuid:f704df0d-0b4c-4a55-8bb9-8f733d275bf7
title: test.CR3 , format: application/octet-stream, instance_id: xmp:iid:c6eb9786-c66c-4d44-a2e4-de88f65c4bf7
c2pa.actions
c2pa.placed
stds.schema-org.CreativeWork
author = me 
stds.exif
c2pa.hash.bmff.v2
Ingredient title:IMG_7123.CR3

Which to my untrained eye indicates it is working. there is no visual corruption either so its not overwriting image data for it to work either.

mauricefisher64 commented 4 months ago

We will discuss support for this in SDK.

gpeacock commented 3 months ago

Please send us a sample file and we can investigate

MTRNord commented 3 months ago

Sorry for the delayed reply. Below are 2 cr3 files. One already signed using c2pa-rs and a patch adding cr3 to the list of filetypes and one not yet signed straight from the camera.

IMG_4654.tar.gz

compressed due to requirements from github. Photo taken by me on a Canon EOS R8. Feel free to use it under CC0 if thats working for you :) It does already have a signature.

C2PATool output

```json { "active_manifest": "urn:uuid:9744236e-b160-4ebb-9fc4-247d15df3380", "manifests": { "urn:uuid:9744236e-b160-4ebb-9fc4-247d15df3380": { "claim_generator": "MTRNord_Photography_Manager/0.1.0 c2pa-rs/0.32.2", "title": "IMG_4650.CR3", "format": "image/x-canon-cr3", "instance_id": "xmp:iid:26f0c6ec-4401-48b4-ab61-a1b568c2a60c", "ingredients": [ { "title": "IMG_4650.CR3", "format": "image/x-canon-cr3", "instance_id": "xmp:iid:51274428-df9a-48c9-8eb1-a00b256a8f0e", "relationship": "parentOf" } ], "assertions": [ { "label": "c2pa.actions", "data": { "actions": [ { "action": "c2pa.created" } ] } }, { "label": "c2pa.ai_training", "data": { "use": "notAllowed", "constraintInfo": null } }, { "label": "c2pa.ai_generative_training", "data": { "use": "notAllowed", "constraintInfo": null } }, { "label": "c2pa.data_mining", "data": { "use": "notAllowed", "constraintInfo": null } }, { "label": "c2pa.inference", "data": { "use": "notAllowed", "constraintInfo": null } }, { "label": "stds.schema-org.CreativeWork", "data": { "@context": "https://schema.org", "@type": "CreativeWork", "author": [ { "@context": "https://schema.org", "@type": "Person", "identifier": "MTRNord", "@id": "https://instagram.com", "name": "MTRNord" } ] }, "kind": "Json" }, { "label": "stds.schema-org.CreativeWork", "data": { "@context": "https://schema.org", "@type": "CreativeWork", "url": "https://mtrnord.blog" }, "instance": 1, "kind": "Json" }, { "label": "stds.schema-org.CreativeWork", "data": { "@context": "https://schema.org", "@type": "CreativeWork", "author": [ { "@context": "https://schema.org", "@type": "Person", "name": "AEDE3887B1551783", "@id": "https://keys.openpgp.org", "identifier": "9768 CA63 F48D 3609 8567 A59D AEDE 3887 B155 1783" } ] }, "instance": 2, "kind": "Json" }, { "label": "stds.exif", "data": { "@context": { "dc": "http://purl.org/dc/elements/1.1/", "exifEX": "http://cipa.jp/exif/2.32/", "exif": "http://ns.adobe.com/exif/1.0/", "tiff": "http://ns.adobe.com/tiff/1.0/", "xmp": "http://ns.adobe.com/xap/1.0/", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#" }, "exif:FNumber": 2.0, "exifEX:LensModel": "EF50mm f/1.8 STM", "exif:ExposureTime": "1/4000" }, "kind": "Json" }, { "label": "c2pa.hash.bmff.v2", "data": { "exclusions": [ { "xpath": "/uuid", "length": null, "data": [ { "offset": 8, "value": [ 216, 254, 195, 214, 27, 14, 72, 60, 146, 151, 88, 40, 135, 126, 196, 129 ] } ], "subset": null, "version": null, "flags": null, "exact": null }, { "xpath": "/ftyp", "length": null, "data": null, "subset": null, "version": null, "flags": null, "exact": null }, { "xpath": "/meta/iloc", "length": null, "data": null, "subset": null, "version": null, "flags": null, "exact": null }, { "xpath": "/mfra/tfra", "length": null, "data": null, "subset": null, "version": null, "flags": null, "exact": null }, { "xpath": "/moov/trak/mdia/minf/stbl/stco", "length": null, "data": null, "subset": [ { "offset": 16, "length": 0 } ], "version": null, "flags": null, "exact": null }, { "xpath": "/moov/trak/mdia/minf/stbl/co64", "length": null, "data": null, "subset": [ { "offset": 16, "length": 0 } ], "version": null, "flags": null, "exact": null }, { "xpath": "/moof/traf/tfhd", "length": null, "data": null, "subset": [ { "offset": 16, "length": 8 } ], "version": null, "flags": [ 1, 0, 0 ], "exact": null }, { "xpath": "/moof/traf/trun", "length": null, "data": null, "subset": [ { "offset": 16, "length": 4 } ], "version": null, "flags": [ 1, 0, 0 ], "exact": null } ], "alg": "sha256", "hash": "qkteOatW+yqZYGRvAusoVuQYWAGemv0fxynNq6Pzkbg=", "name": "jumbf manifest" } } ], "signature_info": { "alg": "Es256", "issuer": "MTRNord", "cert_serial_number": "1394774989354528955397704349500428433318678915552" }, "label": "urn:uuid:9744236e-b160-4ebb-9fc4-247d15df3380" } } } ```

If thats an issue below is one under the same conditions which isnt yet signed. (I am running a cr3 compat fork with some other stuff over at https://github.com/mtrnords-photography-manager/c2pa-rs/ for my use)

IMG_7500.tar.gz