Search Unity

Tell UnityWebRequest to trust invalid SSL certs or convert HTTPWebRequest

Discussion in 'Scripting' started by montag64, Sep 24, 2016.

  1. montag64

    montag64

    Joined:
    Mar 15, 2014
    Posts:
    23
    Hey guys,

    I'd like to use the new UnityWebRequest in UnityEngine.Networking but I don't know how to tell it to ignore invalid certs or add them as trusted somehow. It's easy to do that with C#'s built in HTTP requests. You just need to tell the ServicePointManager to trust the cert. My dev server has an unsigned cert and I see no need to buy an SSL cert for it since it's not public-facing.

    Code (CSharp):
    1.  
    2. //TrustCertificate is just a method that returns true for invalid types of certs
    3. ServicePointManager.ServerCertificateValidationCallback=TrustCertificate;
    4.  
    5. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://invaliddevcert.com/do_stuff.php?");
    6. HttpWebResponse response =(HttpWebResponse) request.GetResponse()
    7. ....
    8.  
    This has been asked before by a few people on Answers but appears to be unresolved.

    I dug through the UnityEngine.Networking source that is available at https://bitbucket.org/Unity-Technologies/networking/overview but I think that gets me nowhere because the NetworkTransport functions are not open sourced (where I suspect the UnityWebRequest method exists). Per the readme:

    "The Unity Networking extension DLL is the open source component of the Unity Multiplayer Networking system. In this DLL we have the whole networking system except the NetworkTransport related APIs and classes..."

    I figure I have the following options:

    1. Try to convert an HttpWebRequest to a UnityWebRequest object
    2. Still somehow attempt to extend the Networking class
    3. Use HttpWebRequest for everything, which restricts the game to certain platforms
    4. Throw hands up as I'm SOL and put in a feature request.

    Any other ideas?