Skip to content

Commit 824c798

Browse files
Merge pull request #27 from Jalen-Stephens/24-service-implement-c2pa-tool-to-automatically-download-via-pomxml-for-all-operating-systems
[c2pa] Implementation of C2PA across all platforms
2 parents bc93b6d + e63b4ed commit 824c798

File tree

14 files changed

+194
-144
lines changed

14 files changed

+194
-144
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ build/
3535
### Enviroment Variables ###
3636
.env
3737
env.local.sh
38-
39-
### C2PA and Tools ###
40-
/tools/
41-
42-
4338
env.pooler.sh

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,9 @@ This section includes notes on tools and technologies used in building this proj
135135
* JUnit tests get run automatically as part of the CI pipeline.
136136
* JaCoCo
137137
* We use JaCoCo for generating code coverage reports.
138-
* Originally we were planning on using Cobertura, however Cobertura does not support our version of Java.
138+
* Originally we were planning on using Cobertura, however Cobertura does not support our version of Java.
139+
* c2patool
140+
* We use the open-source c2patool to scrape manifest metadata for determining the usage of AI in generating an image.
141+
* Coalition for Content Provenance and Authenticity (C2PA). *c2patool (Version 0.23.4)*.
142+
* Content Authenticity Initiative, Adobe Systems, 2024.
143+
* Available at: https://github.com/contentauth/c2pa-rs

citations.md

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -563,38 +563,6 @@ The AI helped ensure that the **C2PAtool binary** (used for AI-image authenticit
563563

564564
---
565565

566-
### **Purpose of AI Assistance**
567-
Assistance was used to **debug and configure Maven build behavior** for the `AnalyzeService` Spring Boot service.
568-
The AI helped ensure that the **C2PAtool binary** (used for AI-image authenticity verification) is correctly downloaded, unpacked, and persisted across build phases so it remains executable both locally and in deployment.
569-
570-
---
571-
572-
### **Prompts / Interaction Summary**
573-
- Asked why `mvn package` wasn’t producing the `tools/c2patool` binary.
574-
- Requested possible solutions to `pom.xml` configuration using `download-maven-plugin` and `maven-antrun-plugin`.
575-
- Troubleshot successive build errors (e.g. "file is directory", missing binary).
576-
- Asked how to keep the binary after packaging and why Maven was deleting it.
577-
- Requested an explanation of the final working solution and how to preserve the executable between builds.
578-
579-
---
580-
581-
### **Resulting Artifacts**
582-
- **Edited File:** `pom.xml`
583-
- Added `download-maven-plugin` section to fetch `c2patool-v0.9.12-universal-apple-darwin.zip`.
584-
- Added `maven-antrun-plugin` section to unzip, copy, chmod, and retain the binary.
585-
- **New Directory:** `tools/` (containing executable `c2patool`)
586-
- **Build Artifact:** Verified Maven package with `tools/c2patool` present and executable.
587-
588-
---
589-
590-
### **Verification**
591-
- Ran `mvn clean package` to confirm the binary appears at `./tools/c2patool`.
592-
- Executed `./tools/c2patool --version` to verify the file runs successfully.
593-
- Rebuilt the Spring Boot JAR to ensure the `tools/` directory remains intact after packaging.
594-
- Manually inspected Maven logs and filesystem to confirm that no cleanup phase deletes the binary.
595-
596-
---
597-
598566
### **Commit / Ticket Reference**
599567

600568
* **Commit:** `feat(auth): add Supabase auth proxy + /auth endpoints + JWKS resource server config (refs #7)`
@@ -1050,4 +1018,64 @@ Helped implement the controller logic integrating with the `ImageService`, updat
10501018

10511019
> Portions of this commit or configuration were generated with assistance from OpenAI ChatGPT (GPT-5) on October 22, 2025. All AI-generated content was reviewed, verified, and finalized by the development team.
10521020
1053-
---
1021+
---
1022+
1023+
### **Commit / Ticket Reference**
1024+
1025+
* **Commit:** `test(c2pa): add unit tests for C2paToolInvoker to validate tool invocation and error handling`
1026+
* **Ticket:** `#24 — Ensure c2patool Functionality Across All Systems and Build Unit Tests for C2paToolInvoker`
1027+
* **Date:** October 22, 2025
1028+
* **Team Member:** Isaac Schmidt
1029+
1030+
---
1031+
1032+
### **AI Tool Information**
1033+
1034+
* **Tool Used:** OpenAI ChatGPT (GPT-5)
1035+
* **Access Method:** ChatGPT Web (.edu academic access)
1036+
* **Configuration:** Default model settings
1037+
* **Cost:** $0 (no paid API calls)
1038+
1039+
---
1040+
1041+
### **Purpose of AI Assistance**
1042+
1043+
The AI assisted in designing and implementing unit tests for the `C2paToolInvoker` class. These tests validate the correct invocation of the `c2patool` binary, handle various error scenarios, and ensure proper exception handling. The AI also provided guidance on creating temporary files for testing and structuring the test cases to cover success and failure paths.
1044+
1045+
---
1046+
1047+
### **Prompts / Interaction Summary**
1048+
1049+
* Asked for a unit test suite for `C2paToolInvoker` to validate tool invocation.
1050+
* Requested test cases for scenarios like:
1051+
- Successful manifest extraction.
1052+
- Non-existent image file.
1053+
- Invalid file format.
1054+
- Missing `c2patool` binary.
1055+
* Asked for a commit message and citation entry for the tests.
1056+
1057+
---
1058+
1059+
### **Resulting Artifacts**
1060+
1061+
* **File Created:** `src/test/java/dev/coms4156/project/metadetect/c2pa/C2paToolInvokerUnitTest.java`
1062+
- `testExtractManifestSuccess`: Validates successful manifest extraction from a mock image file.
1063+
- `testExtractManifestFileNotFound`: Tests behavior when the image file does not exist.
1064+
- `testExtractManifestInvalidFile`: Tests behavior when the file is not a valid image.
1065+
- `testExtractManifestToolNotFound`: Tests behavior when the `c2patool` binary is missing.
1066+
- Helper method `createTempInvalidFile`: Creates a temporary invalid file for testing.
1067+
1068+
---
1069+
1070+
### **Verification**
1071+
1072+
* Ran `mvn clean test` to confirm all tests pass successfully.
1073+
* Verified that temporary files are created and cleaned up correctly during tests.
1074+
* Confirmed that the `c2patool` binary is invoked correctly for valid test cases.
1075+
* Manually reviewed test output to ensure proper exception messages are logged for failure cases.
1076+
1077+
---
1078+
1079+
### **Attribution Statement**
1080+
1081+
> Portions of this test suite were generated with assistance from OpenAI ChatGPT (GPT-5) on October 22, 2025. All AI-generated content was reviewed, verified, and finalized by the development team.

pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
<java.version>17</java.version>
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2424

25-
<!-- C2PA tool download configuration (macOS universal ZIP) -->
26-
<c2pa.version>v0.23.4</c2pa.version>
27-
<c2pa.url>https://github.com/contentauth/c2pa-rs/releases/download/c2patool-{c2pa.version}/c2patool-{c2pa.version}-universal-apple-darwin.zip</c2pa.url>
28-
<c2pa.unpack.dir>${project.basedir}/tools</c2pa.unpack.dir>
29-
<c2pa.unpack.archive>${c2pa.unpack.dir}/c2patool.zip</c2pa.unpack.archive>
30-
<!-- Folder name created by the ZIP for v0.23.4 (contains the binary named "c2patool") -->
31-
<c2pa.unzipped.folder>c2patool-${c2pa.version}-universal-apple-darwin</c2pa.unzipped.folder>
25+
<!-- C2PA tool download configuration -->
26+
<c2pa.version>v0.23.4</c2pa.version>
27+
<c2pa.unpack.dir>${project.basedir}/tools/c2patool</c2pa.unpack.dir>
28+
<c2pa.unpack.archive>${c2pa.unpack.dir}/c2patool.zip</c2pa.unpack.archive>
3229
</properties>
3330

3431
<dependencyManagement>
@@ -187,7 +184,9 @@
187184
</extension>
188185
</extensions>
189186
<finalName>${project.artifactId}-${project.version}</finalName>
190-
187+
<pluginManagement>
188+
189+
191190
<plugins>
192191
<!-- Spring Boot (single declaration) -->
193192
<plugin>
@@ -279,5 +278,6 @@
279278
</executions>
280279
</plugin>
281280
</plugins>
281+
</pluginManagement>
282282
</build>
283283
</project>

src/main/java/dev/coms4156/project/metadetect/c2pa/C2paJsonParser.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/main/java/dev/coms4156/project/metadetect/c2pa/C2paToolInvoker.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package dev.coms4156.project.metadetect.c2pa;
22

33
import java.io.File;
4+
import java.io.FileWriter;
45
import java.io.IOException;
56
import java.io.InputStream;
6-
import java.io.InterruptedIOException;
77
import java.nio.charset.StandardCharsets;
8-
import java.nio.file.Files;
98
import java.util.Scanner;
10-
import java.util.concurrent.TimeUnit;
119

1210

1311
/** Invokes the C2PA command-line tool to extract manifests from images.*/
@@ -39,26 +37,41 @@ public String extractManifest(File imageFile) throws IOException {
3937
"-d"
4038
);
4139

42-
System.out.println("C2PA Tool Path: " + c2paToolPath);
43-
System.out.println("Image File Path: " + imageFile.getAbsolutePath());
44-
System.out.println("Executing command: " + String.join(" ", processBuilder.command()));
45-
46-
// Print the command for debugging
47-
System.out.println("Executing command: " + String.join(" ", processBuilder.command()));
48-
4940
// Start the process
5041
Process process = processBuilder.start();
51-
42+
String output;
43+
String returnString;
5244
try {
5345
// Wait for the process to complete
5446
int exitCode = process.waitFor();
5547
if (exitCode != 0) {
5648
throw new IOException("C2PA tool failed with exit code " + exitCode);
5749
}
50+
5851
// Read the output file and return its contents as a string
59-
return " "; // placeholder
52+
try (InputStream is = process.getInputStream();
53+
Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name())) {
54+
output = scanner.useDelimiter("\\A").next();
55+
56+
returnString = output;
57+
58+
} catch (Exception e) {
59+
throw new IOException("Failed to read C2PA tool output", e);
60+
}
61+
6062
} catch (InterruptedException e) {
6163
throw new IOException("C2PA tool execution was interrupted", e);
6264
}
65+
66+
try (FileWriter file = new FileWriter("output.json")) {
67+
file.write(output);
68+
file.flush();
69+
70+
return returnString;
71+
72+
} catch (IOException e) {
73+
throw new IOException("Failed to write output to file", e);
74+
}
75+
6376
}
6477
}

src/main/java/dev/coms4156/project/metadetect/config/SecurityConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.security.oauth2.jose.jws.MacAlgorithm;
1313
import org.springframework.security.oauth2.jwt.Jwt;
1414
import org.springframework.security.oauth2.jwt.JwtDecoder;
15-
import org.springframework.security.oauth2.jwt.JwtException;
1615
import org.springframework.security.oauth2.jwt.JwtValidators;
1716
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
1817
import org.springframework.security.web.SecurityFilterChain;

src/main/java/dev/coms4156/project/metadetect/service/AnalyzeService.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
import dev.coms4156.project.metadetect.c2pa.C2paToolInvoker;
44
import java.io.File;
55
import java.io.IOException;
6-
import java.io.InputStream;
7-
import java.util.ArrayList;
8-
import java.util.Collection;
9-
import java.util.LinkedHashMap;
10-
import java.util.List;
11-
import java.util.Map;
126
import org.springframework.stereotype.Service;
137
import org.springframework.web.multipart.MultipartFile;
148

src/main/java/dev/coms4156/project/metadetect/service/AuthProxyService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.coms4156.project.metadetect.service;
22

3-
import org.springframework.http.HttpStatus;
43
import org.springframework.http.HttpStatusCode;
54
import org.springframework.http.MediaType;
65
import org.springframework.http.ResponseEntity;

0 commit comments

Comments
 (0)