Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ dependencies {
"gmsImplementation"(libs.google.play.review.ktx)
"gmsImplementation"(libs.google.play.app.update.ktx)
"gmsImplementation"("com.google.android.gms:play-services-location:21.1.0")
"gmsImplementation"("com.google.android.play:integrity:1.4.0")

// Tor
implementation(libs.tor.android)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.opendasharchive.openarchive.util

import android.content.Context
import java.io.File

object SafetyNetHelper {
// Play Integrity API requires GMS — not available on FOSS builds.
fun requestGst(context: Context, mediaHash: String, outFile: File) = Unit

Check warning

Code scanning / detekt

Function parameter is unused and should be removed. Warning

Function parameter context is unused.

Check warning

Code scanning / detekt

Function parameter is unused and should be removed. Warning

Function parameter mediaHash is unused.

Check warning

Code scanning / detekt

Function parameter is unused and should be removed. Warning

Function parameter outFile is unused.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.opendasharchive.openarchive.util

import android.content.Context

Check warning

Code scanning / detekt

Detects imports in non default order Warning

Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
import android.util.Base64
import com.google.android.play.core.integrity.IntegrityManagerFactory
import com.google.android.play.core.integrity.IntegrityTokenRequest
import com.google.android.gms.tasks.Tasks
import net.opendasharchive.openarchive.core.logger.AppLogger
import java.io.File

object SafetyNetHelper {
/**
* Requests a Play Integrity token and writes it as a JWT string to [outFile].
* No-op on network or API failure — outFile simply won't exist, and the caller
* skips it in the upload list.
*/
fun requestGst(context: Context, mediaHash: String, outFile: File) {
try {
val nonce = Base64.encodeToString(mediaHash.toByteArray(Charsets.UTF_8),

Check warning

Code scanning / detekt

Reports incorrect argument list wrapping Warning

Argument should be on a separate line (unless all arguments can fit a single line)

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning

Missing newline after "("
Base64.URL_SAFE or Base64.NO_WRAP)

Check warning

Code scanning / detekt

Reports missing newlines (e.g. between parentheses of a multi-line function call Warning

Missing newline before ")"

Check warning

Code scanning / detekt

Reports incorrect argument list wrapping Warning

Missing newline before ")"
val manager = IntegrityManagerFactory.create(context.applicationContext)
val request = IntegrityTokenRequest.builder().setNonce(nonce).build()
val response = Tasks.await(manager.requestIntegrityToken(request))
outFile.writeText(response.token())
AppLogger.i("[GST] Play Integrity token written for $mediaHash")
} catch (e: Exception) {

Check warning

Code scanning / detekt

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. Warning

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
AppLogger.w("[GST] Play Integrity request failed: ${e.message}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class CameraViewModel : ViewModel() {
if (signedFile != null) {
AppLogger.d("[C2PA] Proof embedded: ${signedFile.name}")
val hash = computeFileHash(signedFile)
if (hash.isNotEmpty()) ProofCompanionGenerator.generateLocalProof(context, signedFile, hash)
if (hash.isNotEmpty()) ProofCompanionGenerator.generateLocalProof(context, signedFile, hash, metadata)
} else {
AppLogger.w("[C2PA] Proof embedding skipped/failed for ${file.name}")
}
Expand All @@ -279,7 +279,7 @@ class CameraViewModel : ViewModel() {
if (signedFile != null) {
AppLogger.d("[C2PA] Proof embedded: ${signedFile.name}")
val hash = computeFileHash(signedFile)
if (hash.isNotEmpty()) ProofCompanionGenerator.generateLocalProof(context, signedFile, hash)
if (hash.isNotEmpty()) ProofCompanionGenerator.generateLocalProof(context, signedFile, hash, metadata)
} else {
AppLogger.w("[C2PA] Proof embedding skipped/failed for ${file.name}")
}
Expand Down
Loading
Loading