From aa6bfad801aec11c25315aaa508172d1b0eaf4a6 Mon Sep 17 00:00:00 2001 From: Tad Date: Sat, 15 Jul 2023 09:54:16 -0400 Subject: [PATCH] Various - Drop OpenCamera, it doesn't work on lock screens anymore? - microG on 18.1+: - set packages forceQueryable - spoof some sources as Play Store TODO: backport this to 17.1 - Remove camera extensions - Churn - Wording Signed-off-by: Tad --- .../build/target/product/lowram.mk | 9 +- .../android_vendor_divested/packages.mk | 8 +- ...> 0021-Unprivileged_microG_Handling.patch} | 6 +- ..._toggle.patch => 0014-microG_Toggle.patch} | 2 +- .../360973-backport-prereq.patch | 13 +- .../360973-backport.patch | 39 +++--- ...> 0024-Unprivileged_microG_Handling.patch} | 109 ++++++++++++++--- ..._toggle.patch => 0015-microG_Toggle.patch} | 2 +- ...> 0031-Unprivileged_microG_Handling.patch} | 112 +++++++++++++++-- ..._toggle.patch => 0016-microG_Toggle.patch} | 2 +- ...> 0036-Unprivileged_microG_Handling.patch} | 114 +++++++++++++++--- ..._toggle.patch => 0016-microG_Toggle.patch} | 2 +- Patches/Linux | 2 +- PrebuiltApps | 2 +- Scripts/Common/Deblob.sh | 3 +- Scripts/LineageOS-17.1/Patch.sh | 6 +- Scripts/LineageOS-18.1/Patch.sh | 4 +- Scripts/LineageOS-19.1/Patch.sh | 5 +- Scripts/LineageOS-20.0/Patch.sh | 4 +- Scripts/init.sh | 2 +- 20 files changed, 344 insertions(+), 102 deletions(-) rename Patches/LineageOS-17.1/android_frameworks_base/{0021-Hardened-signature-spoofing.patch => 0021-Unprivileged_microG_Handling.patch} (97%) rename Patches/LineageOS-17.1/android_packages_apps_Settings/{0014-signature_spoofing_toggle.patch => 0014-microG_Toggle.patch} (99%) rename Patches/LineageOS-18.1/android_frameworks_base/{0024-Hardened-signature-spoofing.patch => 0024-Unprivileged_microG_Handling.patch} (59%) rename Patches/LineageOS-18.1/android_packages_apps_Settings/{0015-signature_spoofing_toggle.patch => 0015-microG_Toggle.patch} (99%) rename Patches/LineageOS-19.1/android_frameworks_base/{0031-Hardened-signature-spoofing.patch => 0031-Unprivileged_microG_Handling.patch} (58%) rename Patches/LineageOS-19.1/android_packages_apps_Settings/{0016-signature_spoofing_toggle.patch => 0016-microG_Toggle.patch} (99%) rename Patches/LineageOS-20.0/android_frameworks_base/{0036-Hardened-signature-spoofing.patch => 0036-Unprivileged_microG_Handling.patch} (72%) rename Patches/LineageOS-20.0/android_packages_apps_Settings/{0016-signature_spoofing_toggle.patch => 0016-microG_Toggle.patch} (99%) diff --git a/Patches/Common/android_vendor_divested/build/target/product/lowram.mk b/Patches/Common/android_vendor_divested/build/target/product/lowram.mk index f39ea7a3..9071129f 100644 --- a/Patches/Common/android_vendor_divested/build/target/product/lowram.mk +++ b/Patches/Common/android_vendor_divested/build/target/product/lowram.mk @@ -28,8 +28,8 @@ PRODUCT_PROPERTY_OVERRIDES += \ ro.lmk.kill_heaviest_task=false \ config.disable_atlas=true \ dalvik.vm.madvise-random=true \ - ro.statsd.enable=false \ - persist.traced.enable=0 + persist.traced.enable=0 \ + ro.statsd.enable=false # set threshold to filter unused apps PRODUCT_PROPERTY_OVERRIDES += pm.dexopt.downgrade_after_inactive_days=10 @@ -52,11 +52,6 @@ PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK := true PRODUCT_PROPERTY_OVERRIDES += \ pm.dexopt.shared=quicken -# Default heap sizes. Allow up to 256m for large heaps to make sure a single app -# doesn't take all of the RAM. -#PRODUCT_PROPERTY_OVERRIDES += dalvik.vm.heapgrowthlimit=128m -#PRODUCT_PROPERTY_OVERRIDES += dalvik.vm.heapsize=256m - # Do not generate libartd. PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD := false diff --git a/Patches/Common/android_vendor_divested/packages.mk b/Patches/Common/android_vendor_divested/packages.mk index d59c8614..a094372f 100644 --- a/Patches/Common/android_vendor_divested/packages.mk +++ b/Patches/Common/android_vendor_divested/packages.mk @@ -8,10 +8,10 @@ PRODUCT_PACKAGES += \ FennecDOS \ SimpleGallery -ifeq ($(findstring flox,$(TARGET_PRODUCT)),) -PRODUCT_PACKAGES += \ - OpenCamera -endif +#ifeq ($(findstring flox,$(TARGET_PRODUCT)),) +#PRODUCT_PACKAGES += \ +# OpenCamera +#endif # Extras PRODUCT_PACKAGES += \ diff --git a/Patches/LineageOS-17.1/android_frameworks_base/0021-Hardened-signature-spoofing.patch b/Patches/LineageOS-17.1/android_frameworks_base/0021-Unprivileged_microG_Handling.patch similarity index 97% rename from Patches/LineageOS-17.1/android_frameworks_base/0021-Hardened-signature-spoofing.patch rename to Patches/LineageOS-17.1/android_frameworks_base/0021-Unprivileged_microG_Handling.patch index 75ce1135..5ac3fee9 100644 --- a/Patches/LineageOS-17.1/android_frameworks_base/0021-Hardened-signature-spoofing.patch +++ b/Patches/LineageOS-17.1/android_frameworks_base/0021-Unprivileged_microG_Handling.patch @@ -1,12 +1,13 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tad Date: Mon, 3 Jul 2023 12:00:12 -0400 -Subject: [PATCH] Hardened signature spoofing +Subject: [PATCH] Unprivileged microG handling - Must be enabled by user - Must match microG package ID - Must meet minimum respective targetSdk and versionCode - Must match official microG build signing key + - Only spoofs the Google package signature This is an effective merge + tweak of two existing patches, credits: @@ -14,6 +15,7 @@ This is an effective merge + tweak of two existing patches, credits: https://github.com/dylangerdaly/platform_frameworks_base/commit/b58aa11631fadab3309a1d9268118bd9f2c2a79f Chirayu Desai of CalyxOS https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/76485abb36dc01b65506b010d0458e96e0116369 + https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/97765782f942d0975c383c90fde9140ef3ccf01b Change-Id: I64a252aac9bb196a11ed7b4b5d8c7e59a3413bd4 --- @@ -120,7 +122,7 @@ index 9483f266b1fa..eb2b66d5ce03 100644 + Set permissions) { + String hash = p.mSigningDetails.getSha256Certificate(); + try { -+ if (hash.equals(MICROG_HASH) && p.applicationInfo.targetSdkVersion >= 24) { ++ if (hash.equals(MICROG_HASH) && p.applicationInfo.targetSdkVersion >= 24 && pi != null) { + pi.signatures = new Signature[] {new Signature(GOOGLE_CERT)}; + if (DEBUG_PACKAGE_INFO) { + Log.v(TAG, "Spoofing signature for microG"); diff --git a/Patches/LineageOS-17.1/android_packages_apps_Settings/0014-signature_spoofing_toggle.patch b/Patches/LineageOS-17.1/android_packages_apps_Settings/0014-microG_Toggle.patch similarity index 99% rename from Patches/LineageOS-17.1/android_packages_apps_Settings/0014-signature_spoofing_toggle.patch rename to Patches/LineageOS-17.1/android_packages_apps_Settings/0014-microG_Toggle.patch index fa2b8308..be669686 100644 --- a/Patches/LineageOS-17.1/android_packages_apps_Settings/0014-signature_spoofing_toggle.patch +++ b/Patches/LineageOS-17.1/android_packages_apps_Settings/0014-microG_Toggle.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tad Date: Wed, 20 Apr 2022 01:04:27 -0400 -Subject: [PATCH] Add a toggle to opt-in to restricted signature spoofing +Subject: [PATCH] Add a toggle for microG enablement Copy and pasted from the GrapheneOS exec spawning toggle patch diff --git a/Patches/LineageOS-17.1/android_tools_apksig/360973-backport-prereq.patch b/Patches/LineageOS-17.1/android_tools_apksig/360973-backport-prereq.patch index 5194e448..991516c9 100644 --- a/Patches/LineageOS-17.1/android_tools_apksig/360973-backport-prereq.patch +++ b/Patches/LineageOS-17.1/android_tools_apksig/360973-backport-prereq.patch @@ -1,7 +1,7 @@ -From 011adec1a494974102930bf65a8d2fdfa8b375b5 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Khaled Abdelmohsen Date: Mon, 24 Feb 2020 16:59:21 +0000 -Subject: [PATCH 1/2] Create source stamp verifier +Subject: [PATCH] Create source stamp verifier Bug: 148005911 Test: gradlew test @@ -13,10 +13,10 @@ Merged-In: I7008c9567ad5e8b63e7f6ba192d38b10c5c9a2dc 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java b/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java -index 2330f6d..f15597b 100644 +index cc69af3..bc3ae48 100644 --- a/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java +++ b/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java -@@ -998,6 +998,20 @@ public class ApkSigningBlockUtils { +@@ -1236,6 +1236,20 @@ public class ApkSigningBlockUtils { return false; } @@ -37,7 +37,7 @@ index 2330f6d..f15597b 100644 public void addError(ApkVerifier.Issue msg, Object... parameters) { mErrors.add(new ApkVerifier.IssueWithParams(msg, parameters)); } -@@ -1042,6 +1056,10 @@ public class ApkSigningBlockUtils { +@@ -1280,6 +1294,10 @@ public class ApkSigningBlockUtils { return !mErrors.isEmpty(); } @@ -48,6 +48,3 @@ index 2330f6d..f15597b 100644 public List getErrors() { return mErrors; } --- -2.30.2 - diff --git a/Patches/LineageOS-17.1/android_tools_apksig/360973-backport.patch b/Patches/LineageOS-17.1/android_tools_apksig/360973-backport.patch index ef02af06..52f229e6 100644 --- a/Patches/LineageOS-17.1/android_tools_apksig/360973-backport.patch +++ b/Patches/LineageOS-17.1/android_tools_apksig/360973-backport.patch @@ -1,7 +1,7 @@ -From 9a80527425030dae7f962ab95eda500a720cde47 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Michael Groover Date: Fri, 31 Mar 2023 14:30:21 -0500 -Subject: [PATCH 2/2] Limit the number of supported v1 and v2 signers +Subject: [PATCH] Limit the number of supported v1 and v2 signers The v1 and v2 APK Signature Schemes support multiple signers; this was intended to allow multiple entities to sign an APK. Previously, @@ -36,10 +36,10 @@ Change-Id: I604ce656e6dcd750e664adcb814c5c66f7b80ce1 create mode 100644 src/test/resources/com/android/apksig/v2-only-11-signers.apk diff --git a/src/main/java/com/android/apksig/ApkVerifier.java b/src/main/java/com/android/apksig/ApkVerifier.java -index 5e458ef..62b132a 100644 +index 3e1e7da..cfbc8d2 100644 --- a/src/main/java/com/android/apksig/ApkVerifier.java +++ b/src/main/java/com/android/apksig/ApkVerifier.java -@@ -620,6 +620,15 @@ public class ApkVerifier { +@@ -644,6 +644,15 @@ public class ApkVerifier { } private void mergeFrom(ApkSigningBlockUtils.Result source) { @@ -55,7 +55,7 @@ index 5e458ef..62b132a 100644 switch (source.signatureSchemeVersion) { case ApkSigningBlockUtils.VERSION_APK_SIGNATURE_SCHEME_V2: mVerifiedUsingV2Scheme = source.verified; -@@ -897,6 +906,16 @@ public class ApkVerifier { +@@ -921,6 +930,16 @@ public class ApkVerifier { */ JAR_SIG_NO_SIGNATURES("No JAR signatures"), @@ -72,7 +72,7 @@ index 5e458ef..62b132a 100644 /** * APK does not contain any entries covered by JAR signatures. */ -@@ -1325,6 +1344,16 @@ public class ApkVerifier { +@@ -1349,6 +1368,16 @@ public class ApkVerifier { "APK Signature Scheme v2 signature %1$s indicates the APK is signed using %2$s but " + "no such signature was found. Signature stripped?"), @@ -111,7 +111,7 @@ index f900211..05721ed 100644 generateManifestFile( jarEntryDigestAlgorithm, jarEntryDigests, sourceManifestBytes); diff --git a/src/main/java/com/android/apksig/internal/apk/v1/V1SchemeVerifier.java b/src/main/java/com/android/apksig/internal/apk/v1/V1SchemeVerifier.java -index a828bcc..8e49dd3 100644 +index 47d5b01..d633514 100644 --- a/src/main/java/com/android/apksig/internal/apk/v1/V1SchemeVerifier.java +++ b/src/main/java/com/android/apksig/internal/apk/v1/V1SchemeVerifier.java @@ -16,6 +16,7 @@ @@ -122,7 +122,7 @@ index a828bcc..8e49dd3 100644 import com.android.apksig.ApkVerifier.Issue; import com.android.apksig.ApkVerifier.IssueWithParams; import com.android.apksig.apk.ApkFormatException; -@@ -249,6 +250,7 @@ public abstract class V1SchemeVerifier { +@@ -275,6 +276,7 @@ public abstract class V1SchemeVerifier { // * All JAR entries listed in JAR manifest are present in the APK. // Identify signers @@ -130,7 +130,7 @@ index a828bcc..8e49dd3 100644 List signers = new ArrayList<>(sigBlockEntries.size()); for (CentralDirectoryRecord sigBlockEntry : sigBlockEntries) { String sigBlockEntryName = sigBlockEntry.getName(); -@@ -277,6 +279,11 @@ public abstract class V1SchemeVerifier { +@@ -303,6 +305,11 @@ public abstract class V1SchemeVerifier { result.addError(Issue.JAR_SIG_NO_SIGNATURES); return; } @@ -143,10 +143,10 @@ index a828bcc..8e49dd3 100644 // Verify each signer's signature block file .(RSA|DSA|EC) against the corresponding // signature file .SF. Any error encountered for any signer terminates verification, to diff --git a/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeSigner.java b/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeSigner.java -index 6d001e7..375ff91 100644 +index d8e4723..a423bdd 100644 --- a/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeSigner.java +++ b/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeSigner.java -@@ -161,6 +161,12 @@ public abstract class V2SchemeSigner { +@@ -162,6 +162,12 @@ public abstract class V2SchemeSigner { throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { // FORMAT: // * length-prefixed sequence of length-prefixed signer blocks. @@ -160,10 +160,10 @@ index 6d001e7..375ff91 100644 List signerBlocks = new ArrayList<>(signerConfigs.size()); int signerNumber = 0; diff --git a/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeVerifier.java b/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeVerifier.java -index e1be06e..39b205b 100644 +index 51c40bd..e3e7e8d 100644 --- a/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeVerifier.java +++ b/src/main/java/com/android/apksig/internal/apk/v2/V2SchemeVerifier.java -@@ -180,6 +180,7 @@ public abstract class V2SchemeVerifier { +@@ -184,6 +184,7 @@ public abstract class V2SchemeVerifier { int maxSdkVersion, ApkSigningBlockUtils.Result result) throws NoSuchAlgorithmException { ByteBuffer signers; @@ -171,7 +171,7 @@ index e1be06e..39b205b 100644 try { signers = ApkSigningBlockUtils.getLengthPrefixedSlice(apkSignatureSchemeV2Block); } catch (ApkFormatException e) { -@@ -221,6 +222,9 @@ public abstract class V2SchemeVerifier { +@@ -225,6 +226,9 @@ public abstract class V2SchemeVerifier { return; } } @@ -182,10 +182,10 @@ index e1be06e..39b205b 100644 /** diff --git a/src/test/java/com/android/apksig/ApkSignerTest.java b/src/test/java/com/android/apksig/ApkSignerTest.java -index 80f35ba..ccdb02a 100644 +index 1434017..729d96f 100644 --- a/src/test/java/com/android/apksig/ApkSignerTest.java +++ b/src/test/java/com/android/apksig/ApkSignerTest.java -@@ -339,6 +339,106 @@ public class ApkSignerTest { +@@ -635,6 +635,106 @@ public class ApkSignerTest { } catch (ApkFormatException expected) {} } @@ -293,7 +293,7 @@ index 80f35ba..ccdb02a 100644 public void testWeirdZipCompressionMethod() throws Exception { // Any ZIP compression method other than STORED is treated as DEFLATED by Android. diff --git a/src/test/java/com/android/apksig/ApkVerifierTest.java b/src/test/java/com/android/apksig/ApkVerifierTest.java -index 6f6c04d..0546f0f 100644 +index 351d0a8..2392b88 100644 --- a/src/test/java/com/android/apksig/ApkVerifierTest.java +++ b/src/test/java/com/android/apksig/ApkVerifierTest.java @@ -239,6 +239,20 @@ public class ApkVerifierTest { @@ -317,7 +317,7 @@ index 6f6c04d..0546f0f 100644 @Test public void testV2StrippedRejected() throws Exception { // APK signed with v1 and v2 schemes, but v2 signature was stripped from the file (by using -@@ -471,6 +485,23 @@ public class ApkVerifierTest { +@@ -630,6 +644,23 @@ public class ApkVerifierTest { Issue.V2_SIG_NO_SUPPORTED_SIGNATURES); } @@ -1442,6 +1442,3 @@ Tg9RFHk9CIzHQe49++O|{heuzh literal 0 HcmV?d00001 --- -2.30.2 - diff --git a/Patches/LineageOS-18.1/android_frameworks_base/0024-Hardened-signature-spoofing.patch b/Patches/LineageOS-18.1/android_frameworks_base/0024-Unprivileged_microG_Handling.patch similarity index 59% rename from Patches/LineageOS-18.1/android_frameworks_base/0024-Hardened-signature-spoofing.patch rename to Patches/LineageOS-18.1/android_frameworks_base/0024-Unprivileged_microG_Handling.patch index 336d900c..3c6501d6 100644 --- a/Patches/LineageOS-18.1/android_frameworks_base/0024-Hardened-signature-spoofing.patch +++ b/Patches/LineageOS-18.1/android_frameworks_base/0024-Unprivileged_microG_Handling.patch @@ -1,26 +1,32 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tad Date: Mon, 3 Jul 2023 12:00:12 -0400 -Subject: [PATCH] Hardened signature spoofing +Subject: [PATCH] Unprivileged microG handling - Must be enabled by user - Must match microG package ID - Must meet minimum respective targetSdk and versionCode - Must match official microG build signing key + - Only spoofs the Google package signature +- Sets the packages forceQueryable +- Spoofs apps installed via some sources as Play Store This is an effective merge + tweak of two existing patches, credits: Dylanger Daly https://github.com/dylangerdaly/platform_frameworks_base/commit/b58aa11631fadab3309a1d9268118bd9f2c2a79f Chirayu Desai of CalyxOS https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/76485abb36dc01b65506b010d0458e96e0116369 + https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/97765782f942d0975c383c90fde9140ef3ccf01b + https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/d81763383588e81353e24ad0a56ae2478752319c Change-Id: I64a252aac9bb196a11ed7b4b5d8c7e59a3413bd4 --- - .../android/content/pm/PackageParser.java | 32 +++++++++++++++ + .../android/content/pm/PackageParser.java | 32 +++++++++++ core/res/res/values/config.xml | 2 + - .../server/pm/PackageManagerService.java | 39 ++++++++++++++++++- - 3 files changed, 71 insertions(+), 2 deletions(-) + .../com/android/server/pm/AppsFilter.java | 19 +++++++ + .../server/pm/PackageManagerService.java | 57 ++++++++++++++++++- + 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index c63fea6e3e0e..a9e49921efba 100644 @@ -78,8 +84,56 @@ index f4efcc7e4eec..584b3011b0c6 100644 +diff --git a/services/core/java/com/android/server/pm/AppsFilter.java b/services/core/java/com/android/server/pm/AppsFilter.java +index 10f77144e022..eaa6bbb58679 100644 +--- a/services/core/java/com/android/server/pm/AppsFilter.java ++++ b/services/core/java/com/android/server/pm/AppsFilter.java +@@ -39,6 +39,7 @@ import android.os.Handler; + import android.os.HandlerExecutor; + import android.os.HandlerThread; + import android.os.Process; ++import android.os.SystemProperties; + import android.os.Trace; + import android.os.UserHandle; + import android.provider.DeviceConfig; +@@ -540,6 +541,15 @@ public class AppsFilter { + } + } + ++ // Package IDs of apps ++ private static final String PACKAGE_GMSCORE = "com.google.android.gms"; ++ private static final String PACKAGE_PLAY_STORE = "com.android.vending"; ++ private static final String PACKAGE_GSFPROXY = "com.google.android.gsf"; ++ // The setting to control microG enablement. ++ private static final String MICROG_ENABLEMENT = "persist.security.sigspoof"; ++ // The signing key hash of official microG builds. ++ private static final String MICROG_HASH = "9BD06727E62796C0130EB6DAB39B73157451582CBD138E86C468ACC395D14165"; ++ + private void addPackageInternal(PackageSetting newPkgSetting, + ArrayMap existingSettings) { + if (Objects.equals("android", newPkgSetting.name)) { +@@ -564,10 +574,19 @@ public class AppsFilter { + mQueriesViaComponentRequireRecompute = true; + } + ++ boolean isMicroG = false; ++ if (SystemProperties.getBoolean(MICROG_ENABLEMENT, false)) { ++ final boolean isValidGmsCore = newPkg.getPackageName().equals(PACKAGE_GMSCORE) && newPkg.getTargetSdkVersion() >= 29 && newPkg.getVersionCode() >= 231657056; ++ final boolean isValidFakeStore = newPkg.getPackageName().equals(PACKAGE_PLAY_STORE) && newPkg.getTargetSdkVersion() >= 24 && newPkg.getVersionCode() >= 30; ++ final boolean isValidGsf = newPkg.getPackageName().equals(PACKAGE_GSFPROXY) && newPkg.getTargetSdkVersion() >= 24 && newPkg.getVersionCode() >= 8; ++ isMicroG = (isValidGmsCore || isValidFakeStore || isValidGsf) && newPkg.getSigningDetails().getSha256Certificate().equals(MICROG_HASH); ++ } ++ + final boolean newIsForceQueryable = + mForceQueryable.contains(newPkgSetting.appId) + /* shared user that is already force queryable */ + || newPkgSetting.forceQueryableOverride /* adb override */ ++ || isMicroG + || (newPkgSetting.isSystem() && (mSystemAppsQueryable + || newPkg.isForceQueryable() + || ArrayUtils.contains(mForceQueryableByDevicePackageNames, diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java -index 9611b381942c..f8f8b29d1798 100644 +index 9611b381942c..c286aa93130b 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -4465,8 +4465,20 @@ public class PackageManagerService extends IPackageManager.Stub @@ -89,11 +143,11 @@ index 9611b381942c..f8f8b29d1798 100644 - PackageInfo packageInfo = PackageInfoUtils.generate(p, gids, flags, - ps.firstInstallTime, ps.lastUpdateTime, permissions, state, userId, ps); + // Allow microG GmsCore and FakeStore to spoof signature -+ final boolean isValidGmsCore = p.getPackageName().equals("com.google.android.gms") && p.getTargetSdkVersion() >= 29 && p.getVersionCode() >= 231657056; -+ final boolean isValidFakeStore = p.getPackageName().equals("com.android.vending") && p.getTargetSdkVersion() >= 24 && p.getVersionCode() >= 30; ++ final boolean isValidGmsCore = p.getPackageName().equals(PACKAGE_GMSCORE) && p.getTargetSdkVersion() >= 29 && p.getVersionCode() >= 231657056; ++ final boolean isValidFakeStore = p.getPackageName().equals(PACKAGE_PLAY_STORE) && p.getTargetSdkVersion() >= 24 && p.getVersionCode() >= 30; + final boolean isMicroG = isValidGmsCore || isValidFakeStore; + PackageInfo packageInfo; -+ if (isMicroG && SystemProperties.getBoolean(SPOOF_CONTROL, false)) { ++ if (isMicroG && SystemProperties.getBoolean(MICROG_ENABLEMENT, false)) { + packageInfo = fakeSignature(p, PackageInfoUtils.generate(p, gids, flags, + ps.firstInstallTime, ps.lastUpdateTime, permissions, state, + userId, ps), permissions); @@ -105,12 +159,17 @@ index 9611b381942c..f8f8b29d1798 100644 if (packageInfo == null) { return null; -@@ -4502,6 +4514,29 @@ public class PackageManagerService extends IPackageManager.Stub - } +@@ -4563,6 +4575,34 @@ public class PackageManagerService extends IPackageManager.Stub + return false; } -+ // The setting to control spoofing enablement. -+ private static final String SPOOF_CONTROL = "persist.security.sigspoof"; ++ // Package IDs of apps ++ private static final String PACKAGE_GMSCORE = "com.google.android.gms"; ++ private static final String PACKAGE_PLAY_STORE = "com.android.vending"; ++ private static final String[] PACKAGES_SPOOF_INSTALLSOURCE = ++ new String[] { "com.aurora.store", "dev.imranr.obtainium" }; ++ // The setting to control microG enablement. ++ private static final String MICROG_ENABLEMENT = "persist.security.sigspoof"; + // The Google signature faked by microG. + private static final String GOOGLE_CERT = "308204433082032ba003020102020900c2e08746644a308d300d06092a864886f70d01010405003074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f6964301e170d3038303832313233313333345a170d3336303130373233313333345a3074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f696430820120300d06092a864886f70d01010105000382010d00308201080282010100ab562e00d83ba208ae0a966f124e29da11f2ab56d08f58e2cca91303e9b754d372f640a71b1dcb130967624e4656a7776a92193db2e5bfb724a91e77188b0e6a47a43b33d9609b77183145ccdf7b2e586674c9e1565b1f4c6a5955bff251a63dabf9c55c27222252e875e4f8154a645f897168c0b1bfc612eabf785769bb34aa7984dc7e2ea2764cae8307d8c17154d7ee5f64a51a44a602c249054157dc02cd5f5c0e55fbef8519fbe327f0b1511692c5a06f19d18385f5c4dbc2d6b93f68cc2979c70e18ab93866b3bd5db8999552a0e3b4c99df58fb918bedc182ba35e003c1b4b10dd244a8ee24fffd333872ab5221985edab0fc0d0b145b6aa192858e79020103a381d93081d6301d0603551d0e04160414c77d8cc2211756259a7fd382df6be398e4d786a53081a60603551d2304819e30819b8014c77d8cc2211756259a7fd382df6be398e4d786a5a178a4763074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f6964820900c2e08746644a308d300c0603551d13040530030101ff300d06092a864886f70d010104050003820101006dd252ceef85302c360aaace939bcff2cca904bb5d7a1661f8ae46b2994204d0ff4a68c7ed1a531ec4595a623ce60763b167297a7ae35712c407f208f0cb109429124d7b106219c084ca3eb3f9ad5fb871ef92269a8be28bf16d44c8d9a08e6cb2f005bb3fe2cb96447e868e731076ad45b33f6009ea19c161e62641aa99271dfd5228c5c587875ddb7f452758d661f6cc0cccb7352e424cc4365c523532f7325137593c4ae341f4db41edda0d0b1071a7c440f0fe9ea01cb627ca674369d084bd2fd911ff06cdbf2cfa10dc0f893ae35762919048c7efc64c7144178342f70581c9de573af55b390dd7fdb9418631895d5f759f30112687ff621410c069308a"; + // The signing key hash of official microG builds. @@ -120,7 +179,7 @@ index 9611b381942c..f8f8b29d1798 100644 + Set permissions) { + String hash = p.getSigningDetails().getSha256Certificate(); + try { -+ if (hash.equals(MICROG_HASH) && p.getTargetSdkVersion() >= 24) { ++ if (hash.equals(MICROG_HASH) && p.getTargetSdkVersion() >= 24 && pi != null) { + pi.signatures = new Signature[] {new Signature(GOOGLE_CERT)}; + if (DEBUG_PACKAGE_INFO) { + Log.v(TAG, "Spoofing signature for microG"); @@ -133,5 +192,25 @@ index 9611b381942c..f8f8b29d1798 100644 + } + @Override - public void checkPackageStartable(String packageName, int userId) { - final int callingUid = Binder.getCallingUid(); + public PackageInfo getPackageInfo(String packageName, int flags, int userId) { + return getPackageInfoInternal(packageName, PackageManager.VERSION_CODE_HIGHEST, +@@ -21565,6 +21605,19 @@ public class PackageManagerService extends IPackageManager.Stub + return null; + } + ++ if (SystemProperties.getBoolean(MICROG_ENABLEMENT, false)) { ++ InstallSource installSource = ps.installSource; ++ if (installSource != null && installSource.installerPackageName != null ++ && mSettings.mPackages.get(PACKAGE_PLAY_STORE) != null ++ && callingUid != Process.SYSTEM_UID ++ && ArrayUtils.contains(PACKAGES_SPOOF_INSTALLSOURCE, installSource.installerPackageName)) { ++ return InstallSource.create(PACKAGE_PLAY_STORE, PACKAGE_PLAY_STORE, PACKAGE_PLAY_STORE, ++ ps.installSource.isOrphaned, false) ++ .setInitiatingPackageSignatures(new PackageSignatures( ++ mSettings.mPackages.get(PACKAGE_PLAY_STORE).getSigningDetails())); ++ } ++ } ++ + return ps.installSource; + } + diff --git a/Patches/LineageOS-18.1/android_packages_apps_Settings/0015-signature_spoofing_toggle.patch b/Patches/LineageOS-18.1/android_packages_apps_Settings/0015-microG_Toggle.patch similarity index 99% rename from Patches/LineageOS-18.1/android_packages_apps_Settings/0015-signature_spoofing_toggle.patch rename to Patches/LineageOS-18.1/android_packages_apps_Settings/0015-microG_Toggle.patch index 4d67c30a..06a54664 100644 --- a/Patches/LineageOS-18.1/android_packages_apps_Settings/0015-signature_spoofing_toggle.patch +++ b/Patches/LineageOS-18.1/android_packages_apps_Settings/0015-microG_Toggle.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tad Date: Wed, 20 Apr 2022 01:04:27 -0400 -Subject: [PATCH] Add a toggle to opt-in to restricted signature spoofing +Subject: [PATCH] Add a toggle for microG enablement Copy and pasted from the GrapheneOS exec spawning toggle patch diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0031-Hardened-signature-spoofing.patch b/Patches/LineageOS-19.1/android_frameworks_base/0031-Unprivileged_microG_Handling.patch similarity index 58% rename from Patches/LineageOS-19.1/android_frameworks_base/0031-Hardened-signature-spoofing.patch rename to Patches/LineageOS-19.1/android_frameworks_base/0031-Unprivileged_microG_Handling.patch index 6889ce32..412af034 100644 --- a/Patches/LineageOS-19.1/android_frameworks_base/0031-Hardened-signature-spoofing.patch +++ b/Patches/LineageOS-19.1/android_frameworks_base/0031-Unprivileged_microG_Handling.patch @@ -1,26 +1,32 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tad Date: Mon, 3 Jul 2023 12:00:12 -0400 -Subject: [PATCH] Hardened signature spoofing +Subject: [PATCH] Unprivileged microG handling - Must be enabled by user - Must match microG package ID - Must meet minimum respective targetSdk and versionCode - Must match official microG build signing key + - Only spoofs the Google package signature +- Sets the packages forceQueryable +- Spoofs apps installed via some sources as Play Store This is an effective merge + tweak of two existing patches, credits: Dylanger Daly https://github.com/dylangerdaly/platform_frameworks_base/commit/b58aa11631fadab3309a1d9268118bd9f2c2a79f Chirayu Desai of CalyxOS https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/76485abb36dc01b65506b010d0458e96e0116369 + https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/97765782f942d0975c383c90fde9140ef3ccf01b + https://gitlab.com/CalyxOS/platform_frameworks_base/-/commit/d81763383588e81353e24ad0a56ae2478752319c Change-Id: I64a252aac9bb196a11ed7b4b5d8c7e59a3413bd4 --- - .../android/content/pm/PackageParser.java | 32 +++++++++++++++ + .../android/content/pm/PackageParser.java | 32 ++++++++++ core/res/res/values/config.xml | 2 + - .../server/pm/PackageManagerService.java | 39 ++++++++++++++++++- - 3 files changed, 71 insertions(+), 2 deletions(-) + .../com/android/server/pm/AppsFilter.java | 18 ++++++ + .../server/pm/PackageManagerService.java | 58 ++++++++++++++++++- + 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 8f5df4672dc0..c326ed2eb09c 100644 @@ -78,22 +84,84 @@ index 35af82fb39a2..403680089a8d 100644