简体   繁体   English

Keychain和Secure Enclave有什么区别

[英]What is difference between Keychain and Secure Enclave

I've been in searching where keychain stores either secure enclave or any other, I found many articles (one of this stackoverflow answer ) which says following but I'm looking for some Authenticated like Apple statement 我一直在寻找钥匙串存放安全飞地或其他任何地方,我发现很多文章(这个stackoverflow答案之一 )说下面但我正在寻找一些像Apple声明的认证

The keychain stores the keys (and other small data) encrypted and restricts access to that data. 钥匙串存储加密的密钥(和其他小数据)并限制对该数据的访问。 Additionally in recent iPhones (5S and later) the keychain is in a separate processor, the Secure Enclave which additionally restricts access. 此外,在最近的iPhone(5S及更高版本)中,钥匙串位于单独的处理器中,Secure Enclave还限制了访问。 There is no more secure way to store keys in iOS. 没有更安全的方法来在iOS中存储密钥。

So my queries on the basis of above statement. 所以我的查询基于上述声明。

  • Is Keychain Items store in secure Enclave Keychain项目是否存储在安全的Enclave中
  • If yes then where Public key and Private key CFTypeRef Store 如果是,则公钥和私钥CFTypeRef存储在哪里
  • Why we use this kSecAttrTokenIDSecureEnclave while creating key pair. 为什么我们在创建密钥对时使用此kSecAttrTokenIDSecureEnclave (example following code). (以下代码示例)。

     -(bool) generateKeyPairWithAccessControlObject:(SecAccessControlRef)accessControlRef { CFMutableDictionaryRef accessControlDict = newCFDict;; CFDictionaryAddValue(accessControlDict, kSecAttrAccessControl, accessControlRef); CFDictionaryAddValue(accessControlDict, kSecAttrIsPermanent, kCFBooleanTrue); CFDictionaryAddValue(accessControlDict, kSecAttrLabel, kPrivateKeyName); // create dict which actually saves key into keychain CFMutableDictionaryRef generatePairRef = newCFDict; CFDictionaryAddValue(generatePairRef, kSecAttrTokenID, kSecAttrTokenIDSecureEnclave); CFDictionaryAddValue(generatePairRef, kSecAttrKeyType, kSecAttrKeyTypeEC); CFDictionaryAddValue(generatePairRef, kSecAttrKeySizeInBits, (__bridge const void *)([NSNumber numberWithInt:256])); CFDictionaryAddValue(generatePairRef, kSecPrivateKeyAttrs, accessControlDict); OSStatus status = SecKeyGeneratePair(generatePairRef, &publicKeyRef, &privateKeyRef); if (status != errSecSuccess) return NO; [self savePublicKeyFromRef:publicKeyRef]; return YES; } 

Looking for authenticated answer. 寻找经过验证的答案。 Cheers 干杯

The Keychain uses Secure Enclave, the Secure Enclave is implemented in hardware. Keychain使用Secure Enclave,Secure Enclave在硬件中实现。

From what I understand: 据我所知:
By default asymmetric key-pairs are created and stored in the secure enclave. 默认情况下,会创建非对称密钥对并将其存储在安全区域中。 The private key is available only at creation time and can not be obtained later. 私钥仅在创建时可用,以后无法获取。 Asymmetric operations that use the private key obtain it from the keychain without exposing it to user code. 使用私钥的非对称操作从钥匙串获取它而不将其暴露给用户代码。

There is an exception that allows access to the private key, the Keychain Access app. 有一个例外允许访问私钥Keychain Access应用程序。

Not all keychain items are stored in secure enclave 并非所有钥匙串物品都存储在安全区域内
From Apple document 来自Apple文档

The only keychain items supported by the Secure Enclave are 256-bit elliptic curve private keys (those that have key type kSecAttrKeyTypeEC). Secure Enclave支持唯一钥匙串项是256位椭圆曲线私钥 (密钥类型为kSecAttrKeyTypeEC的私钥)。 Such keys must be generated directly on the Secure Enclave using the SecKeyGeneratePair( : :_:) function with the kSecAttrTokenID key set to kSecAttrTokenIDSecureEnclave in the parameters dictionary. :_ :)与所述参数字典设定为kSecAttrTokenIDSecureEnclave的kSecAttrTokenID关键功能这些键都必须直接在使用SecKeyGeneratePair(安全区域来生成。 It is not possible to import pre-existing keys into the Secure Enclave. 无法将预先存在的密钥导入Secure Enclave。

Take a look at Apple's iOS Security documentation , it describes what Secure Enclave and Keychain are exactly. 看一下Apple的iOS安全文档 ,它描述了Secure Enclave和Keychain的确切内容。

A Secure Enclave is a coprocessor fabricated within the system on chip (SoC). Secure Enclave在片上系统(SoC)内制造的协处理器。 It uses encrypted memory and includes a hardware random number generator . 它使用加密内存并包含硬件随机数生成器 As for the Keychain , the iOS Keychain provides a secure way to store these (passwords and other short but sensitive bits of data) items. 对于KeychainiOS Keychain提供了一种安全存储方式(密码和其他短而敏感的数据位)项的安全方法。 [...] The Keychain is implemented as a SQLite database stored on the file system. [...] Keychain是作为存储在文件系统上的SQLite数据库实现的。 .

Keychain is a piece of software that stores encrypted data (such as passwords) in a SQLite database. Keychain是一种将加密数据(如密码)存储在SQLite数据库中的软件。 The key that encrypts this data is inside the Secure Enclave - it never leaves the SE, as per this paragraph 加密此数据的密钥位于Secure Enclave内部 - 它根本不会离开SE

Keychain items are encrypted using two different AES-256-GCM keys, a table key (metadata) and per-row key (secret-key). 使用两个不同的AES-256-GCM密钥,表密钥(元数据)和每行密钥(密钥)对密钥链项进行加密。 Keychain metadata (all attributes other than kSecValue) is encrypted with the metadata key to speed search while the secret value (kSecValueData) is encrypted with the secret-key. 密钥链元数据(除kSecValue之外的所有属性)使用元数据密钥加密以加速搜索,同时使用密钥加密秘密值(kSecValueData)。 The metadata key is protected by Secure Enclave processor, but cached in the application processor to allow fast queries of the keychain. 元数据密钥受Secure Enclave处理器保护,但缓存在应用程序处理器中以允许快速查询密钥链。 The secret key always requires a round-trip through the Secure Enclave processor. 密钥始终需要通过Secure Enclave处理器往返。

To answer your question: are keychain items stored inside Secure Enclave, no, they are stored inside a SQLite database on disk, but the encryption key needed to decrypt this data is inside the Secure Enclave. 回答你的问题:存储在Secure Enclave中的钥匙串项目,不,它们存储在磁盘上的SQLite数据库中,但解密此数据所需的加密密钥位于Secure Enclave内部。 As for kSecAttrTokenIDSecureEnclave that apperas to be a flag that indicates that the key should be generated inside the Secure Element. 至于kSecAttrTokenIDSecureEnclave ,它是一个标志,表示应该在安全元素内生成密钥。

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

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