00002-microg-sigspoof.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. diff --git a/frameworks/base/core/res/AndroidManifest.xml b/frameworks/base/core/res/AndroidManifest.xml
  2. index 66c497e..485635e 100644
  3. --- a/frameworks/base/core/res/AndroidManifest.xml
  4. +++ b/frameworks/base/core/res/AndroidManifest.xml
  5. @@ -2341,6 +2341,13 @@
  6. android:description="@string/permdesc_getPackageSize"
  7. android:protectionLevel="normal" />
  8. + <!-- @hide Allows an application to change the package signature as
  9. + seen by applications -->
  10. + <permission android:name="android.permission.FAKE_PACKAGE_SIGNATURE"
  11. + android:protectionLevel="signature|privileged"
  12. + android:label="@string/permlab_fakePackageSignature"
  13. + android:description="@string/permdesc_fakePackageSignature" />
  14. +
  15. <!-- @deprecated No longer useful, see
  16. {@link android.content.pm.PackageManager#addPackageToPreferred}
  17. for details. -->
  18. diff --git a/frameworks/base/core/res/res/values/config.xml b/frameworks/base/core/res/res/values/config.xml
  19. index 0b5dd7e..bbdba64 100644
  20. --- a/frameworks/base/core/res/res/values/config.xml
  21. +++ b/frameworks/base/core/res/res/values/config.xml
  22. @@ -1650,6 +1650,8 @@
  23. <string-array name="config_locationProviderPackageNames" translatable="false">
  24. <!-- The standard AOSP fused location provider -->
  25. <item>com.android.location.fused</item>
  26. + <!-- The (faked) microg fused location provider (a free reimplementation) -->
  27. + <item>com.google.android.gms</item>
  28. </string-array>
  29. <!-- This string array can be overriden to enable test location providers initially. -->
  30. diff --git a/frameworks/base/core/res/res/values/strings.xml b/frameworks/base/core/res/res/values/strings.xml
  31. index 3c5159c..42ee3c6 100644
  32. --- a/frameworks/base/core/res/res/values/strings.xml
  33. +++ b/frameworks/base/core/res/res/values/strings.xml
  34. @@ -785,6 +785,12 @@
  35. <!-- Permissions -->
  36. +
  37. + <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
  38. + <string name="permlab_fakePackageSignature">Spoof package signature</string>
  39. + <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
  40. + <string name="permdesc_fakePackageSignature">Allows the app to pretend to be a different app. Malicious applications might be able to use this to access private application data. Legitimate uses include an emulator pretending to be what it emulates. Grant this permission with caution only!</string>
  41. +
  42. <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
  43. <string name="permlab_statusBar">disable or modify status bar</string>
  44. <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
  45. diff --git a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
  46. index 63c721a5da7..f6b441d990a 100644
  47. --- a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
  48. +++ b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
  49. @@ -703,6 +703,11 @@ public class PackageManagerService extends IPackageManager.Stub
  50. private static final String RANDOM_DIR_PREFIX = "~~";
  51. + /**
  52. + * The Google signature faked by microG.
  53. + */
  54. + private static final String MICROG_FAKE_SIGNATURE = "308204433082032ba003020102020900c2e08746644a308d300d06092a864886f70d01010405003074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f6964301e170d3038303832313233313333345a170d3336303130373233313333345a3074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f696430820120300d06092a864886f70d01010105000382010d00308201080282010100ab562e00d83ba208ae0a966f124e29da11f2ab56d08f58e2cca91303e9b754d372f640a71b1dcb130967624e4656a7776a92193db2e5bfb724a91e77188b0e6a47a43b33d9609b77183145ccdf7b2e586674c9e1565b1f4c6a5955bff251a63dabf9c55c27222252e875e4f8154a645f897168c0b1bfc612eabf785769bb34aa7984dc7e2ea2764cae8307d8c17154d7ee5f64a51a44a602c249054157dc02cd5f5c0e55fbef8519fbe327f0b1511692c5a06f19d18385f5c4dbc2d6b93f68cc2979c70e18ab93866b3bd5db8999552a0e3b4c99df58fb918bedc182ba35e003c1b4b10dd244a8ee24fffd333872ab5221985edab0fc0d0b145b6aa192858e79020103a381d93081d6301d0603551d0e04160414c77d8cc2211756259a7fd382df6be398e4d786a53081a60603551d2304819e30819b8014c77d8cc2211756259a7fd382df6be398e4d786a5a178a4763074310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e205669657731143012060355040a130b476f6f676c6520496e632e3110300e060355040b1307416e64726f69643110300e06035504031307416e64726f6964820900c2e08746644a308d300c0603551d13040530030101ff300d06092a864886f70d010104050003820101006dd252ceef85302c360aaace939bcff2cca904bb5d7a1661f8ae46b2994204d0ff4a68c7ed1a531ec4595a623ce60763b167297a7ae35712c407f208f0cb109429124d7b106219c084ca3eb3f9ad5fb871ef92269a8be28bf16d44c8d9a08e6cb2f005bb3fe2cb96447e868e731076ad45b33f6009ea19c161e62641aa99271dfd5228c5c587875ddb7f452758d661f6cc0cccb7352e424cc4365c523532f7325137593c4ae341f4db41edda0d0b1071a7c440f0fe9ea01cb627ca674369d084bd2fd911ff06cdbf2cfa10dc0f893ae35762919048c7efc64c7144178342f70581c9de573af55b390dd7fdb9418631895d5f759f30112687ff621410c069308a";
  55. +
  56. final ServiceThread mHandlerThread;
  57. final Handler mHandler;
  58. @@ -4383,8 +4388,9 @@ public class PackageManagerService extends IPackageManager.Stub
  59. final Set<String> permissions = ArrayUtils.isEmpty(p.getRequestedPermissions())
  60. ? Collections.emptySet() : permissionsState.getPermissions(userId);
  61. - PackageInfo packageInfo = PackageInfoUtils.generate(p, gids, flags,
  62. - ps.firstInstallTime, ps.lastUpdateTime, permissions, state, userId, ps);
  63. + PackageInfo packageInfo = mayFakeSignature(p, PackageInfoUtils.generate(p, gids, flags,
  64. + ps.firstInstallTime, ps.lastUpdateTime, permissions, state, userId, ps),
  65. + permissions);
  66. if (packageInfo == null) {
  67. return null;
  68. @@ -4420,6 +4426,24 @@ public class PackageManagerService extends IPackageManager.Stub
  69. }
  70. }
  71. + private PackageInfo mayFakeSignature(AndroidPackage p, PackageInfo pi,
  72. + Set<String> permissions) {
  73. + try {
  74. + if (permissions.contains("android.permission.FAKE_PACKAGE_SIGNATURE")
  75. + && p.getTargetSdkVersion() > Build.VERSION_CODES.LOLLIPOP_MR1) {
  76. + // Only allow microG and FakeStore
  77. + String packageName = p.getPackageName();
  78. + if (packageName.equals("com.google.android.gms") || packageName.equals("com.android.vending")) {
  79. + pi.signatures = new Signature[] {new Signature(MICROG_FAKE_SIGNATURE)};
  80. + }
  81. + }
  82. + } catch (Throwable t) {
  83. + // We should never die because of any failures, this is system code!
  84. + Log.w("PackageManagerService.FAKE_PACKAGE_SIGNATURE", t);
  85. + }
  86. + return pi;
  87. + }
  88. +
  89. @Override
  90. public void checkPackageStartable(String packageName, int userId) {
  91. final int callingUid = Binder.getCallingUid();