Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

SslStream AuthenticateAsClient hangs

markgamachemarkgamache USBeta ✭✭
edited September 2015 in Xamarin.Android

I am trying to create a secure connection to a TcpServer. The server is written in .net using the TCPListener class +sslStream. I have written a test client in c# for the desktop that works fine (with the same self cert), but the equivalent Xamarin Android code fails.

     var clientCertificate = new  X509Certificate2(ReadAllBytes(context.Assets.Open("selfcert.pfx")),"password");
    var clientCertificateCollection = new X509CertificateCollection(new X509Certificate[] { clientCertificate });
    _netclient = new TcpClient ();
     _netclient.Connect (ipaddress, port);
     _sslStream = new SslStream (_netclient.GetStream (), false, App_CertificateValidation);
    _sslStream.AuthenticateAsClient("servercertname", clientCertificateCollection, SslProtocols.Tls12, false); <-- this never returns

note:App_CertificateValidation never gets called`


  • markgamachemarkgamache USBeta ✭✭
    edited September 2015

    When I run the desktop version of the client on the .net CLR it works fine. Running the same exe via Mono 4.0.3 results in the same hanging as the Android app. So this is either a bug in Mono's implementation of client certificates or some type of Mono difference due to cross platform issues. Are there any Mono specific differences that are causing the issue?

  • 1iveowl1iveowl USMember ✭✭

    Did you ever find a solution to this? I'm seeing the same issue running todays latest Xamarin build, which I believe is running mono

  • StephenHeindelStephenHeindel USMember
    edited February 2017

    I'm dealing with this same issue, did any of you ever come up with a solution or a workaround? In my situation, I can connect to my server application running Mono with no issues, but when I connect to my server on Windows, and then disconnect and attempt to connect to my server running on Mono again, it won't authenticate. When I close the app entirely, I can reconnect. I believe it has to do with the internal static SSL session cache in the System.Net.Security namespace which would get re-initialized on a fresh start, but I don't know how to work around it.

  • EmilMller.4175EmilMller.4175 NOMember ✭✭

    Uh oh. Why doesn't this get fixed? This is a major bug :s:'(:*

Sign In or Register to comment.