How to properly disable certificate verification?

28 Views Asked by At

There is a console application (.net 4.8, .net 6.0, VS 2022). I use webdav.Client to access the cloud from two networks - one with Internet access, the other without access. In the network where there is an Internet connection, there are no problems. In a local departmental network (without Internet access), I disable certificate verification, because certificate is designed for an open network - different domains are used.

To disable certificate verification I use the following code:

         private static WebDavClient getClient()
        {
            string nextCloudAddr = Intranet ? "https://drive.domen0.ru" : "https://drive.domen1.ru";
            HttpClientHandler httpClientHandler = new HttpClientHandler();
            httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
            {
                return true;    /// строка ***
            };
            httpClientHandler.UseDefaultCredentials = false;
            httpClientHandler.Credentials = new NetworkCredential(login, passw);
 
            HttpClient httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(nextCloudAddr + "/remote.php/dav/files/логин/replicator/toIntranet/MyEvents/") };
            WebDavClient webdavclient = new WebDavClient(httpClient); ;
            return webdavclient;
 
        }

But on the Intranet this approach either works or stops working. Moreover, if the scheme works, then code gets to the line ***, but in the second case it doesn’t and the program seems to freeze... In this case, restarting the application does not help.

What could be the problem? How else I can disable certificate verification? In the browser, after confirming that I trust this site, the problem does not arise and access to the cloud is open.

How I can fix an issue?

0

There are 0 best solutions below