Implement HWI checksums checking.
ADD
WalletWasabi.Tests/UnitTests/Hwi/HwiBinaryHashesTests.cs
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Security.Cryptography;
+using System.Threading;
+using WalletWasabi.Microservices;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.Hwi
+{
+ public class HwiBinaryHashesTests
+ {
+ /// <summary>
+ /// Verifies HWI binaries distributed with Wasabi Wallet against checksums on https://github.com/bitcoin-core/HWI/releases/.
+ /// </summary>
+ /// <seealso href="https://github.com/bitcoin-core/HWI/releases/download/1.2.1/SHA256SUMS.txt.asc">Our current HWI version is 1.2.1.</seealso>
+ [Fact]
+ public void VerifyHwiBinaryChecksumHashes()
+ {
+ using var cts = new CancellationTokenSource(5_000);
+
+ Dictionary<OSPlatform, string> expectedHashes = new()
+ {
+ { OSPlatform.Windows, "b8b21499592a311cfaa18676280807d6bf674d72cef21409ed265069f6582c1b" },
+ { OSPlatform.Linux, "23ea301117f74561294b5b3ebe1eeb461004aff7e479c4b90a0aaec5924cc677" },
+ { OSPlatform.OSX, "dc516e563db7c0f21b3f017313fc93a2a57f8d614822b8c71f1467a4e5f59dbb" },
+ };
+
+ foreach (var item in expectedHashes)
+ {
+ string binaryFolder = MicroserviceHelpers.GetBinaryFolder(item.Key);
+ string filePath = Path.Combine(binaryFolder, item.Key == OSPlatform.Windows ? "hwi.exe" : "hwi");
+
+ using SHA256 sha256 = SHA256.Create();
+ using FileStream fileStream = File.OpenRead(filePath);
+ Assert.Equal(item.Value, ByteHelpers.ToHex(sha256.ComputeHash(fileStream)).ToLowerInvariant());
+ }
+ }
+ }
+}
\ No newline at end of file

MODIFY
WalletWasabi/Microservices/MicroserviceHelpers.cs
WalletWasabi/Microservices/MicroserviceHelpers.cs
@@ -8,20 +8,40 @@ namespace WalletWasabi.Microservices
public static class MicroserviceHelpers
{
public static string GetBinaryFolder()
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ return GetBinaryFolder(OSPlatform.Windows);
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ {
+ return GetBinaryFolder(OSPlatform.Linux);
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ return GetBinaryFolder(OSPlatform.OSX);
+ }
+ else
+ {
+ throw new NotSupportedException("Operating system is not supported.");
+ }
+ }
+
+ public static string GetBinaryFolder(OSPlatform platform)
{
var fullBaseDirectory = EnvironmentHelpers.GetFullBaseDirectory();
string commonPartialPath = Path.Combine(fullBaseDirectory, "Microservices", "Binaries");
string path;
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (platform == OSPlatform.Windows)
{
path = Path.Combine(commonPartialPath, $"win64");
}
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ else if (platform == OSPlatform.Linux)
{
path = Path.Combine(commonPartialPath, $"lin64");
}
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ else if (platform == OSPlatform.OSX)
{
path = Path.Combine(commonPartialPath, $"osx64");
}

Implement HWI checksums checking.