Commit 24f26da5 authored by narinder Rana's avatar narinder Rana Committed by Aayush Gupta
Browse files

Use JSON file in package

parent f9f3439b
...@@ -29,7 +29,6 @@ import android.util.Log ...@@ -29,7 +29,6 @@ import android.util.Log
import android.widget.Toast import android.widget.Toast
import foundation.e.apps.R import foundation.e.apps.R
import foundation.e.apps.api.FDroidAppExistsRequest import foundation.e.apps.api.FDroidAppExistsRequest
import foundation.e.apps.api.SystemAppExistsRequest
import foundation.e.apps.application.model.data.FullData import foundation.e.apps.application.model.data.FullData
import org.bouncycastle.jce.provider.BouncyCastleProvider import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.openpgp.PGPCompressedData import org.bouncycastle.openpgp.PGPCompressedData
...@@ -41,10 +40,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider ...@@ -41,10 +40,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.io.BufferedInputStream import java.io.*
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.security.MessageDigest import java.security.MessageDigest
import java.security.Security import java.security.Security
...@@ -62,7 +58,7 @@ class IntegrityVerificationTask( ...@@ -62,7 +58,7 @@ class IntegrityVerificationTask(
override fun doInBackground(vararg context: Context): Context { override fun doInBackground(vararg context: Context): Context {
try { try {
val packageName = getAPK_PackageName(context[0]) val packageName = getAPK_PackageName(context[0])
verificationSuccessful = if (isSystemApplication(packageName.toString())) { verificationSuccessful = if (isSystemApplication(context[0], packageName.toString())) {
verifyAPKSignature(context[0]) verifyAPKSignature(context[0])
} else if (isfDroidApplication(packageName.toString())) { } else if (isfDroidApplication(packageName.toString())) {
verifyFdroidSignature(context[0]) verifyFdroidSignature(context[0])
...@@ -176,21 +172,25 @@ class IntegrityVerificationTask( ...@@ -176,21 +172,25 @@ class IntegrityVerificationTask(
return fDroidAppExistsResponse == 200 return fDroidAppExistsResponse == 200
} }
private fun isSystemApplication(packageName: String): Boolean { fun loadJSONFromAsset(context: Context): String? {
var jsonResponse = "" var json: String? = null
SystemAppExistsRequest(packageName) json = try {
.request { applicationError, searchResult -> val inputStream: InputStream = context.getAssets().open("systemApp.json")
when (applicationError) { val size = inputStream.available()
null -> { val buffer = ByteArray(size)
if (searchResult.size > 0) { inputStream.read(buffer)
jsonResponse = searchResult[0].toString() inputStream.close()
} String(buffer, charset("UTF-8"))
} } catch (ex: IOException) {
else -> { ex.printStackTrace()
Log.e(TAG, applicationError.toString()) return null
} }
} return json
} }
private fun isSystemApplication(context: Context, packageName: String): Boolean {
var jsonResponse = loadJSONFromAsset(context)
try { try {
if (JSONObject(jsonResponse).has(packageName)) { if (JSONObject(jsonResponse).has(packageName)) {
systemJsonData = JSONObject(jsonResponse).getJSONObject(packageName) systemJsonData = JSONObject(jsonResponse).getJSONObject(packageName)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment