Specify kSecUseDataProtectionKeychain when generating RSA/ECC keys on macOS/iOS
authorFilip Navara <navara@emclient.com>
Thu, 3 Jun 2021 22:38:13 +0000 (00:38 +0200)
committerGitHub <noreply@github.com>
Thu, 3 Jun 2021 22:38:13 +0000 (15:38 -0700)
src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_ecc.c
src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_rsa.c

index bf320e7..39d7a99 100644 (file)
@@ -24,6 +24,10 @@ int32_t AppleCryptoNative_EccGenerateKey(int32_t keySizeBits,
     {
         CFDictionaryAddValue(attributes, kSecAttrKeyType, kSecAttrKeyTypeEC);
         CFDictionaryAddValue(attributes, kSecAttrKeySizeInBits, cfKeySizeValue);
+        if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, *))
+        {
+            CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);
+        }
 
         *pPrivateKey = SecKeyCreateRandomKey(attributes, pErrorOut);
         if (*pPrivateKey != NULL)
index ba2525f..a9aece3 100644 (file)
@@ -26,6 +26,10 @@ int32_t AppleCryptoNative_RsaGenerateKey(int32_t keySizeBits,
     {
         CFDictionaryAddValue(attributes, kSecAttrKeyType, kSecAttrKeyTypeRSA);
         CFDictionaryAddValue(attributes, kSecAttrKeySizeInBits, cfKeySizeValue);
+        if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, *))
+        {
+            CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);
+        }
 
         *pPrivateKey = SecKeyCreateRandomKey(attributes, pErrorOut);
         if (*pPrivateKey != NULL)