简体   繁体   English

保护Coredata对象

[英]Securing Coredata objects

I am working on an application which has got some sensitive information. 我正在开发一个有一些敏感信息的应用程序。 I am aware that it would be difficult for a layman to hack into iphone to get the information. 我知道外行人很难入侵iPhone获取信息。 If I use SQLite directly I have something called SQLite Cipher to encrypt / encode the database. 如果我直接使用SQLite,我会使用SQLite Cipher来加密/编码数据库。

Is there anyway where I can have the same way of encrypting the coredata so it makes it hard for hackers to get into the data. 无论如何,我可以采用相同的方式加密coredata,这样黑客就很难进入数据。

Can someone shed some light on this? 有人可以对此有所了解吗?

Thanks in Advance 提前致谢

Core data is now encrypted by default (hardware encryption) on iPhone 3GS and later devices, including iPad. 核心数据现在默认加密(硬件加密)在iPhone 3GS和后来的设备上,包括iPad。 This means that data is automatically encrypted with a hardware key. 这意味着使用硬件密钥自动加密数据。 In iOS 4 or later, by following the steps at Nick Harris' more detailed blog entry , a second layer of encryption (called 'data protection') can be enabled which also uses the user's password to encrypt the hardware key. 在iOS 4或更高版本中, 按照Nick Harris更详细的博客条目中的步骤,可以启用第二层加密(称为“数据保护”),该加密也使用用户的密码来加密硬件密钥。

All of this depends on users setting a secure passcode and enabling data protection in iOS 4 . 所有这一切都取决于用户在iOS 4中设置安全密码和启用数据保护 If you're a registered apple developer, you can also watch the WWDC 2010 video on "Securing Application Data" in iTunes at this link and look at the PDF of the slides here after entering your developer id and password, for more detailed information about file encryption. 如果您是注册苹果开发人员,您还可以通过此链接 观看 iTunes中的“保护应用程序数据”的WWDC 2010视频,并在输入您的开发者ID和密码后查看幻灯片的PDF ,以获取更多详细信息。文件加密。

To enable data protection, in your - (NSPersistentStoreCoordinator *)persistentStoreCoordinator call, just change the file attributes of your .sqlite file using the key and value below. 要启用数据保护,请在- (NSPersistentStoreCoordinator *)persistentStoreCoordinator调用中,使用下面的键和值更改.sqlite文件的文件属性。 See Nick Harris' blog for more detailed code, including how to check to see if iOS 4 or higher is active. 有关更详细的代码,请参阅Nick Harris的博客,包括如何检查iOS 4或更高版本是否处于活动状态。

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyAppName.sqlite"];
NSString *storePath = [storeURL path];
NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
[[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:storePath error:&error]

The Core Data Programming Guide says explicitly that the SQL store type is a little more secure than XML or binary, but is not inherently secure - it recommends an encrypted disk image. “核心数据编程指南”明确指出SQL存储类型比XML或二进制文件更安全,但本质上不安全 - 它建议使用加密磁盘映像。 Unfortunately, that's a little hard to manage on the iPhone. 不幸的是,这在iPhone上有点难以管理。

What you might consider, if this is a real concern for you, is to build your own persistent store type - the Guide has a section on creating your own atomic store, and refers you to the Atomic Store Programming Topics document. 您可能会考虑的是,如果这是您真正关心的问题,那就是构建自己的持久存储类型 - 指南中有一节介绍如何创建自己的原子存储,并引用您的Atomic Store Programming Topics文档。 Build a store that takes some key from a user prompt at startup, then initializes with that key for encryption and decryption purposes. 构建一个商店,在启动时从用户提示中获取一些密钥,然后使用该密钥初始化以进行加密和解密。 (Note that if you take this route, the NSPersistentStore class reference says that subclassing NSPersistentStore directly is not supported in Core Data - you should subclass NSAtomicStore instead.) (请注意,如果采用此路由, NSPersistentStore类引用表明Core Data中不支持直接子类化NSPersistentStore - 您应该改为继承NSAtomicStore。)

If someone is using a jail broken iphone there is absolutely nothing you can do. 如果有人使用监狱打破的iPhone,你绝对没有办法。 The functions you are using for encryption and decryption can be hooked to obtain the key/iv used. 您可以连接用于加密和解密的功能以获取使用的密钥/ iv。 You can also do nasty things like do full dumps of the flash, keyboard buffer, and other "debug" info. 您还可以执行令人讨厌的事情,例如完全转储闪存,键盘缓冲区和其他“调试”信息。

To make things more difficult you can limit the amount of time a secret is stored on the device. 为了使事情变得更加困难,您可以限制秘密存储在设备上的时间。 Store secrets on a remote system and transfer them via ssl, delete them when you don't need it. 将密钥存储在远程系统上并通过ssl传输,在不需要时删除它们。 This protects against someone stealing the iphone, jail breaking it, and then dumping the database. 这可以防止有人窃取iPhone,监禁它,然后转储数据库。 I'm not sure if this is an attack that threatens your specific application. 我不确定这是否是一种威胁您特定应用的攻击。

In terms of a "layman" (people who can't read? :) Then you don't have much to worry about. 对于一个“外行人”(无法阅读的人?)然后你没有太多担心。 Apple has protection in place to keep installed apps from reading/writing to each others resources. Apple已采取保护措施,以防止已安装的应用程序无法读取/写入彼此的资源。

You can add a category for an entity, which overrides reading and writing values to the persistent store. 您可以为实体添加类别,该类别会覆盖对持久性存储的读取和写入值。 You can then hook into CommonCrypto routines for private- and public-key encryption and decryption of those values as they are stored and retrieved by your application. 然后,您可以挂钩到CommonCrypto例程,以便在应用程序存储和检索这些值时对其进行私钥和公钥加密和解密。

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

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