I was using iOS to connect to a server using a certificate whose CN (commonname) and FQDN (fully qualified domain name) is server.myexample.com
. The server certificate was signed by my own Root CA (whose certificate I added to my anchor certs via SecTrustSetAnchorCertificates
and verified via the method described here using NSURLAuthenticationChallenge
).
With my iOS client, I was attempting to connect my REST service located at: server.myexample.com/Path1/service1
, but I kept receiving the following error:
The certificate for this server is invalid. You might be connecting to a server
that is pretending to be “server.myexample.com” which could put your confidential
information at risk.
Error occurred while fetching https://server.myexample.com/Path1/service1: Error
Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid.
You might be connecting to a server that is pretending to be “server.myexample.com”
which could put your confidential information at risk."
I get additional messages with the same info but specifying the errors: NSErrorFailingURLStringKey
and NSURLErrorFailingURLPeerTrustErrorKey
.
I found that I could also call the service with server.myexample.com/service1
and removed Path1 from my request URL, and the server certificate verification worked correctly. Why is this? I was under the impression that the server only needed 1 certificate, meaning any services it hosts would also be using that same certificate. Maybe you need a separate server certificate per path? I was not aware the paths after the server ip address/domain needed to have their own certificate.
To summarize:
- iOS client app with Root CA certificate in the anchor certs
- Server
server1
's certificate signed by Root CA has a CN ofserver.myexample.com
and whose FQDN ishttps://server.myexample.com
. - Server
server.myexample.com
hostsservice1
which can be accessed by web browser via:https://server.myexample.com/service1
(passes iOS client's authentication of server)https://server.myexample.com/Path1/service1
(FAILS iOS client's authentication of server)
- CA and server certificates were created via OpenSSL
Thanks in advance!