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

How to disable SSL certificate validation? #70

Open
lmattcris opened this issue Jan 20, 2022 · 3 comments
Open

How to disable SSL certificate validation? #70

lmattcris opened this issue Jan 20, 2022 · 3 comments
Labels

Comments

@lmattcris
Copy link

I have a WebDAV server on a local network, to access it over TLS/SSL I have to set up a certificate with a dummy CA, which is quite annoying.
Can I disable the SSL certificate validation? (Yes I know that this way I'd be losing the trusted CA)

I've found a solution for an HttpClient here, but I'm not sure if/how to employ it with WebDavClient

@skazantsev
Copy link
Owner

Hi @lmattcris,
You can pass an instance of HttpClient when creating WebDavClient. That should do the trick.

@lmattcris
Copy link
Author

@skazantsev That sounds fine, however, I have to admit I have no idea how to pass on the credentials that previously I entered with WebDavClientParams.Credentials ... I mean that otherwise I just filled in a WebDavClientParams object and pass it to the WebDavClient constructor, as in base examples

@lmattcris
Copy link
Author

Oh well, I made it, no matter how dumb I am 😄
I just changed the code to this

            var httpClientHandler = new HttpClientHandler();
            httpClientHandler.ServerCertificateCustomValidationCallback = ( message, cert, chain, sslPolicyErrors ) =>
            {
                return true;
            };
            httpClientHandler.Credentials = new NetworkCredential( "user", "password" );
            HttpClient httpClient = new HttpClient( httpClientHandler ) { BaseAddress = new Uri( server ) };
            WebDavClient client = new WebDavClient( httpClient );

And that worked, even removing the dummy CA, so without a trusted CA. Great!
Still: this is a restricted use, on a local network, possibly not even connected to the internet. I understand that using it outside a controlled environment isn't a good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants