Skip to content

Commit 3721bc8

Browse files
Suppress warnings for deprecated keychain APIs (#77924)
Co-authored-by: Kevin Jones <kevin@vcsjones.com>
1 parent d933222 commit 3721bc8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/native/libs/System.Security.Cryptography.Native.Apple/pal_keychain_macos.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ int32_t AppleCryptoNative_SecKeychainItemCopyKeychain(SecKeychainItemRef item, S
1616

1717
if (itemType == SecKeyGetTypeID() || itemType == SecIdentityGetTypeID() || itemType == SecCertificateGetTypeID())
1818
{
19+
#pragma clang diagnostic push
20+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1921
OSStatus status = SecKeychainItemCopyKeychain(item, pKeychainOut);
22+
#pragma clang diagnostic pop
2023

2124
if (status == noErr)
2225
{
@@ -40,20 +43,29 @@ int32_t AppleCryptoNative_SecKeychainCreate(const char* pathName,
4043
const uint8_t* passphraseUtf8,
4144
SecKeychainRef* pKeychainOut)
4245
{
46+
#pragma clang diagnostic push
47+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4348
return SecKeychainCreate(pathName, passphraseLength, passphraseUtf8, false, NULL, pKeychainOut);
49+
#pragma clang diagnostic pop
4450
}
4551

4652
int32_t AppleCryptoNative_SecKeychainDelete(SecKeychainRef keychain)
4753
{
54+
#pragma clang diagnostic push
55+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4856
return SecKeychainDelete(keychain);
57+
#pragma clang diagnostic pop
4958
}
5059

5160
int32_t AppleCryptoNative_SecKeychainCopyDefault(SecKeychainRef* pKeychainOut)
5261
{
5362
if (pKeychainOut != NULL)
5463
*pKeychainOut = NULL;
5564

65+
#pragma clang diagnostic push
66+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
5667
return SecKeychainCopyDefault(pKeychainOut);
68+
#pragma clang diagnostic pop
5769
}
5870

5971
int32_t AppleCryptoNative_SecKeychainOpen(const char* pszKeychainPath, SecKeychainRef* pKeychainOut)
@@ -64,12 +76,18 @@ int32_t AppleCryptoNative_SecKeychainOpen(const char* pszKeychainPath, SecKeycha
6476
if (pszKeychainPath == NULL)
6577
return errSecParam;
6678

79+
#pragma clang diagnostic push
80+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
6781
return SecKeychainOpen(pszKeychainPath, pKeychainOut);
82+
#pragma clang diagnostic pop
6883
}
6984

7085
int32_t AppleCryptoNative_SecKeychainUnlock(SecKeychainRef keychain, uint32_t passphraseLength, const uint8_t* passphraseUtf8)
7186
{
87+
#pragma clang diagnostic push
88+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
7289
return SecKeychainUnlock(keychain, passphraseLength, passphraseUtf8, true);
90+
#pragma clang diagnostic pop
7391
}
7492

7593
int32_t AppleCryptoNative_SetKeychainNeverLock(SecKeychainRef keychain)
@@ -81,7 +99,10 @@ int32_t AppleCryptoNative_SetKeychainNeverLock(SecKeychainRef keychain)
8199
.lockInterval = INT_MAX,
82100
};
83101

102+
#pragma clang diagnostic push
103+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
84104
return SecKeychainSetSettings(keychain, &settings);
105+
#pragma clang diagnostic pop
85106
}
86107

87108
static int32_t
@@ -262,7 +283,7 @@ static bool IsCertInKeychain(CFTypeRef needle, SecKeychainRef haystack)
262283
{
263284
ret = false;
264285
}
265-
286+
266287
if (result != NULL)
267288
{
268289
CFRelease(result);
@@ -355,7 +376,10 @@ int32_t AppleCryptoNative_X509StoreAddCertificate(CFTypeRef certOrIdentity, SecK
355376
// keychain back to disk.
356377
if (status == noErr && privateKey != NULL)
357378
{
379+
#pragma clang diagnostic push
380+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
358381
status = SecKeychainItemCreateCopy((SecKeychainItemRef)privateKey, keychain, NULL, &itemCopy);
382+
#pragma clang diagnostic pop
359383
}
360384

361385
if (status == errSecDuplicateItem)
@@ -374,7 +398,10 @@ int32_t AppleCryptoNative_X509StoreAddCertificate(CFTypeRef certOrIdentity, SecK
374398

375399
if (status == noErr && cert != NULL)
376400
{
401+
#pragma clang diagnostic push
402+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
377403
status = SecKeychainItemCreateCopy((SecKeychainItemRef)cert, keychain, NULL, &itemCopy);
404+
#pragma clang diagnostic pop
378405
}
379406

380407
if (status == errSecDuplicateItem)

src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509_macos.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,10 @@ int32_t AppleCryptoNative_X509CopyWithPrivateKey(SecCertificateRef cert,
384384
}
385385

386386
SecKeychainRef keyKeychain = NULL;
387-
387+
#pragma clang diagnostic push
388+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
388389
OSStatus status = SecKeychainItemCopyKeychain((SecKeychainItemRef)privateKey, &keyKeychain);
390+
#pragma clang diagnostic pop
389391
SecKeychainItemRef itemCopy = NULL;
390392

391393
// This only happens with an ephemeral key, so the keychain we're adding it to is temporary.
@@ -536,7 +538,10 @@ int32_t AppleCryptoNative_X509MoveToKeychain(SecCertificateRef cert,
536538

537539
SecKeychainRef curKeychain = NULL;
538540
SecKeyRef importedKey = NULL;
541+
#pragma clang diagnostic push
542+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
539543
OSStatus status = SecKeychainItemCopyKeychain((SecKeychainItemRef)cert, &curKeychain);
544+
#pragma clang diagnostic pop
540545

541546
if (status == errSecNoSuchKeychain)
542547
{
@@ -559,7 +564,10 @@ int32_t AppleCryptoNative_X509MoveToKeychain(SecCertificateRef cert,
559564

560565
if (status == noErr && privateKey != NULL)
561566
{
567+
#pragma clang diagnostic push
568+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
562569
status = SecKeychainItemCopyKeychain((SecKeychainItemRef)privateKey, &curKeychain);
570+
#pragma clang diagnostic pop
563571

564572
if (status == errSecNoSuchKeychain)
565573
{

0 commit comments

Comments
 (0)