-
-
Notifications
You must be signed in to change notification settings - Fork 351
feat: implement APK signing fingerprint verification and improve Shiz… #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
19d1635
95b7a94
e27f25e
ec79ce7
64dc2d5
b25bb34
a613a0f
f5e0de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package zed.rainxch.core.data.local.db.migrations | ||
|
|
||
| import androidx.room.migration.Migration | ||
| import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
|
||
| val MIGRATION_4_5 = | ||
| object : Migration(4, 5) { | ||
| override fun migrate(db: SupportSQLiteDatabase) { | ||
| db.execSQL("ALTER TABLE installed_apps ADD COLUMN signingFingerprint TEXT") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ package zed.rainxch.core.data.services | |
| import android.content.Context | ||
| import android.content.pm.ApplicationInfo | ||
| import android.content.pm.PackageManager | ||
| import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES | ||
| import android.os.Build | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
| import zed.rainxch.core.domain.model.DeviceApp | ||
| import zed.rainxch.core.domain.model.SystemPackageInfo | ||
| import zed.rainxch.core.domain.system.PackageMonitor | ||
| import java.security.MessageDigest | ||
|
|
||
| class AndroidPackageMonitor( | ||
| context: Context, | ||
|
|
@@ -20,12 +22,23 @@ class AndroidPackageMonitor( | |
| override suspend fun getInstalledPackageInfo(packageName: String): SystemPackageInfo? = | ||
| withContext(Dispatchers.IO) { | ||
| runCatching { | ||
| val flags = | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
| GET_SIGNING_CERTIFICATES.toLong() | ||
| } else { | ||
| @Suppress("DEPRECATION") | ||
| PackageManager.GET_SIGNATURES.toLong() | ||
| } | ||
|
|
||
| val packageInfo = | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
| packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0L)) | ||
| packageManager.getPackageInfo( | ||
| packageName, | ||
| PackageManager.PackageInfoFlags.of(flags), | ||
| ) | ||
| } else { | ||
| @Suppress("DEPRECATION") | ||
| packageManager.getPackageInfo(packageName, 0) | ||
| packageManager.getPackageInfo(packageName, flags.toInt()) | ||
| } | ||
|
|
||
| val versionCode = | ||
|
|
@@ -36,11 +49,37 @@ class AndroidPackageMonitor( | |
| packageInfo.versionCode.toLong() | ||
| } | ||
|
|
||
| val signingFingerprint: String? = | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
| val sigInfo = packageInfo.signingInfo | ||
| val certs = | ||
| if (sigInfo?.hasMultipleSigners() == true) { | ||
| sigInfo.apkContentsSigners | ||
| } else { | ||
| sigInfo?.signingCertificateHistory | ||
| } | ||
| certs?.firstOrNull()?.toByteArray()?.let { certBytes -> | ||
| MessageDigest | ||
| .getInstance("SHA-256") | ||
| .digest(certBytes) | ||
| .joinToString(":") { "%02X".format(it) } | ||
| } | ||
| } else { | ||
| @Suppress("DEPRECATION") | ||
| packageInfo.signatures?.firstOrNull()?.toByteArray()?.let { certBytes -> | ||
| MessageDigest | ||
| .getInstance("SHA-256") | ||
| .digest(certBytes) | ||
| .joinToString(":") { "%02X".format(it) } | ||
| } | ||
| } | ||
|
Comment on lines
+52
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result:
Sources: Android Use the current signer from On API 28+, 🤖 Prompt for AI Agents |
||
|
|
||
| SystemPackageInfo( | ||
| packageName = packageInfo.packageName, | ||
| versionName = packageInfo.versionName ?: "unknown", | ||
| versionCode = versionCode, | ||
| isInstalled = true, | ||
| signingFingerprint = signingFingerprint, | ||
| ) | ||
| }.getOrNull() | ||
| } | ||
|
|
@@ -70,12 +109,10 @@ class AndroidPackageMonitor( | |
|
|
||
| packages | ||
| .filter { pkg -> | ||
| // Exclude system apps (keep user-installed + updated system apps) | ||
| val isSystemApp = (pkg.applicationInfo?.flags ?: 0) and ApplicationInfo.FLAG_SYSTEM != 0 | ||
| val isUpdatedSystem = (pkg.applicationInfo?.flags ?: 0) and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0 | ||
| !isSystemApp || isUpdatedSystem | ||
| } | ||
| .map { pkg -> | ||
| }.map { pkg -> | ||
| val versionCode = | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
| pkg.longVersionCode | ||
|
|
@@ -89,8 +126,8 @@ class AndroidPackageMonitor( | |
| appName = pkg.applicationInfo?.loadLabel(packageManager)?.toString() ?: pkg.packageName, | ||
| versionName = pkg.versionName, | ||
| versionCode = versionCode, | ||
| signingFingerprint = null, | ||
| ) | ||
| } | ||
| .sortedBy { it.appName.lowercase() } | ||
| }.sortedBy { it.appName.lowercase() } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OpenHub-Store/GitHub-Store
Length of output: 73
🏁 Script executed:
Repository: OpenHub-Store/GitHub-Store
Length of output: 373
🏁 Script executed:
Repository: OpenHub-Store/GitHub-Store
Length of output: 1000
MIGRATION_4_5 file is missing but referenced in the code.
The import at line 9 and the reference at line 23 use
MIGRATION_4_5, but the file does not exist incore/data/src/androidMain/kotlin/zed/rainxch/core/data/local/db/migrations/. OnlyMIGRATION_1_2.kt,MIGRATION_2_3.kt, andMIGRATION_3_4.ktare present. Create theMIGRATION_4_5.ktfile with the database schema changes for adding thesigningFingerprintcolumn.🤖 Prompt for AI Agents