use local instead of property
MODIFY
WalletWasabi/Services/UpdateManager.cs
WalletWasabi/Services/UpdateManager.cs
@@ -19,7 +19,6 @@ namespace WalletWasabi.Services;
public class UpdateManager : IDisposable
{
private string InstallerPath { get; set; } = "";
- private string Sha256SumsFilePath { get; set; } = "";
private const byte MaxTries = 2;
private const string ReleaseURL = "https://api.github.com/repos/zkSNACKs/WalletWasabi/releases/latest";
@@ -83,7 +82,8 @@ public class UpdateManager : IDisposable
/// <param name="targetVersion">This does not contains the revision number, because backend always sends zero.</param>
private async Task<(string filePath, Version newVersion)> GetInstallerAsync(Version targetVersion)
{
- (Version newVersion, string url, string installerFileName) = await GetLatestReleaseFromGithubAsync(targetVersion).ConfigureAwait(false);
+ var sha256SumsFilePath = Path.Combine(InstallerDir, "SHA256SUMS.asc");
+ (Version newVersion, string url, string installerFileName) = await GetLatestReleaseFromGithubAsync(targetVersion, sha256SumsFilePath).ConfigureAwait(false);
var installerFilePath = Path.Combine(InstallerDir, installerFileName);
@@ -104,7 +104,7 @@ public class UpdateManager : IDisposable
await CopyStreamContentToFileAsync(stream, installerFilePath).ConfigureAwait(false);
}
- await VerifyInstallerHashAsync(installerFileName, installerFilePath, newVersion).ConfigureAwait(false);
+ await VerifyInstallerHashAsync(installerFileName, installerFilePath, sha256SumsFilePath, newVersion).ConfigureAwait(false);
}
catch (IOException)
{
@@ -115,21 +115,21 @@ public class UpdateManager : IDisposable
return (installerFilePath, newVersion);
}
- private async Task VerifyInstallerHashAsync(string expectedFileName, string installerFilePath, Version version)
+ private async Task VerifyInstallerHashAsync(string expectedFileName, string installerFilePath, string sha256SumsFilePath, Version version)
{
var bytes = await WasabiSignerHelpers.GetShaComputedBytesOfFileAsync(installerFilePath, CancellationToken).ConfigureAwait(false);
string downloadedHash = Convert.ToHexString(bytes).ToLower();
- string expectedHash = await GetHashFromSha256SumsFileAsync(expectedFileName, version).ConfigureAwait(false);
+ string expectedHash = await GetHashFromSha256SumsFileAsync(expectedFileName, sha256SumsFilePath, version).ConfigureAwait(false);
if (expectedHash != downloadedHash)
{
throw new InvalidOperationException("Downloaded file hash doesn't match expected hash.");
}
}
- private async Task<string> GetHashFromSha256SumsFileAsync(string installerFileName, Version newVersion)
+ private async Task<string> GetHashFromSha256SumsFileAsync(string installerFileName, string sha256SumsFilePath, Version newVersion)
{
- string[] lines = await File.ReadAllLinesAsync(Sha256SumsFilePath).ConfigureAwait(false);
+ string[] lines = await File.ReadAllLinesAsync(sha256SumsFilePath).ConfigureAwait(false);
var installerLines = lines.Where(line => line.Contains($"Wasabi-{newVersion}")).ToList();
var correctLine = installerLines.FirstOrDefault(line => line.Contains(installerFileName));
if (correctLine == null)
@@ -157,7 +157,7 @@ public class UpdateManager : IDisposable
File.Move(tmpFilePath, filePath);
}
- private async Task<(Version Version, string DownloadUrl, string FileName)> GetLatestReleaseFromGithubAsync(Version targetVersion)
+ private async Task<(Version Version, string DownloadUrl, string FileName)> GetLatestReleaseFromGithubAsync(Version targetVersion, string sha256SumsFilePath)
{
using HttpRequestMessage message = new(HttpMethod.Get, ReleaseURL);
message.Headers.UserAgent.Add(new("WalletWasabi", "2.0"));
@@ -183,7 +183,7 @@ public class UpdateManager : IDisposable
assetDownloadUrls.Add(asset["browser_download_url"]?.ToString() ?? throw new InvalidDataException("Missing download url from response."));
}
- bool isReleaseValid = await ValidateWasabiSignatureAsync(assetDownloadUrls).ConfigureAwait(false);
+ bool isReleaseValid = await ValidateWasabiSignatureAsync(assetDownloadUrls, sha256SumsFilePath).ConfigureAwait(false);
if (!isReleaseValid)
{
throw new InvalidOperationException($"Downloading new release was aborted, Wasabi signature was invalid.");
@@ -193,9 +193,8 @@ public class UpdateManager : IDisposable
return (githubVersion, url, fileName);
}
- private async Task<bool> ValidateWasabiSignatureAsync(List<string> assetDownloadUrls)
+ private async Task<bool> ValidateWasabiSignatureAsync(List<string> assetDownloadUrls, string sha256SumsFilePath)
{
- var sha256SumsFilePath = Path.Combine(InstallerDir, "SHA256SUMS.asc");
var wasabiSigFilePath = Path.Combine(InstallerDir, "SHA256SUMS.wasabisig");
using HttpClient httpClient = new();
@@ -207,7 +206,6 @@ public class UpdateManager : IDisposable
using (var stream = await httpClient.GetStreamAsync(sha256SumsUrl, CancellationToken).ConfigureAwait(false))
{
await CopyStreamContentToFileAsync(stream, sha256SumsFilePath).ConfigureAwait(false);
- Sha256SumsFilePath = sha256SumsFilePath;
}
using (var stream = await httpClient.GetStreamAsync(wasabiSigUrl, CancellationToken).ConfigureAwait(false))

use local instead of property