Skip to content

Commit

Permalink
Deprecate SparkleUpdater SecurityProtocolType prop; don't use Service…
Browse files Browse the repository at this point in the history
…PointManager
  • Loading branch information
Deadpikle committed Oct 16, 2024
1 parent 0b90eec commit 7049354
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/NetSparkle/Downloaders/WebRequestAppCastDataDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ public async Task<string> DownloadAndGetAppCastDataAsync(string url)
{
_appcastUrl = url;
// configure ssl cert link
// .NET 9 -> ServicePointManager is deprecated
// we have the lambda below for trusting all connections anyway, so this
// is sort of redundant at the moment.
#if NETSTANDARD || NET6 || NET7 || NET8
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;

#endif
var handler = new HttpClientHandler();
if (RedirectHandler != null)
{
Expand Down Expand Up @@ -111,7 +115,10 @@ public async Task<string> DownloadAndGetAppCastDataAsync(string url)
if (response.IsSuccessStatusCode)
{
Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
// .NET 9 -> ServicePointManager is deprecated
#if NETSTANDARD || NET6 || NET7 || NET8
ServicePointManager.ServerCertificateValidationCallback -= ValidateRemoteCertificate;
#endif
using (StreamReader reader = new StreamReader(responseStream, GetAppCastEncoding()))
{
return await reader.ReadToEndAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -143,8 +150,10 @@ public async Task<string> DownloadAndGetAppCastDataAsync(string url)
}
else
{
Stream responseStream = await httpClient.GetStreamAsync(url).ConfigureAwait(false);
Stream responseStream = await httpClient.GetStreamAsync(url).ConfigureAwait(false);// .NET 9 -> ServicePointManager is deprecated
#if NETSTANDARD || NET6 || NET7 || NET8
ServicePointManager.ServerCertificateValidationCallback -= ValidateRemoteCertificate;
#endif
using (StreamReader reader = new StreamReader(responseStream, GetAppCastEncoding()))
{
return await reader.ReadToEndAsync().ConfigureAwait(false);
Expand Down
15 changes: 12 additions & 3 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,19 @@ public SparkleUpdater(string appcastUrl, ISignatureVerifier signatureVerifier, s

#region Properties

#if NETSTANDARD || NET6 || NET7 || NET8
/// <summary>
/// The security protocol used by NetSparkle. Setting this property will also set this
/// for the current AppDomain of the caller. Needs to be set to
/// SecurityProtocolType.Tls12 for some cases (such as when downloading from GitHub).
/// </summary>
/// for the current AppDomain of the caller. May need to be set to
/// SecurityProtocolType.Tls12 for some cases (such as when downloading from GitHub);
/// however, if your app is using a more recent version of .NET, you should be OK.
/// See also: https://stackoverflow.com/a/59398678/3938401
/// .NET 9 -> ServicePointManager is deprecated
/// </summary>
[Obsolete("Deprecated in .NET 9; this property may be removed at any time " +
"(including minor/patch updates to this library); override pertinent " +
"functions (e.g. to HttpClient) in WebRequestAppCastDataDownloader or " +
"similar to make equivalent changes to your application")]
public SecurityProtocolType SecurityProtocolType
{
get
Expand All @@ -166,6 +174,7 @@ public SecurityProtocolType SecurityProtocolType
ServicePointManager.SecurityProtocol = value;
}
}
#endif

/// <summary>
/// Set the user interaction mode for Sparkle to use when there is a valid update for the software
Expand Down

0 comments on commit 7049354

Please sign in to comment.