Skip to content

Commit

Permalink
clean-up c2pa metadata setting and update to 2.2.0-BETA-1
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 7, 2023
1 parent 34d0b8f commit b0317d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package org.witness.proofmode.camera
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.witness.proofmode.camera.c2pa.C2paUtils
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.IDENTITY_EMAIL_KEY
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.IDENTITY_NAME_KEY
import org.witness.proofmode.camera.c2pa.C2paUtils.Companion.IDENTITY_URI_KEY

class CameraActivity : AppCompatActivity(){


private val PREF_OPTION_AI = "blockAI"

private val PREF_OPTION_CREDENTIALS = "addCR"

var useCredentials = true
Expand All @@ -23,12 +23,5 @@ class CameraActivity : AppCompatActivity(){
useCredentials = intent.getBooleanExtra(PREF_OPTION_CREDENTIALS, true)
useAIFlag = intent.getBooleanExtra(PREF_OPTION_AI, true)

if (useCredentials) {
//set identity based on passed strings
C2paUtils.setC2PAIdentity(
intent.getStringExtra(IDENTITY_NAME_KEY),
intent.getStringExtra(IDENTITY_URI_KEY)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class C2paUtils {

private const val CERT_VALIDITY_DAYS = 365U //5 years

private var _identityUri = "ProofMode@https://proofmode.org"
private var _identityUri = "https://proofmode.org"
private var _identityName = "ProofMode"
private var _identityEmail = "[email protected]"
private var _identityKey = "0x00000000"

private var userCert : Certificate? = null

Expand All @@ -40,14 +42,20 @@ class C2paUtils {
/**
* Set identity values for certificate and content credentials
*/
fun setC2PAIdentity (identityName: String?, identityUri: String?)
fun setC2PAIdentity (identityName: String?, identityUri: String?, identityEmail: String?, identityKey: String?)
{
if (identityName != null) {
if (identityName?.isNotEmpty() == true)
_identityName = identityName
}
if (identityUri != null) {

if (identityUri?.isNotEmpty() == true)
_identityUri = identityUri
}

if (identityEmail?.isNotEmpty() == true)
_identityEmail = identityEmail

if (identityKey?.isNotEmpty() == true)
_identityKey = identityKey

}

/**
Expand Down Expand Up @@ -91,16 +99,13 @@ class C2paUtils {
}

if (fileMedia.exists()) {
//TODO add c2pa capture here
var identityId = _identityName
var identityUri = _identityUri

addContentCredentials(
_context,
identityId,
identityUri,
identityId,
identityUri,
_identityEmail,
_identityKey,
_identityName,
_identityUri,
isDirectCapture,
allowMachineLearning,
fileMedia,
Expand Down Expand Up @@ -196,7 +201,7 @@ class C2paUtils {
/**
* add new C2PA Content Credential assertions and then embed and sign them
*/
fun addContentCredentials(mContext : Context, emailAddress: String, pgpFingerprint: String, emailDisplay: String?, webLink: String?, isDirectCapture: Boolean, allowMachineLearning: Boolean, fileImageIn: File, fileImageOut: File) {
fun addContentCredentials(mContext : Context, emailAddress: String, pgpFingerprint: String, emailDisplay: String, webLink: String, isDirectCapture: Boolean, allowMachineLearning: Boolean, fileImageIn: File, fileImageOut: File) {

if (userCert == null)
initCredentials(mContext, emailAddress, pgpFingerprint)
Expand All @@ -219,37 +224,9 @@ class C2paUtils {
else
contentCreds?.addPermissiveAiTrainingAssertions()

emailDisplay?.let { contentCreds?.addEmailAssertion(emailAddress, it) }
pgpFingerprint?.let { contentCreds?.addPgpAssertion(it, it) }
webLink?.let { contentCreds?.addWebsiteAssertion(it) }

/**
* let exif_data = ExifData {
* gps_version_id: Some("2.2.0.0".to_string()),
* latitude: Some("39,21.102N".to_string()),
* longitude: Some("74,26.5737W".to_string()),
* altitude_ref: Some(0),
* altitude: Some("100963/29890".to_string()),
* timestamp: Some("2019-09-22T18:22:57Z".to_string()),
* speed_ref: Some("K".to_string()),
* speed: Some("4009/161323".to_string()),
* direction_ref: Some("T".to_string()),
* direction: Some("296140/911".to_string()),
* destination_bearing_ref: Some("T".to_string()),
* destination_bearing: Some("296140/911".to_string()),
* positioning_error: Some("13244/2207".to_string()),
* exposure_time: Some("1/100".to_string()),
* f_number: Some(4.0),
* color_space: Some(1),
* digital_zoom_ratio: Some(2.0),
* make: Some("ProofMode".to_string()),
* model: Some("ProofMode In-App Camera v2.0".to_string()),
* lens_make: Some("CameraCompany".to_string()),
* lens_model: Some("17.0-35.0 mm".to_string()),
* lens_specification: Some(vec![1.55, 4.2, 1.6, 2.4]),
* };
*
*/
contentCreds?.addEmailAssertion(emailAddress, emailDisplay)
contentCreds?.addPgpAssertion(pgpFingerprint, pgpFingerprint)
contentCreds?.addWebsiteAssertion(webLink)

var exifMake = Build.MANUFACTURER
var exifModel = Build.MODEL
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "org.witness.proofmode"
minSdkVersion 24
targetSdkVersion 33
versionCode 220104
versionName "2.2.0-ALPHA-4"
versionCode 220201
versionName "2.2.0-BETA-1"
multiDexEnabled true
archivesBaseName = "ProofMode-$versionName"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
44 changes: 18 additions & 26 deletions app/src/main/java/org/witness/proofmode/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -630,34 +630,30 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
var useCredentials = mPrefs.getBoolean(PREF_OPTION_CREDENTIALS, PREF_OPTION_CREDENTIALS_DEFAULT);

intentCam.putExtra(PREF_OPTION_CREDENTIALS, useCredentials);
intentCam.putExtra(PREF_OPTION_AI, mPrefs.getBoolean(PREF_OPTION_CREDENTIALS, PREF_OPTION_AI_DEFAULT));

if (useCredentials) {
if (useCredentials)
initContentCredentials()

val credPrimary = mPrefs.getString(PREF_CREDENTIALS_PRIMARY,"");

if (credPrimary?.isNotEmpty() == true)
{
var displayName = "${credPrimary.replace("@"," at ")}"

intentCam.putExtra(C2paUtils.IDENTITY_NAME_KEY, displayName)

var credUri =
"${URLEncoder.encode(displayName, "UTF-8")}@mailto:${URLEncoder.encode(credPrimary, "UTF-8")}"

intentCam.putExtra(C2paUtils.IDENTITY_URI_KEY, credUri)
}
else {
intentCam.putExtra(C2paUtils.IDENTITY_NAME_KEY, "0x" + mPgpUtils?.publicKeyString)
startActivity(intentCam)
}

var pgpUri =
"0x" + mPgpUtils?.publicKeyFingerprint + "@https://keys.openpgp.org/search?q=" + mPgpUtils?.publicKeyFingerprint
intentCam.putExtra(C2paUtils.IDENTITY_URI_KEY, pgpUri)
}
fun initContentCredentials () {
val email = mPrefs.getString(PREF_CREDENTIALS_PRIMARY,"");
var display : String? = null
var key : String? = "0x" + mPgpUtils?.publicKeyFingerprint
var uri : String? = null

intentCam.putExtra(PREF_OPTION_AI, mPrefs.getBoolean(PREF_OPTION_CREDENTIALS, PREF_OPTION_AI_DEFAULT));
if (email?.isNotEmpty() == true)
{
display = "${email.replace("@"," at ")}"
}

startActivity(intentCam)
uri =
"https://keys.openpgp.org/search?q=" + mPgpUtils?.publicKeyFingerprint

C2paUtils.setC2PAIdentity(display, uri, email, key)
}

fun initPgpKey () {
Expand All @@ -667,11 +663,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
mPrefs.getString(PREFS_KEY_PASSPHRASE, PREFS_KEY_PASSPHRASE_DEFAULT)
)

var identityName = "0x" + mPgpUtils?.publicKeyFingerprint
var identityUri = "0x" + mPgpUtils?.publicKeyFingerprint + "@https://keys.openpgp.org/search?q=" + mPgpUtils?.publicKeyFingerprint

//set identity based on passed strings
C2paUtils.setC2PAIdentity(identityName,identityUri)
initContentCredentials()

}
}
Expand Down

0 comments on commit b0317d6

Please sign in to comment.