Android IPC 和 ContentProvider 差异
我正在尝试确定将手机上存储的加密内容公开给第三方应用程序的最佳方法。该内容是敏感的,需要受到保护,因此只有某些应用程序可以访问它。我正在研究的方法是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当您是唯一使用内容提供商的公司时才有效。
我更愿意将此描述为“可能符合‘精神错乱’的医学定义”。您的第三方将能够修改您的“安全”数据、伪造您发布的应用程序、将您的签名密钥泄露给恶意软件作者等。
除了基于
Cursor
的内容提供程序 API 之外,您还可以使用基于文件的内容提供程序 API,或者代替基于文件的内容提供程序 API。请参阅ContentResolver
上的openInputStream()
等方法。不是特别。
两者都可以,尽管我个人觉得服务更容易一些。
权限对于服务和内容提供商同样有效,但我想再次强调,您永远不应该与第三方共享您的签名密钥,除非是在枪口下。
That only works if you are the only firm using the content provider.
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.
You can use the file-based content provider API in addition to, or instead of, the
Cursor
-based content provider API. See methods likeopenInputStream()
onContentResolver
.Not especially.
Both can, though personally I find it a bit easier with services.
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.
我无法回答你的完整问题,但我可以解决关键共享部分。
您的 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.
(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.