@contentauth/c2pa-node 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -637,6 +637,7 @@ The library provides helper functions to create and manage settings objects:
637
637
  import {
638
638
  Context,
639
639
  createTrustSettings,
640
+ createTsaTrustSettings,
640
641
  createCawgTrustSettings,
641
642
  createVerifySettings,
642
643
  mergeSettings
@@ -650,10 +651,16 @@ const trustSettings = createTrustSettings({
650
651
  allowedList: "path/to/allowed-list.pem"
651
652
  });
652
653
 
654
+ // Create timestamp trust settings.
655
+ const tsaTrustSettings = createTsaTrustSettings({
656
+ trustAnchors: "path/to/tsa-anchors.pem"
657
+ });
658
+
653
659
  // Create CAWG trust settings
654
660
  const cawgTrustSettings = createCawgTrustSettings({
655
661
  verifyTrustList: true,
656
- trustAnchors: "path/to/cawg-anchors.pem"
662
+ trustAnchors: "path/to/cawg-anchors.pem",
663
+ trustedIcaIssuers: ["did:web:example.com"]
657
664
  });
658
665
 
659
666
  // Create verify settings
@@ -683,8 +690,11 @@ Low-level serialization and loading helpers remain available, but their raw JSON
683
690
  - `verifyTrustList` - Whether to verify against the trust list
684
691
  - `userAnchors` - User-provided trust anchors (PEM format or path)
685
692
  - `trustAnchors` - Trust anchors for validation (PEM format or path)
686
- - `trustConfig` - Path to trust configuration file
687
- - `allowedList` - Allowed list of certificates (PEM format or path)
693
+ - `trustConfig` - Path to trust configuration file. Not available in `tsaTrust`.
694
+ - `allowedList` - Allowed list of certificates (PEM format or path). Not available in `tsaTrust`.
695
+ - `trustedIcaIssuers` - DIDs of identity claims aggregation issuers to trust. Available only in `cawgTrust`.
696
+
697
+ The same fields configure three sections: `trust` for claim signers, `tsaTrust` for timestamps and `cawgTrust` for CAWG identities.
688
698
 
689
699
  **Verify settings:**
690
700
  - `verifyAfterReading` - Whether to verify after reading a manifest
@@ -4,9 +4,12 @@
4
4
  // or the MIT license (http://opensource.org/licenses/MIT),
5
5
  // at your option.
6
6
  import path from "path";
7
+ import { createHash, X509Certificate } from "crypto";
7
8
  import fs from "fs-extra";
8
- import { AssetTooLargeError, Context } from "@contentauth/c2pa-utilities";
9
+ import { AssetTooLargeError, Context, } from "@contentauth/c2pa-utilities";
10
+ import { Builder } from "./Builder.js";
9
11
  import { Reader } from "./Reader.js";
12
+ import { LocalSigner } from "./Signer.js";
10
13
  import { MAX_SIZE_IN_BYTES } from "./assetSize.js";
11
14
  const tempDir = path.join(__dirname, "tmp");
12
15
  describe("Reader", () => {
@@ -271,4 +274,60 @@ describe("Reader", () => {
271
274
  const reader = await Reader.fromAsset(asset);
272
275
  expect(reader).toBeNull();
273
276
  });
277
+ it("trusts a claim signer pinned from trust.allowedList when no other trust set", async () => {
278
+ const certs = await fs.readFile("./tests/fixtures/certs/es256.pub");
279
+ const privateKey = await fs.readFile("./tests/fixtures/certs/es256.pem");
280
+ const leafHash = createHash("sha256")
281
+ .update(new X509Certificate(certs).raw)
282
+ .digest("base64");
283
+ const builder = await Builder.withJsonAsync({
284
+ claim_generator_info: [{ name: "c2pa-js tests", version: "1.0.0" }],
285
+ title: "allowed-list.jpg",
286
+ format: "image/jpeg",
287
+ assertions: [
288
+ {
289
+ label: "c2pa.actions",
290
+ data: {
291
+ actions: [
292
+ {
293
+ action: "c2pa.created",
294
+ digitalSourceType: "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCapture",
295
+ },
296
+ ],
297
+ },
298
+ },
299
+ ],
300
+ });
301
+ const dest = { buffer: null };
302
+ builder.sign(LocalSigner.newSigner(certs, privateKey, "es256"), {
303
+ buffer: await fs.readFile("./tests/fixtures/thumbnail.jpg"),
304
+ mimeType: "image/jpeg",
305
+ }, dest);
306
+ const successCodes = async (allowedList) => {
307
+ const reader = await Reader.fromAsset({ buffer: dest.buffer, mimeType: "image/jpeg" }, new Context({ trust: { allowedList } }));
308
+ return (reader
309
+ .json()
310
+ .validation_results?.activeManifest?.success.map((status) => status.code) ?? []);
311
+ };
312
+ const otherHash = createHash("sha256")
313
+ .update(new X509Certificate(await fs.readFile("./tests/fixtures/certs/ed25519.pub")).raw)
314
+ .digest("base64");
315
+ expect(await successCodes(leafHash)).toContain("signingCredential.trusted");
316
+ expect(await successCodes(otherHash)).not.toContain("signingCredential.trusted");
317
+ });
318
+ it("trusts an ICA issuer listed in cawgTrust trustedIcaIssuers", async () => {
319
+ const asset = { path: "./tests/fixtures/cawg_ica_trust.jpg" };
320
+ const issuer = "did:jwk:eyJhbGciOiJFZERTQSIsImt0eSI6Ik9LUCIsImNydiI6IkVkMjU1MTkiLCJ4IjoiTXA1LTBlODNuTmdRaGRoQlc4UnNoa2p5OTBzYTFBOUpJemtJdGNEcUN1SSJ9";
321
+ const activeManifestCodes = async (settings) => {
322
+ const reader = await Reader.fromAsset(asset, new Context(settings));
323
+ const results = reader.json().validation_results?.activeManifest;
324
+ return [
325
+ ...(results?.success ?? []),
326
+ ...(results?.informational ?? []),
327
+ ...(results?.failure ?? []),
328
+ ].map((status) => status.code);
329
+ };
330
+ expect(await activeManifestCodes({ cawgTrust: { trustedIcaIssuers: [issuer] } })).toContain("cawg.ica.credential_valid");
331
+ expect(await activeManifestCodes({})).toContain("cawg.ica.untrusted_issuer");
332
+ });
274
333
  });
package/dist/index.node CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/index.node
3
- size: 52409088 bytes
4
- sha256: dd151f6f6f5b4ccca5b9d5e754770ad977dca5f8dcef4bed3c3e0e78d6e8c118
3
+ size: 52405720 bytes
4
+ sha256: 2d95b6b5e5c989c5ae5eb4ed43c941fe12527bd9010c36150394fbe22513ce71
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/contentauth/c2pa-js.git",
6
6
  "directory": "packages/c2pa-node"
7
7
  },
8
- "version": "0.12.0",
8
+ "version": "0.12.1",
9
9
  "description": "Node.js bindings for C2PA",
10
10
  "main": "dist/index.js",
11
11
  "type": "module",
@@ -65,7 +65,7 @@
65
65
  "pretty-bytes": "^6.1.1",
66
66
  "unzipper": "^0.10.14",
67
67
  "@contentauth/c2pa-types": "0.8.0",
68
- "@contentauth/c2pa-utilities": "0.5.1"
68
+ "@contentauth/c2pa-utilities": "0.5.2"
69
69
  },
70
70
  "nx": {
71
71
  "tags": [
@@ -165,8 +165,8 @@ impl NeonTrustmark {
165
165
 
166
166
  let promise = cx
167
167
  .task(move || {
168
- let trustmark = trustmark.lock()?;
169
168
  let image = image::load_from_memory(&image_bytes)?;
169
+ let trustmark = trustmark.lock()?;
170
170
  let watermark = watermark.unwrap_or_else(|| gen_watermark(version));
171
171
  let watermarked_image = trustmark
172
172
  .encode(watermark, image, strength)
@@ -217,8 +217,8 @@ impl NeonTrustmark {
217
217
 
218
218
  let promise = cx
219
219
  .task(move || {
220
- let trustmark = trustmark.lock()?;
221
220
  let image = image::load_from_memory(&image_bytes)?;
221
+ let trustmark = trustmark.lock()?;
222
222
  let watermark = trustmark.decode(image)?;
223
223
  Ok(watermark)
224
224
  })