mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 15:29:26 +01:00
CP-31587 added a checksum check to download and install client action
Signed-off-by: Christophe25 <christopher.lancaste1@citrix.com>
This commit is contained in:
parent
c1c8c3d1c3
commit
75f9b402ec
@ -44,6 +44,7 @@ namespace XenAdmin.Alerts
|
||||
{
|
||||
NewVersion = version;
|
||||
_timestamp = NewVersion.TimeStamp;
|
||||
Checksum = version.Checksum;
|
||||
}
|
||||
|
||||
public override AlertPriority Priority => AlertPriority.Priority5;
|
||||
@ -72,8 +73,10 @@ namespace XenAdmin.Alerts
|
||||
get {
|
||||
// TODO: Implement proper check in CP-31587
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Checksum = string.Empty;
|
||||
|
||||
static int DISMISSED_XC_VERSIONS_LIMIT = 5;
|
||||
|
||||
|
@ -3332,7 +3332,7 @@ namespace XenAdmin
|
||||
|
||||
private void updateToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var downloadAndInstallClientAction = new DownloadAndUpdateClientAction(updateAlert.Name, new Uri(updateAlert.NewVersion.Url), Path.Combine(Path.GetTempPath(), $"{updateAlert.Name}.msi"), true);
|
||||
var downloadAndInstallClientAction = new DownloadAndUpdateClientAction(updateAlert.Name, new Uri(updateAlert.NewVersion.Url), Path.Combine(Path.GetTempPath(), $"{updateAlert.Name}.msi"), true, updateAlert.Checksum);
|
||||
|
||||
using (var dlg = new ActionProgressDialog(downloadAndInstallClientAction, ProgressBarStyle.Marquee))
|
||||
dlg.ShowDialog(Parent);
|
||||
|
@ -978,8 +978,7 @@ namespace XenAdmin.TabPages
|
||||
alert.FixLinkAction.Invoke();
|
||||
}
|
||||
|
||||
//do not register the event ShowUserInstruction; we show explicitly a message afterwards
|
||||
var downloadAndInstallClientAction = new DownloadAndUpdateClientAction(alert.Name, new Uri(alert.NewVersion.Url), Path.Combine(Path.GetTempPath(), $"{alert.Name}.msi"), true) ;
|
||||
var downloadAndInstallClientAction = new DownloadAndUpdateClientAction(alert.Name, new Uri(alert.NewVersion.Url), Path.Combine(Path.GetTempPath(), $"{alert.Name}.msi"), true, alert.Checksum) ;
|
||||
|
||||
using (var dlg = new ActionProgressDialog(downloadAndInstallClientAction, ProgressBarStyle.Marquee))
|
||||
dlg.ShowDialog(Parent);
|
||||
|
@ -43,8 +43,9 @@ namespace XenAdmin.Core
|
||||
public string Url;
|
||||
public string Lang;
|
||||
public DateTime TimeStamp;
|
||||
public string Checksum;
|
||||
|
||||
public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp)
|
||||
public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp, string checksum = "")
|
||||
{
|
||||
ParseVersion(version_lang);
|
||||
Name = name;
|
||||
@ -52,6 +53,7 @@ namespace XenAdmin.Core
|
||||
LatestCr = latest_cr;
|
||||
Url = url;
|
||||
DateTime.TryParse(timestamp, out TimeStamp);
|
||||
Checksum = checksum;
|
||||
}
|
||||
|
||||
private void ParseVersion(string version_lang)
|
||||
|
@ -37,6 +37,9 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using XenCenterLib;
|
||||
using System.Text;
|
||||
|
||||
namespace XenAdmin.Actions
|
||||
{
|
||||
@ -57,12 +60,13 @@ namespace XenAdmin.Actions
|
||||
private readonly bool downloadUpdate;
|
||||
private DownloadState updateDownloadState;
|
||||
private Exception updateDownloadError;
|
||||
private string checksum;
|
||||
|
||||
public string PatchPath { get; private set; }
|
||||
|
||||
public string ByteProgressDescription { get; set; }
|
||||
|
||||
public DownloadAndUpdateClientAction(string updateName, Uri uri, string outputFileName, bool suppressHist, params string[] updateFileExtensions)
|
||||
public DownloadAndUpdateClientAction(string updateName, Uri uri, string outputFileName, bool suppressHist, string checksum, params string[] updateFileExtensions)
|
||||
: base(null, uri == null
|
||||
? string.Format(Messages.UPDATES_WIZARD_EXTRACT_ACTION_TITLE, updateName)
|
||||
: string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_TITLE, updateName), string.Empty, suppressHist)
|
||||
@ -71,6 +75,7 @@ namespace XenAdmin.Actions
|
||||
address = uri;
|
||||
downloadUpdate = address != null;
|
||||
this.outputPathAndFileName = outputFileName;
|
||||
this.checksum = checksum;
|
||||
}
|
||||
|
||||
private WebClient client;
|
||||
@ -187,32 +192,69 @@ namespace XenAdmin.Actions
|
||||
if (Cancelling)
|
||||
throw new CancelledException();
|
||||
}
|
||||
|
||||
// Install the downloaded msi
|
||||
try
|
||||
if (ValidMsi())
|
||||
{
|
||||
// Start the install process and end current
|
||||
if (File.Exists(outputPathAndFileName))
|
||||
// Install the downloaded msi
|
||||
try
|
||||
{
|
||||
// Launch downloaded msi
|
||||
Process.Start(outputPathAndFileName);
|
||||
log.DebugFormat("Update {0} found and install started", updateName);
|
||||
// Start the install process and end current
|
||||
if (File.Exists(outputPathAndFileName))
|
||||
{
|
||||
// Launch downloaded msi
|
||||
Process.Start(outputPathAndFileName);
|
||||
log.DebugFormat("Update {0} found and install started", updateName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (File.Exists(outputPathAndFileName))
|
||||
catch (Exception e)
|
||||
{
|
||||
File.Delete(outputPathAndFileName);
|
||||
if (File.Exists(outputPathAndFileName))
|
||||
{
|
||||
File.Delete(outputPathAndFileName);
|
||||
}
|
||||
log.Error("Exception occurred when installing CHC.", e);
|
||||
throw;
|
||||
}
|
||||
log.Error("Exception occurred when installing CHC.", e);
|
||||
throw;
|
||||
}
|
||||
|
||||
Description = Messages.COMPLETED;
|
||||
MarkCompleted();
|
||||
}
|
||||
|
||||
private bool ValidMsi()
|
||||
{
|
||||
using (FileStream stream = new FileStream(outputPathAndFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var hash = StreamUtilities.ComputeHash(stream, out var hashAlgorithm);
|
||||
//Convert to Hex string
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var b in hash)
|
||||
{
|
||||
sb.Append(b.ToString("x2"));
|
||||
}
|
||||
var calculatedChecksum = sb.ToString();
|
||||
// Check if calculatedChecksum matches what is in chcupdates.xml
|
||||
if (checksum != calculatedChecksum)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
// TODO: Check digital signature of .msi
|
||||
|
||||
}
|
||||
// Display the byte array in a readable format.
|
||||
public static void PrintByteArray(byte[] array)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
Console.Write($"{array[i]:X2}");
|
||||
if ((i % 4) == 3) Console.Write(" ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
int pc = (int)(95.0 * e.BytesReceived / e.TotalBytesToReceive);
|
||||
|
@ -110,6 +110,7 @@ namespace XenAdmin.Actions
|
||||
bool latest_cr = false;
|
||||
string url = "";
|
||||
string timestamp = "";
|
||||
string checksum = "";
|
||||
|
||||
foreach (XmlAttribute attrib in version.Attributes)
|
||||
{
|
||||
@ -125,9 +126,11 @@ namespace XenAdmin.Actions
|
||||
url = attrib.Value;
|
||||
else if (attrib.Name == "timestamp")
|
||||
timestamp = attrib.Value;
|
||||
else if (attrib.Name == "checksum")
|
||||
checksum = attrib.Value;
|
||||
}
|
||||
|
||||
ClientVersions.Add(new ClientVersion(version_lang, name, latest, latest_cr, url, timestamp));
|
||||
ClientVersions.Add(new ClientVersion(version_lang, name, latest, latest_cr, url, timestamp, checksum));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user