How to use swagger in C# DotNet2 over https

52 views
Skip to first unread message

ra...@vizzario.com

unread,
Apr 18, 2017, 2:20:49 AM4/18/17
to Swagger
Hi! I got a Unity Mono c# swagger client generated, so when I run the code over http; it runs fine, but if I run it over https, I get 

Error getting response stream (Write: The authentication or decryption has failed.): SendFailure


I try using certmgr.exe to add the certificate and also used the mozilla tools, but it doesnt work.
In stackoverflow they mentioned that in order to bypass the certificate I should use:
    void OnEnable()
    {
        Debug.Log("OnEnable********");

        ServicePointManager.ServerCertificateValidationCallback += MyRemoteCertificateValidationCallback;
    }

public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    UnityEngine.Debug.Log("MyRemoteCertificateValidationCallback");
    bool isOk = true;
    // If there are errors in the certificate chain, look at each error to determine the cause.
    if (sslPolicyErrors != SslPolicyErrors.None)
    {
        for (int i = 0; i < chain.ChainStatus.Length; i++)
        {
            if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown)
            {
                chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
                chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
                chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
                chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
                bool chainIsValid = chain.Build((X509Certificate2)certificate);
                if (!chainIsValid)
                {
                    isOk = false;
                }
            }
        }
    }
    return isOk;
}
, but it doesnt work. and the callback never gets called. How do you make swagger be able to run in https?
Thanks in advance.
Reply all
Reply to author
Forward
0 new messages