Commit 50e4f13c authored by narinder Rana's avatar narinder Rana
Browse files

ktlintFormat run

parent d3b72b31
Pipeline #131802 passed with stage
in 3 minutes and 35 seconds
......@@ -48,11 +48,10 @@ import java.io.InputStream
import java.security.MessageDigest
import java.security.Security
class IntegrityVerificationTask(
private val applicationInfo: ApplicationInfo,
private val fullData: FullData,
private val integrityVerificationCallback: IntegrityVerificationCallback
private val applicationInfo: ApplicationInfo,
private val fullData: FullData,
private val integrityVerificationCallback: IntegrityVerificationCallback
) :
AsyncTask<Context, Void, Context>() {
......@@ -60,8 +59,6 @@ class IntegrityVerificationTask(
private var verificationSuccessful: Boolean = false
private var TAG = "IntegrityVerificationTask"
override fun doInBackground(vararg context: Context): Context {
try {
verificationSuccessful = if (isSystemApplication(fullData.packageName)) {
......@@ -97,13 +94,13 @@ class IntegrityVerificationTask(
return false
}
//get signature from apk and check
// get signature from apk and check
private fun verifyAPKSignature(context: Context): Boolean {
//get Signature from APK
if (getAPKSignature(context)!=null) {
// get Signature from APK
if (getAPKSignature(context) != null) {
return getAPKSignature(context)?.toCharsString() ==
getSystemSignature(context.packageManager)?.toCharsString()
getSystemSignature(context.packageManager)?.toCharsString()
}
return false
}
......@@ -111,33 +108,31 @@ class IntegrityVerificationTask(
private fun getAPKSignature(context: Context): Signature? {
try {
val fullPath: String = applicationInfo.getApkFile(
context,
fullData.basicData
context,
fullData.basicData
).absolutePath
val releaseSig = context.packageManager.getPackageArchiveInfo(fullPath, PackageManager.GET_SIGNATURES)
return getFirstSignature(releaseSig)
} catch (e: PackageManager.NameNotFoundException) {
Log.d(TAG, "Unable to find the package: android")
}
return null
}
private fun verifySystemValues(context: Context): Boolean {
val pm: PackageManager = context.packageManager
val fullPath: String = applicationInfo.getApkFile(
context,
fullData.basicData
context,
fullData.basicData
).absolutePath
val info = pm.getPackageArchiveInfo(fullPath, 0)
if (info != null) {
Log.e("TAG", ".................." + info.packageName)
Log.e("TAG", ".................." + info.signatures)
}
return false;
return false
}
private fun getFirstSignature(pkg: PackageInfo?): Signature? {
......@@ -159,17 +154,17 @@ class IntegrityVerificationTask(
private fun verifyFdroidSignature(context: Context): Boolean {
Security.addProvider(BouncyCastleProvider())
return verifyAPKSignature(
context,
BufferedInputStream(
FileInputStream(
applicationInfo.getApkFile(
context,
fullData.basicData
).absolutePath
)
),
fullData.getLastVersion()!!.signature.byteInputStream(Charsets.UTF_8),
context.assets.open("f-droid.org-signing-key.gpg")
context,
BufferedInputStream(
FileInputStream(
applicationInfo.getApkFile(
context,
fullData.basicData
).absolutePath
)
),
fullData.getLastVersion()!!.signature.byteInputStream(Charsets.UTF_8),
context.assets.open("f-droid.org-signing-key.gpg")
)
}
......@@ -207,14 +202,13 @@ class IntegrityVerificationTask(
}
}
try {
if(JSONObject(jsonResponse).has(packageName)){
systemJsonData = JSONObject(jsonResponse).getJSONObject(packageName);
if (JSONObject(jsonResponse).has(packageName)) {
systemJsonData = JSONObject(jsonResponse).getJSONObject(packageName)
return true
}
else{
} else {
return false
}
// return JSONObject(jsonResponse).has(packageName);
// return JSONObject(jsonResponse).has(packageName);
} catch (e: Exception) {
if (e is JSONException) {
Log.d(TAG, "$packageName is not a system application")
......@@ -253,10 +247,10 @@ class IntegrityVerificationTask(
}
private fun verifyAPKSignature(
context: Context,
apkInputStream: BufferedInputStream,
apkSignatureInputStream: InputStream,
publicKeyInputStream: InputStream
context: Context,
apkInputStream: BufferedInputStream,
apkSignatureInputStream: InputStream,
publicKeyInputStream: InputStream
): Boolean {
try {
......@@ -274,8 +268,8 @@ class IntegrityVerificationTask(
val pgpPublicKeyRingCollection =
PGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(publicKeyInputStream),
JcaKeyFingerprintCalculator()
PGPUtil.getDecoderStream(publicKeyInputStream),
JcaKeyFingerprintCalculator()
)
val signature = pgpSignatureList.get(0)
......
......@@ -71,6 +71,6 @@ object Constants {
// Integrity Verification
const val F_DROID_PACKAGES_URL = "https://f-droid.org/en/packages/"
//const val SYSTEM_PACKAGES_JSON_FILE_URL = "https://gitlab.e.foundation/e/apps/apps/-/raw/e169c1905114d97af867b051f96c38166f4782e2/app/src/main/assets/systemApp.json"
// const val SYSTEM_PACKAGES_JSON_FILE_URL = "https://gitlab.e.foundation/e/apps/apps/-/raw/e169c1905114d97af867b051f96c38166f4782e2/app/src/main/assets/systemApp.json"
const val SYSTEM_PACKAGES_JSON_FILE_URL = "https://gitlab.e.foundation/e/apps/apps/-/raw/issue-3328JSON/app/src/main/assets/systemApp.json"
}
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