Search Unity

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

Discussion in 'Scripting' started by garcia-raul, Apr 17, 2017.

  1. garcia-raul

    garcia-raul

    Joined:
    Dec 8, 2014
    Posts:
    10
    Hello!
    I have a script that call a webservice over https build with swagger in C# and I´m getting: Error calling AuthenticatePost: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure

    I already imported all the certifies from the moztools.exe and even used certmgr.exe to add the url from where I call the webservice, but it didnt worked.

    Now I´m using the ServicePointManager.ServerCertificateValidationCallback but it never enters my callback, here is my code:
    Code (CSharp):
    1.     public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
    2.             Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
    3.             Dictionary<String, FileParameter> fileParams, String[] authSettings)
    4.         {
    5.             var request = new RestRequest(path, method);
    6.  
    7.  
    8.         //UpdateParamsForAuth(queryParams, headerParams, authSettings);
    9.  
    10.         // add default header, if any
    11.         foreach(var defaultHeader in _defaultHeaderMap)
    12.             request.AddHeader(defaultHeader.Key, defaultHeader.Value);
    13.  
    14.         // add header parameter, if any
    15.         foreach(var param in headerParams)
    16.             request.AddHeader(param.Key, param.Value);
    17.  
    18.         // add query parameter, if any
    19.         foreach(var param in queryParams)
    20.             request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
    21.  
    22.         // add form parameter, if any
    23.         foreach(var param in formParams)
    24.             request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
    25.  
    26.         // add file parameter, if any
    27.         foreach(var param in fileParams)
    28.             request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
    29.  
    30.         if (postBody != null) // http body (model) parameter
    31.             request.AddParameter("application/json", postBody, ParameterType.RequestBody);
    32.  
    33.         ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
    34.         return (Object)RestClient.Execute(request);
    35.     }
    36.  
    37.     public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    38.     {
    39.         UnityEngine.Debug.Log("MyRemoteCertificateValidationCallback");
    40.         bool isOk = true;
    41.         // If there are errors in the certificate chain, look at each error to determine the cause.
    42.         if (sslPolicyErrors != SslPolicyErrors.None)
    43.         {
    44.             for (int i = 0; i < chain.ChainStatus.Length; i++)
    45.             {
    46.                 if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown)
    47.                 {
    48.                     chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
    49.                     chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
    50.                     chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
    51.                     chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
    52.                     bool chainIsValid = chain.Build((X509Certificate2)certificate);
    53.                     if (!chainIsValid)
    54.                     {
    55.                         isOk = false;
    56.                     }
    57.                 }
    58.             }
    59.         }
    60.         return isOk;
    61.     }
    Why eventhoughI added the certificates it doesnt work, and why is the delegate callback not being called?

    Thanks in advance.
     
    tomfurrier likes this.
  2. AuraCS

    AuraCS

    Joined:
    Jun 3, 2014
    Posts:
    2
    Did you find a solution? I'm having the same error with WebClient in Unity.
     
    DeveshPandey likes this.