Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: SecureChannelFailure (The authentication or decryption has failed.) #1034

Closed
loretoparisi opened this issue Aug 2, 2016 · 2 comments

Comments

@loretoparisi
Copy link

I have generated the C# and the C# .NET 2.0 clients, the I did the build to get the dll in the bin folder.
As soon as I put this in a Xamarin Android example project and I do a http call I get this error:

W/SWAGGER (21249): Exception when calling DefaultApi.AlbumGetGet: Error calling AlbumGetGet: Error: SecureChannelFailure (The authentication or decryption has failed.)

I'm not sure if this is related to mono or to the way the swagger auto generated client is using TLS in the http module, since the calls are over https.

@loretoparisi
Copy link
Author

Adding here, that from the client point of view (the auto generated client), it could be a mono issue, but if is so, this

System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                   System.Security.Cryptography.X509Certificates.X509Chain chain,
                                   System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
               return true; // **** Always accept
            };
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

where MyRemoteCertificateValidationCallback is

public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            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;
        }

should bypass the problem, while it does not solve it. See here for more details about it.

@webron
Copy link
Contributor

webron commented Aug 2, 2016

This issue was moved to swagger-api/swagger-codegen#3505

@webron webron closed this as completed Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants