Răsfoiți Sursa

Logging SHA-256 of WinSCP.exe, when its product version does not match .NET assembly

(cherry picked from commit 8b3bcbd3ff8729f373e562084eb3cc3a6551dfcc)

Source commit: a22ba21b802e84176cb6a8bff30eda9685c4aa00
Martin Prikryl 5 ani în urmă
părinte
comite
9875f708f3
1 a modificat fișierele cu 16 adăugiri și 0 ștergeri
  1. 16 0
      dotnet/internal/ExeSessionProcess.cs

+ 16 - 0
dotnet/internal/ExeSessionProcess.cs

@@ -11,6 +11,7 @@ using System.Reflection;
 using System.Security.Principal;
 using System.Security.AccessControl;
 using System.ComponentModel;
+using System.Security.Cryptography;
 
 namespace WinSCP
 {
@@ -1055,6 +1056,21 @@ namespace WinSCP
                     }
                     else if (assemblyVersion.ProductVersion != version.ProductVersion)
                     {
+                        try
+                        {
+                            using (SHA256 SHA256 = SHA256.Create())
+                            using (FileStream stream = File.OpenRead(exePath))
+                            {
+                                string sha256 = Convert.ToBase64String(SHA256.ComputeHash(stream));
+                                _logger.WriteLine($"SHA-256 of the executable file is {sha256}");
+                            }
+                        }
+                        catch (Exception e)
+                        {
+                            _logger.WriteLine("Calculating SHA-256 of the executable file failed");
+                            _logger.WriteException(e);
+                        }
+
                         string message;
                         if (string.IsNullOrEmpty(version.ProductVersion) && (accessException != null))
                         {