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