简体   繁体   English

使用 PLATFORM 密钥签名的 Android APK 未获得系统权限?

[英]Android APK signed with PLATFORM key not given system privileges?

I have access to an Android tablets' platform key and certificate.我可以访问 Android 平板电脑的平台密钥和证书。 I'm attempting to build an app and install it with system level privileges by doing the following:我正在尝试构建一个应用程序并通过执行以下操作以系统级权限安装它:

  1. Create a Java KeyStore file with platform.pk8 and platform.x509.pem using the bash script called platform_import_keystore found on GitHub.使用 GitHub 上名为platform_import_keystore的 bash 脚本创建一个包含 platform.pk8 和 platform.x509.pem 的 Java KeyStore 文件。

  2. In AndroidManifex.xml add the following:在 AndroidManifex.xml 中添加以下内容:

    <uses-permission android:name="android.permission.READ_LOGS"/> android:sharedUserId="android.uid.system" <uses-permission android:name="android.permission.READ_LOGS"/> android:sharedUserId="android.uid.system"

  3. Sign APK with PLATFORM key and certificate using a Java KeyStore file in Android Studio.使用 Android Studio 中的 Java KeyStore 文件使用 PLATFORM 密钥和证书签署 APK。

  4. Install APK安装 APK

When the app runs, the system denies READ_LOGS permission.当应用程序运行时,系统拒绝 READ_LOGS 权限。 Why isn't my app running with system level permissions?为什么我的应用没有以系统级权限运行?

What @Mark mentions is correct to some extent, for system apps. @Mark 提到的在某种程度上是正确的,对于系统应用程序。 I think you are doing something else wrong.我认为你做错了其他事情。 I have tried this with system apps as well, and as long it was signed with the platform keystore, it works.我也用系统应用程序尝试过这个,只要它是用平台密钥库签名的,它就可以工作。 Now this was on Android 8 and Android 9. You haven't mentioned the AOSP version running the device.现在这是在 Android 8 和 Android 9 上。您没有提到运行该设备的 AOSP 版本。

That changes things AFAIK, so if it's AOSP 10+, it might behave differently.这改变了 AFAIK,所以如果它是 AOSP 10+,它的行为可能会有所不同。

Also the other comments are missing another key thing SELinux.此外,其他评论缺少 SELinux 的另一个关键内容。 SELinux is not permissive for user builds. SELinux 不允许用户构建。 Verity is enabled, and you cannot have root access. Verity 已启用,您不能拥有 root 访问权限。 So you cannot push the app into /system/priv-app/ or push it into /vendor/app/ .因此,您不能将应用程序推送到/system/priv-app/或推送到/vendor/app/ You cannot access system resources without proper SE Policy files.如果没有适当的 SE 策略文件,您将无法访问系统资源。 You can check the logs yourself, to see avc denied messages.您可以自己检查日志,以查看avc denied消息。

I think overall what you are seeing should be inline with AOSP's security ideals.我认为总体而言,您所看到的应该符合 AOSP 的安全理念。 An app signed with System keys should not be able to get system permissions.使用系统密钥签名的应用程序应该无法获得系统权限。 It also needs to be located in the correct place, either as a privileged app or vendor app.它还需要位于正确的位置,作为特权应用程序或供应商应用程序。 Such apps need to be whitelisted.此类应用程序需要列入白名单。 There's a built in script in AOSP source to even generate the permissions for whitelisting (it produces the required xml) AOSP 源中有一个内置脚本,甚至可以生成白名单权限(它生成所需的 xml)

There's two classes of system apps, /system/app/ and /system/priv-app/ The privileged apps are the only ones that get signature level permissions, and according to newer versions of android, you need to enable whitelisting in the /system/etc/priv_app-permissions_device_name .有两类系统应用程序, /system/app//system/priv-app/特权应用程序是唯一获得签名级别权​​限的应用程序,并且根据较新版本的android,您需要在/system/etc/priv_app-permissions_device_name启用白名单/system/etc/priv_app-permissions_device_name

If you make any changes to the system or vendor when verity is enabled, firstly they are mounted read only, but somehow if you do make a change, the device will brick itself.如果在启用验证时对系统或供应商进行任何更改,首先它们以只读方式安装,但不知何故,如果您进行更改,设备将自行变砖。 This is the security feature.这是安全功能。 All custom development needs to be done in userdebug builds with SELinux in permissive mode, and then all the permissions need to be predefined, SE Policies fine tuned to utmost minimal, only then the user build can function normally.所有自定义开发都需要在许可模式下使用 SELinux 的 userdebug build 中完成,然后需要预定义所有权限,SE Policies 微调到最小,然后 user build 才能正常运行。 User build is not at all suitable for AOSP development activities, even if it's just for testing or trying out a single app.用户构建根本不适合 AOSP 开发活动,即使它只是用于测试或试用单个应用程序。

User build is production type build that the end user can use and is not for development.用户构建是最终用户可以使用且不用于开发的生产类型构建。 It's the most secure form of android, so if you have platform keys, it may never be enough.它是最安全的 android 形式,因此如果您有平台密钥,它可能永远都不够。

All that being said, I'm sure you don't have the right keys.说了这么多,我敢肯定你没有正确的钥匙。 Just pull an app from system/priv-app/ and use keytool or similar to check it's signature, and then try to match with your release apk.只需从system/priv-app/提取一个应用system/priv-app/并使用keytool或类似工具检查它的签名,然后尝试与您发布的 apk 匹配。

It's little complicated as it is, and kind of hard to explain and there are levels of permissions also in android, so if you aren't following a specific approach/path, you will not be able to get it to work.它并不复杂,有点难以解释,而且 android 中也有权限级别,所以如果您不遵循特定的方法/路径,您将无法让它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM