SSL with Self Signed Certificate on iOS - possible?

Has anyone had any success using a self signed certificate on iOS?

Attempting to do a WWW https call in Unity iOS build generates the error:

Error: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “sub.domain.com” which could put your confidential information at risk.

On Android this is worked around by replacing the trust manager using the method shown here: http://luz.4science.co/unity-android-and-ssl-sslhandshakeexceptioncertpathvalidatorexception/

I can’t find a similar solution for Unity/iOS… Does one exist?

Any ideas greatly appreciated.

Unity/WWWConnection.mm

// If you need to communicate with HTTPS server with self signed certificate you might consider UnityWWWConnectionSelfSignedCertDelegate
// Though use it on your own risk. Blindly accepting self signed certificate is prone to MITM attack

//const char* WWWDelegateClassName     = "UnityWWWConnectionSelfSignedCertDelegate";
const char* WWWDelegateClassName     = "UnityWWWConnectionDelegate";
1 Like

Ha, too simple! Thanks Alexey - that’s exactly what I needed.

where do i put this c# script, in unity or xcode?

// If you need to communicate with HTTPS server with self signed certificate you might consider UnityWWWConnectionSelfSignedCertDelegate
// Though use it on your own risk. Blindly accepting self signed certificate is prone to MITM attack
//const char* WWWDelegateClassName     = "UnityWWWConnectionSelfSignedCertDelegate";
const char* WWWDelegateClassName     = "UnityWWWConnectionDelegate";

In XCode, you’ll find the file in your XCode project, this needs to be modified every time you rebuild (including append) from Unity as Unity will overwrite the file each time.

It doesn’t work for me.
I still get the “The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.mywebsite” which could put your confidential information at risk.” message after uncommenting the UnityWWWConnectionSelfSignedCertDelegate line.
Is there anything else to do?

So did you make it look like:

// If you need to communicate with HTTPS server with self signed certificate you might consider UnityWWWConnectionSelfSignedCertDelegate
// Though use it on your own risk. Blindly accepting self signed certificate is prone to MITM attack
const char* WWWDelegateClassName     = "UnityWWWConnectionSelfSignedCertDelegate";
//const char* WWWDelegateClassName     = "UnityWWWConnectionDelegate";

I’ve done this recently and it works 100% fine for me, remember if you rebuild from Unity it will overwrite this file every time and you need to make the changes again (unless you script is some way).

Yes, I did make it look like that, cleaned and rebuilt and it is still giving me the “The certificate for this server is invalid. You might be connecting to a server that is pretending to be” error.
I didn’t rebuild from Unity.

Hmm, this worked perfectly for me so I’m at a loss what could be wrong.

Is there any chance that your cert doesn’t match your domain properly?

The “Common Name” will need to match the exact domain name you’re connecting to…

Same problem here. Does this only work for WWW but not for WWWForm?

I have the same problem with my WWWForm. I have tried so many solution, but nothing helps.
Should I try this in combination with AllowArbitraryLoads in plist?
//const char* WWWDelegateClassName = “UnityWWWConnectionSelfSignedCertDelegate”;

Or are there cases in which there is no way to allow insecure certificates? (certificate on wrong domain perhaps?) Our test environment is a bit of a mess.

Not a solution for self certs, but you could use a free cert from: https://letsencrypt.org

Yeah, we ended up fixing the certificate in our test environment… less work than this XCode mayhem

I am facing the same issue. Trying to download something using www and I am setting //const char* WWWDelegateClassName = “UnityWWWConnectionSelfSignedCertDelegate”; too still getting

Error: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “sub.domain.com” which could put your confidential information at risk.

Anyone who have fixed this and how please let us know. It’s a kind of show stopper for us. Thanks!

Have you tried the solutions proposed in this thread?