[Mono-list] Problem with mono and HtttpWebRequest (ssl)

MkProc matthias.ruck at mars-engineering.de
Mon Jun 15 13:59:18 UTC 2015


Hello everyone,

I have the following problem:
I need to check ssl-certificates and also read/output Websites as part of a
program.
For Websites like www.google.com or www.twitter.com it works fine, 
but using my company’s site I always get exceptions like this:

System.Net.WebException: Error getting response stream (Write: The
authentication or decryption has failed.): SendFailure --->
System.IO.IOException: The authentication or decryption has failed. ---> 

Mono.Security.Protocol.Tls.TlsException: The authentication or decryption
has failed.
  at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel
alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback
(IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback
(IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
[0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename
unknown>:0
  at Testprogram.Program.Main (System.String[] args) [0x00000] in <filename
unknown>:0

I already tried using mozroots to get all trusted certificates and also
added the site's certificates manually with certmgr,
but I still get the same errors over and over. I also tried different
machines and different versions of mono, the latest being 4.0.1, to no
avail.

Here’s the test program I tried

using System;
using System.Linq;
using System.Net;

namespace Testprogram
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback =
delegate { return true; };

            if (! args.Any() || string.IsNullOrEmpty(args[0])) return;
            var address = args[0];

            try
            {
                var request = (HttpWebRequest) WebRequest.Create("https://"
+ address);

                using (var response = (HttpWebResponse)
request.GetResponse())
                {
                    response.Close();

                    Console.WriteLine("Certificate recieved: " +
(request.ServicePoint.Certificate != null ? "true" : "false"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }
}

The code works just fine under Windows without Mono, but with Mono, it works
on neither Windows nor Unix.
It also fails if I try to output the site using the following code:

var wr = WebRequest.Create("https://" + address);
var stream = wr.GetResponse().GetResponseStream();
Console.WriteLine(new StreamReader(stream, Encoding.UTF8).ReadToEnd());

The site’s certificate itself should be perfectly fine:
https://www.ssllabs.com/ssltest/analyze.html?d=mars-solutions.de&s=188.40.173.108&hideResults=on

I also tried tlstest.exe, but it fails the same way.
Google also couldn't help me with this.


Greetings



--
View this message in context: http://mono.1490590.n4.nabble.com/Problem-with-mono-and-HtttpWebRequest-ssl-tp4666196.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list