CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

Wikipedia requires TLS1.2; Fx4.5 does not use it by default #66

Closed DavidWBrooks closed 4 years ago

DavidWBrooks commented 4 years ago

Since late January 2020, English Wikipedia/Wikisource (and probably everything else) required TLS 1.2 for connections. Framework 4.5 by default only goes up to 1.1. (Framework 4.8 uses the OS default, which is 1.2 on Windows 10). This makes the demo apps fail on startup.

If using 4.5, it's necessary to execute the following somewhere before the first HTTP transaction: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; (using System.Net)

Verified by adding the line to the console and WPF apps, but it should probably be in the API in a path that's always executed during initialization.

DavidWBrooks commented 4 years ago

Addendum: the problem with the 4.5 workaround is that it isn't future-proof (one day WP may require 1.3 for example). Fx 4.7 is slightly better; currently TLS1.2 is the Win10 default: ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; Fx 4.8 lets you apply it per-client: HttpClientHandler.SslProtocols = SslProtocols.None; which again lets the OS decide. Or you can specify a collection of protocols, currently only up to TLS1.3.

CXuesong commented 4 years ago

Thanks for your detailed report! I feel that choosing the correct TLS version is the responsibility of WCL users. After all, not all users are using this library against WP, and I don't think it a good idea to do global configuration change in our library "for sake of" consumer.

However, I think we may offer some clearer error message, providing a link to FAQ for this purpose...

DavidWBrooks commented 4 years ago

OK, but at least let's add the fix to the demo apps (which would also be a good model). I can volunteer to do that; I need to learn how to handle pull requests anyway... You can provide the error message; it will require unpicking the big AggregateException, I think.

CXuesong commented 4 years ago

OK, but at least let's add the fix to the demo apps (which would also be a good model).

Oops. Just forgot that 🌚

But if you see any further issue, don't hesitate to open a PR!