Android IPC 和 ContentProvider 差异

发布于 2024-11-17 15:48:47 字数 701 浏览 3 评论 0原文

我正在尝试确定将手机上存储的加密内容公开给第三方应用程序的最佳方法。该内容是敏感的,需要受到保护,因此只有某些应用程序可以访问它。我正在研究的方法是 IPC 和 Content Provider。以下是我认为对于我的情况而言两者的一些优点和缺点。

IPC - Pro's

  • 对客户的灵活响应类型。可以返回不同的错误代码和限制访问级别

IPC - Con's

  • 比Content Provider实现更复杂

  • 必须编写自己的保护内容访问的方式。

内容提供商 - 专业版

  • 易于实施

  • 通过设置提供商定义权限来轻松安全访问:protectionLevel=signature

内容提供商 - 缺点

  • 为了安全访问,内容提供商的密钥签名必须与第三方应用程序共享,这并不理想。

  • 返回结果类型的灵活性有限。内容提供程序仅返回查询的列的 Cursor 对象。


性能和电池方面有什么重大差异吗?
可以异步执行吗?
对列表还有其他意见/建议吗?

I am trying to decide the best approach to expose encrypted content stored on phone to 3rd party apps. The content is sensitive and needs to be protected so only certain apps can access this. The approaches I'm investigating are IPC and Content Provider. Below is what I believe to be some of the pro's and con's of both for my situation.

IPC - Pro's

  • Flexible response types to client. Different error codes and levels of restricted access can be returned

IPC - Con's

  • More complicated to implement than Content Provider

  • Would have to write own way of securing access to content.

Content Provider - Pro's

  • Easy to implement

  • Easy to secure access by making provider definition permission: protectionLevel=signature

Content Provider - Con's

  • To secure access, the Content Provider's key signature must be shared with 3rd party app which isn't ideal.

  • Limited flexibility in results types returned. Content Provider returns only a Cursor object for the columns that were queried.

Is there any major differences on performance and battery?
Can either execute asynchronously?
Any other comments/suggestions to the list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-11-24 15:48:47

通过提供提供者定义权限,轻松保护访问:protectionLevel=signature

仅当您是唯一使用内容提供商的公司时才有效。

为了确保访问安全,内容提供商的密钥签名必须与第三方应用程序共享,这并不理想。

我更愿意将此描述为“可能符合‘精神错乱’的医学定义”。您的第三方将能够修改您的“安全”数据、伪造您发布的应用程序、将您的签名密钥泄露给恶意软件作者等。

Content Provider 仅返回查询的列的 Cursor 对象。

除了基于Cursor 的内容提供程序 API 之外,您还可以使用基于文件的内容提供程序 API,或者代替基于文件的内容提供程序 API。请参阅 ContentResolver 上的 openInputStream() 等方法。

性能和电池方面有什么重大差异吗?

不是特别。

可以异步执行吗?

两者都可以,尽管我个人觉得服务更容易一些。

对该列表还有其他意见/建议吗?

权限对于服务和内容提供商同样有效,但我想再次强调,您永远不应该与第三方共享您的签名密钥,除非是在枪口下。

Easy to secure access by making provider definition permission: protectionLevel=signature

That only works if you are the only firm using the content provider.

To secure access, the Content Provider's key signature must be shared with 3rd party app which isn't ideal.

I would describe this more as "may meet the medical definition of 'insanity'". Your third parties will be able to modify your "secure" data, forge applications as having been published by you, leak your signing key to malware authors, etc.

Content Provider returns only a Cursor object for the columns that were queried.

You can use the file-based content provider API in addition to, or instead of, the Cursor-based content provider API. See methods like openInputStream() on ContentResolver.

Is there any major differences on performance and battery?

Not especially.

Can either execute asynchronously?

Both can, though personally I find it a bit easier with services.

Any other comments/suggestions to the list?

Permissions work equally well with services and content providers, but I wish to re-emphasize that you should never be sharing your signing key with third parties, except perhaps at gunpoint.

瑾夏年华 2024-11-24 15:48:47

我无法回答你的完整问题,但我可以解决关键共享部分。
您的 APK 是使用您的公钥/私钥对的公开部分进行签名的。可以将您的公钥附加到另一个应用程序以冒充您的应用程序,但有人需要拥有您的私钥才能使用您的公钥以您的名义上传应用程序。

公钥证书,也称为数字证书或
身份证书,包含公钥/私钥的公钥
对,以及识别密钥所有者的一些其他元数据
(例如,名称和位置)。证书的所有者持有
相应的私钥。

当您对 APK 进行签名时,签名工具会将公钥证书附加到 APK。公钥证书充当
将 APK 与您和您的设备唯一关联的“指纹”
对应的私钥。这有助于 Android 确保任何未来
您的 APK 更新是真实的,并且来自原作者。

(来自 https://developer.android.com/studio/publish/app-signing.html

另外,根据我的措辞,我的理解是其他应用程序与您的应用程序共享密钥,而不是与您的应用程序共享密钥。反过来说。如果您可以使用其他设置之一,则也不需要签名级别保护。根据 https://developer.android.com/guide/ topic/manifest/permission-element.html#plevel 您可以选择将应用程序设置为 4 个不同的保护级别之一。大多数应用程序不包含足够敏感的数据,不需要“危险”设置,因此正常可能适用于大多数应用程序。

此外,您的应用程序的签名(公钥)已通过 PackageManager 类中可用的方法公开。我广泛查看了 Android 开发者页面,并通读了另一篇文章的非常有用的答案,找到了这一点。似乎任何应用程序都可以通过此处描述的方法获取应用程序的公钥 Android 内容提供商保护级别和CommonsWare 的不同键

I cannot answer your full question, but I can address the key sharing part.
Your APK is signed with the public part of your public/private key pair. It may be possible to attach your public key to another app to pretend to be your app, but someone would need to have your private key to upload an app in your name by using your public key.

A public-key certificate, also known as a digital certificate or an
identity certificate, contains the public key of a public/private key
pair, as well as some other metadata identifying the owner of the key
(for example, name and location). The owner of the certificate holds
the corresponding private key.

When you sign an APK, the signing tool attaches the public-key certificate to the APK. The public-key certificate serves as as a
"fingerprint" that uniquely associates the APK to you and your
corresponding private key. This helps Android ensure that any future
updates to your APK are authentic and come from the original author.

(from https://developer.android.com/studio/publish/app-signing.html )

Also, it is my understanding from how it is worded that the other applications share their keys with your app and not the other way around. The signature level protection is also not necessary if you can make use of one of the other settings. According to https://developer.android.com/guide/topics/manifest/permission-element.html#plevel you can choose to set the app to one of 4 different protection levels. Most apps do not contain data that is sensitive enough to require the “dangerous” setting, so normal would likely work for most applications.

Also, your app’s signature (public key) is already exposed through the methods available in the PackageManager class. I looked extensively the Android developer pages and read through a very helpful answer to another post to find this. It appears that any app can get your app’s public key through the method described here Android content provider protection level & different keys by CommonsWare.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文