How to validate the server certificate in xamarin forms PCL while calling to the rest calls

In my xamarin forms app i am using HttpClient class to call the rest calls, in my rest url i am using "https" for secure connection every thing is working fine, but the problem is in server certificate is expired even through my rest call is working fine means HttpClient class is bypassing the checks which i dont want. So i want to validate the server certificate host name and expired date etc..

Quick response is highly appreciated.

Posts

  • Taimoor.JanjuaTaimoor.Janjua DEMember ✭✭

    Hello @DVLNarayana,

    I also have a Rest Service and I am using self signed certificate. I can consume my rest service from other machine. I have a problem in android. I am getting this error on consuming my rest service.

    InnerException {System.Net.WebException: Error writing headers ---> System.IO.IOException: Error while sending TLS Alert (Fatal:InternalError): System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: EndRead failure ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.EndReceive (IAsyncResult result) [0x00033] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x0002f] in <filename unknown>:0 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00048] in <filename unknown>:0 at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00019] in <filename unknown>:0 --- End of inner exception stack trace --- at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (IAsyncResult result) [0x0003b] in <filename unknown>:0 at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x0000c] in <filename unknown>:0 ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: EndRead failure ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.EndReceive (IAsyncResult result) [0x00033] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x0002f] in <filename unknown>:0 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00048] in <filename unknown>:0 at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00019] in <filename unknown>:0 --- End of inner exception stack trace --- at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (IAsyncResult result) [0x0003b] in <filename unknown>:0 at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x0000c] in <filename unknown>:0 --- End of inner exception stack trace --- at System.Net.WebConnection.EndWrite (System.Net.HttpWebRequest request, Boolean throwOnError, IAsyncResult result) [0x000a7] in <filename unknown>:0 at System.Net.WebConnectionStream+<SetHeadersAsync>c__AnonStorey1.<>m__0 (IAsyncResult r) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace ---} System.Net.WebException

    Hope to hear from you soon!

  • Taimoor.JanjuaTaimoor.Janjua DEMember ✭✭

    It works fine with HTTP

  • Taimoor.JanjuaTaimoor.Janjua DEMember ✭✭

    Hello All,

    Thanks for the help. I have solved my problem on my own. I wasn't generating the key properly for the encipherment and was using the wrong key provider.

    Regards, Taimoor Janjua

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @Taimoor.Janjua
    Hi

    I wasn't generating the key properly for the encipherment and was using the wrong key provider.

    Can you please explain more in detail, what you have done (step-by-step).
    Thanks :)

Sign In or Register to comment.