@H_502_6@
我正在开发一个带钥匙串实现的应用程序.我能够创造&将数据保存到钥匙串中.我正在使用Apple提供的
Keychain Wrapper classes.
根据要求,我必须在KeyChain中实现最好的安全性(安全团队指出了失误,例如它在Jail-broken设备上的可访问性).
有人可以指点我吗?
解决方法
我还在应用程序中实现了keychain long返回使用你引用的相同Wrapper,当然还有很多修改.
基本上Keychain非常安全.根据Apple的说法,它是一个加密容器,可以保存多个应用程序的安全信息,这意味着当钥匙串被锁定时,没有人可以访问其受保护的内容.
在iOS中,只有创建钥匙串的应用程序才能访问它.
根据Apple的文档,iOS可以选择内存缓存或磁盘缓存.
但是从iOS 4.xx开始,它只是磁盘缓存(不知道为什么),因此总是创建一个
sqlite DB,其中存储钥匙串中的所有数据,对应于特定的标识符.
sqlite DB可以在root或Jail-broken设备上被黑客攻击.
保护钥匙串
1在添加或添加安全关键字“kSecAttrAccessibleWhenUnlockedThisDeviceOnly”时
更新方法“SecItemUpdate”&的钥匙串中的数据“SecItemAdd”.
就像是 :-
- (void)writeToKeychain { NSDictionary *attributes = NULL; NSMutableDictionary *updateItem = NULL; OSStatus result; if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery,(CFTypeRef *)&attributes) == noErr) { updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; [tempCheck removeObjectForKey:(id)kSecClass]; #if TARGET_IPHONE_SIMULATOR [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; #endif [updateItem setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible]; result = SecItemUpdate((CFDictionaryRef)updateItem,(CFDictionaryRef)tempCheck); NSAssert( result == noErr,@"Couldn't update the Keychain Item." ); CFRelease(attributes); } else { [keychainItemData setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible]; result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData],NULL); NSAssert( result == noErr,@"Couldn't add the Keychain Item." ); } }
2在添加到Keychain之前加密数据.我使用AES-128加密.
还要确保用于加密的密钥是RSA密钥.(由SSL Web服务发送).
注意: – 钥匙串数据存储在iPhone上的/private/var/Keychains/keychain-2.db文件中.
希望它能帮到你.