Skip to content

Commit

Permalink
add c2pa public cert to proof zip
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 15, 2023
1 parent c4dfe9f commit a008e0c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class C2paUtils {

companion object {

private const val C2PA_CERT_PATH = "cr.cert"
public const val C2PA_CERT_PATH = "cr.cert"
private const val C2PA_KEY_PATH = "cr.key"

private const val C2PA_CERT_PATH_PARENT = "crp.cert"
Expand Down Expand Up @@ -139,6 +139,10 @@ class C2paUtils {
fun importCredentials (mContext : Context, fileKey : File, fileCert : File) {

}

fun getUserCertificate (mContext : Context) : File {
return File(mContext.filesDir, C2PA_CERT_PATH)
}
/**
* initialize the private keys and certificates for signing C2PA data
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ProofMode {

public final static String PUBKEY_FILE = "pubkey.asc";

public final static String C2PA_CERT_FILE = "c2paidentity.cert";
public final static String PREFS_DOPROOF = "doProof";

public final static String EVENT_PROOF_START = "org.witness.proofmode.PROOF_START";
Expand Down Expand Up @@ -466,6 +467,18 @@ public static void generateProofZip(Context context, String proofHash, String pa
out.putNextEntry(entry);
out.write(getPublicKeyString(context, passphrase).getBytes());

String C2PA_CERT_PATH = "cr.cert";

entry = new ZipEntry(C2PA_CERT_FILE);
out.putNextEntry(entry);
FileInputStream fisCert = new FileInputStream((new File(context.getFilesDir(), C2PA_CERT_PATH)));
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = fisCert.read(buf)) > 0) {
out.write(buf, 0, len);
}

Timber.d("Zip complete");

out.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Dialog
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.LabeledIntent
Expand Down Expand Up @@ -47,6 +46,7 @@ import org.witness.proofmode.ProofMode.PREF_OPTION_AI_DEFAULT
import org.witness.proofmode.ProofModeConstants.PREFS_KEY_PASSPHRASE
import org.witness.proofmode.ProofModeConstants.PREFS_KEY_PASSPHRASE_DEFAULT
import org.witness.proofmode.camera.c2pa.C2paUtils
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.C2PA_CERT_PATH
import org.witness.proofmode.crypto.HashUtils
import org.witness.proofmode.crypto.pgp.PgpUtils
import org.witness.proofmode.databinding.ActivityShareBinding
Expand Down Expand Up @@ -1555,6 +1555,12 @@ class ShareProofActivity : AppCompatActivity() {
var entry: ZipEntry? = ZipEntry("pubkey.asc")
out.putNextEntry(entry)
out.write(pubKey.toByteArray())

Timber.d("Adding C2PA certificate")
entry = ZipEntry(C2PA_CERT_PATH)
out.putNextEntry(entry)
out.write(File(filesDir,C2PA_CERT_PATH).readBytes())

Timber.d("Adding HowToVerifyProofData.txt")
val howToFile = "HowToVerifyProofData.txt"
entry = ZipEntry(howToFile)
Expand Down

0 comments on commit a008e0c

Please sign in to comment.