0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-22 19:25:11 +00:00

Revert "new signature checking method"

This commit is contained in:
Xinto 2020-10-02 22:21:28 +04:00
parent 46978f2f6f
commit f3356f1044
3 changed files with 4 additions and 61 deletions

View file

@ -1,6 +1,7 @@
package com.vanced.manager.model package com.vanced.manager.model
import android.content.Context import android.content.Context
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -10,7 +11,6 @@ import androidx.databinding.ObservableInt
import com.beust.klaxon.JsonObject import com.beust.klaxon.JsonObject
import com.vanced.manager.BuildConfig.ENABLE_SIGNATURE_CHECK import com.vanced.manager.BuildConfig.ENABLE_SIGNATURE_CHECK
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.AppUtils.doSignaturesMatch
import com.vanced.manager.utils.AppUtils.managerPkg import com.vanced.manager.utils.AppUtils.managerPkg
import com.vanced.manager.utils.AppUtils.vancedRootPkg import com.vanced.manager.utils.AppUtils.vancedRootPkg
import com.vanced.manager.utils.PackageHelper.isPackageInstalled import com.vanced.manager.utils.PackageHelper.isPackageInstalled
@ -37,9 +37,9 @@ open class DataModel(
fun fetch() = CoroutineScope(Dispatchers.IO).launch { fun fetch() = CoroutineScope(Dispatchers.IO).launch {
isAppInstalled.set(isPackageInstalled(appPkg, context.packageManager)) isAppInstalled.set(isPackageInstalled(appPkg, context.packageManager))
isOfficial.set(doSignaturesMatch(managerPkg, appPkg, context))
versionName.set(jsonObject.get()?.string("version")?.removeSuffix("-vanced") ?: context.getString(R.string.unavailable)) versionName.set(jsonObject.get()?.string("version")?.removeSuffix("-vanced") ?: context.getString(R.string.unavailable))
installedVersionName.set(getPkgVersionName(isAppInstalled.get(), appPkg)) installedVersionName.set(getPkgVersionName(isAppInstalled.get(), appPkg))
isOfficial.set(doSignaturesMatch(managerPkg, appPkg))
versionCode.set(jsonObject.get()?.int("versionCode") ?: 0) versionCode.set(jsonObject.get()?.int("versionCode") ?: 0)
installedVersionCode.set(getPkgVersionCode(isAppInstalled.get(), appPkg)) installedVersionCode.set(getPkgVersionCode(isAppInstalled.get(), appPkg))
buttonTxt.set(compareInt(installedVersionCode.get(), versionCode.get())) buttonTxt.set(compareInt(installedVersionCode.get(), versionCode.get()))
@ -55,7 +55,7 @@ open class DataModel(
val pm = context.packageManager val pm = context.packageManager
return if (toCheck) { return if (toCheck) {
if (ENABLE_SIGNATURE_CHECK) { if (ENABLE_SIGNATURE_CHECK) {
if (isOfficial.get() || appPkg == vancedRootPkg) if (doSignaturesMatch(managerPkg, pkg) || appPkg == vancedRootPkg)
pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced") pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced")
else else
pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced") + " (${context.getString(R.string.unofficial)})" pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced") + " (${context.getString(R.string.unofficial)})"
@ -66,15 +66,12 @@ open class DataModel(
} }
} }
/*
private fun doSignaturesMatch(pkg1: String, pkg2: String): Boolean = private fun doSignaturesMatch(pkg1: String, pkg2: String): Boolean =
if (isPackageInstalled(pkg2, context.packageManager)) if (isPackageInstalled(pkg2, context.packageManager))
context.packageManager.checkSignatures(pkg1, pkg2) == PackageManager.SIGNATURE_MATCH context.packageManager.checkSignatures(pkg1, pkg2) == PackageManager.SIGNATURE_MATCH
else else
true true
*/
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private fun getPkgVersionCode(toCheck: Boolean, pkg: String): Int { private fun getPkgVersionCode(toCheck: Boolean, pkg: String): Int {
return if (toCheck) { return if (toCheck) {

View file

@ -1,5 +1,6 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle

View file

@ -1,11 +1,8 @@
package com.vanced.manager.utils package com.vanced.manager.utils
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageInstaller import android.content.pm.PackageInstaller
import android.content.pm.PackageManager
import android.os.Build
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
@ -16,7 +13,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.security.MessageDigest
object AppUtils { object AppUtils {
@ -59,57 +55,6 @@ object AppUtils {
} }
} }
fun doSignaturesMatch(pkg1: String, pkg2: String, context: Context): Boolean {
val apk1sig = getApplicationSignature(pkg1, context)
val apk2sig = getApplicationSignature(pkg2, context)
return apk2sig.containsAll(apk1sig)
}
@SuppressLint("PackageManagerGetSignatures")
fun getApplicationSignature(packageName: String, context: Context): List<String> {
val signatureList: List<String>
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val sig = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES).signingInfo
signatureList = if (sig.hasMultipleSigners()) {
sig.apkContentsSigners.map {
val msgDigest = MessageDigest.getInstance("SHA")
msgDigest.update(it.toByteArray())
bytesToHex(msgDigest.digest())
}
} else {
sig.signingCertificateHistory.map {
val msgDigest = MessageDigest.getInstance("SHA")
msgDigest.update(it.toByteArray())
bytesToHex(msgDigest.digest())
}
}
} else {
val sig = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures
signatureList = sig.map {
val msgDigest = MessageDigest.getInstance("SHA")
msgDigest.update(it.toByteArray())
bytesToHex(msgDigest.digest())
}
}
signatureList
} catch (e: Exception) {
emptyList()
}
}
private fun bytesToHex(bytes: ByteArray): String {
val hexArray = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
val hexChars = CharArray(bytes.size * 2)
var v: Int
for (j in bytes.indices) {
v = bytes[j].toInt() and 0xFF
hexChars[j * 2] = hexArray[v.ushr(4)]
hexChars[j * 2 + 1] = hexArray[v and 0x0F]
}
return String(hexChars)
}
private fun getErrorMessage(status: String, context: Context): String { private fun getErrorMessage(status: String, context: Context): String {
return when { return when {
status.contains("INSTALL_FAILED_ABORTED") -> context.getString(R.string.installation_aborted) status.contains("INSTALL_FAILED_ABORTED") -> context.getString(R.string.installation_aborted)