NSURLSession HTTP load failed kCFStreamErrorDomainSSL, -9813 ; Self signing certificate
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In iOS development, working with network communications often involves using NSURLSession for tasks like downloading data from the internet. When dealing with HTTPS requests, which use SSL/TLS protocols for security, a common issue developers encounter is the kCFStreamErrorDomainSSL, -9813 error. This error typically occurs when dealing with self-signed certificates. Below, we'll explore this issue in detail, explaining what it means, why it happens, and how to address it.
Understanding the Error
The error kCFStreamErrorDomainSSL, -9813 indicates a problem with the SSL configuration of the network call. Specifically, it is associated with the inability of NSURLSession to establish a secure connection using SSL/TLS because it cannot validate the trustworthiness of the self-signed certificate provided by the server.
What is a Self-Signed Certificate?
A self-signed certificate is one that is not signed by a trusted Certificate Authority (CA) but rather by the organization or individual that created it. While self-signed certificates can establish secure connections, they are inherently less trusted by client systems because they lack validation from a third-party CA.
Technical Explanation
When you initiate a network request using NSURLSession, it performs several checks to ensure the security and integrity of the connection. One of these checks is the certificate validation, where it verifies that the server's certificate is signed by a trusted CA. In a real-world scenario, certificates signed by well-known CAs are considered trustworthy by default.
Here's where the self-signed certificate issues typically arise. Because they are not signed by a trusted CA, iOS will not automatically trust self-signed certificates, hence the kCFStreamErrorDomainSSL, -9813 error. This is a security feature to prevent man-in-the-middle attacks.
Example Scenario
Imagine you're developing an application that communicates with a development server over HTTPS. To secure the connection, you decide to use a self-signed certificate. When your app tries to connect to this server using NSURLSession, it throws an error similar to:
Related reading
- OAuth with Verification in .NET
- Obscure a UITextField password
- Obscure a UITextField password
- On logout, clear Activity history stack, preventing back button from opening logged-in-only Activities
- NSUserDefaults not cleared after app uninstall on simulator
- NuGet auto package restore does not work with MSBuild
- One istio-ingressgateway and multiple TLS gateways
- Openshift .kubeconfig file and certificate authentication

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.