iOS SecTrustRef Always NULL iOS SecTrustRef Always NULL ios ios

iOS SecTrustRef Always NULL


Since there seems to be some interest in this question I decided to update the question with a answer with details on how this problem was eventually solved.

First some background. I inherited this code from a previous developer and my role was to get the broken code to work.

I spent a lot of time writing and re-writing the connection code using the details from the Apple iOS developer web page, but nothing seemed to work.

I finally decided to take a closer look at this function, code I had inherited and incorrectly assumed was working:

[self loadClientCertificates:certificates];

At first glance the code looked OK. The function did nothing more than load certificates from file. But on closer inspection, while the code was loading the certificates correctly, it was not returning those certificates to the caller!!!

After fixing that code so that it correctly returned the certificates the connection code worked fine and the SecTrustRef was no longer NULL.

In summary:

1) The Apple documentation, while lacking good examples does appear to be accurate.

2) The reason the SecTrustRef was NULL was because no valid certificate could be found for the connection negotiations phase and that was because no certificates where being made available to the connection API due to the earlier mentioned coding error.

3) If you are seeing a similar error, my suggestion would be to check and double check your code, because as would be expected, the iOS side of the equation works as documented.


I recently created an Obj-C package to handle TLS taking into account the latest restrictions imposed by Apple. Getting the certificates right is a very important step.

https://github.com/eamonwhiter73/IOSObjCWebSockets


matomo