12

I would like to add some items to the keychain using "secitemadd", but I need to know first, if this is thread safe.

I have read the documentation from apple, but I am unable to find anywhere stating if its thread-safe.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
raghul
  • 1,008
  • 1
  • 15
  • 33
  • 1
    I am amazed how little documentation there is on this. I would imagine that based on the lack of documentation and issues raises on SO, that the API is probably thread safe. – Rory McKinnel May 11 '15 at 14:51

2 Answers2

18

In another document, Apple says it is thread safe.

Concurrency Considerations
On iOS, all the functions in this API are thread-safe and reentrant.

see Certificate, Key, and Trust Services Reference

Mac_Cain13
  • 3,611
  • 2
  • 24
  • 38
mash
  • 4,204
  • 4
  • 32
  • 34
  • 1
    Quinn explains concurrency in Keychain a bit more in depth in this forum post, might be of interest to anyone looking into this: https://developer.apple.com/forums/thread/117092?answerId=361922022#361922022 – Mac_Cain13 Apr 28 '23 at 12:25
0

Keychain isn't thread-safe. If we try to retrieve the keychain information it returns -25300 from time to time in practice. Be careful.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • 1
    `-25300` = errSecItemNotFound to help those reading; also this answer is only partially accurate -- the accepted answer is accurate. macOS and iOS are **different**. Here, the question clearly states _ios_ thus this answer is incorrect. – Mark Dec 19 '19 at 20:24
  • It may be helpful noting [there are other reasons](https://stackoverflow.com/questions/32721826/keychain-error-25300-errsecitemnotfound-when-disabling-and-re-enabling-touch) that can cause similar result code. – Mark Dec 19 '19 at 20:25
  • @Mark and what? the question of what about thread saving. Not about any other reason of -25300. – Vyacheslav Dec 20 '19 at 12:19
  • @Vyacheslav read [this](https://developer.apple.com/documentation/security/certificate_key_and_trust_services/working_with_concurrency) – Alhomaidhi Sep 11 '21 at 13:11
  • @Vyacheslav Apple docs state "In iOS, all the functions in this API are thread-safe and reentrant." this is in the Security framework and keychain is part of this framework. I have posted the link above. [This is the link to the apple docs once again](https://developer.apple.com/documentation/security/certificate_key_and_trust_services/working_with_concurrency?language=objc). May I ask what your reference is? – Alhomaidhi Sep 14 '21 at 18:28
  • @Alhomaidhi I faced the problem where this isn't correct. – Vyacheslav Sep 24 '21 at 12:25