@joebigelow / wix / commits / 914a92d1

Supply hashes to BA if present in update feed.

Fixes https://github.com/wixtoolset/issues/issues/6353.

Bob Arnson committed Aug 31, 2022 at 16:07 UTC 914a92d16d7a0245f3cf0b42cc5e320c34d23d30
12 files changed +58 -10
src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h
+2
@@ -870,6 +870,8 @@ struct BA_ONDETECTUPDATE_ARGS
870 DWORD cbSize;
871 LPCWSTR wzUpdateLocation;
872 DWORD64 dw64Size;
873 + LPCWSTR wzHash;
874 + BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm;
875 LPCWSTR wzVersion;
876 LPCWSTR wzTitle;
877 LPCWSTR wzSummary;
src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs
+2 -2
@@ -1451,9 +1451,9 @@ namespace WixToolset.Mba.Core
1451 return args.HResult;
1452 }
1453
1454 - int IBootstrapperApplication.OnDetectUpdate(string wzUpdateLocation, long dw64Size, string wzVersion, string wzTitle, string wzSummary, string wzContentType, string wzContent, ref bool fCancel, ref bool fStopProcessingUpdates)
1454 + int IBootstrapperApplication.OnDetectUpdate(string wzUpdateLocation, long dw64Size, string wzHash, UpdateHashType hashAlgorithm, string wzVersion, string wzTitle, string wzSummary, string wzContentType, string wzContent, ref bool fCancel, ref bool fStopProcessingUpdates)
1455 {
1456 - DetectUpdateEventArgs args = new DetectUpdateEventArgs(wzUpdateLocation, dw64Size, wzVersion, wzTitle, wzSummary, wzContentType, wzContent, fCancel, fStopProcessingUpdates);
1456 + DetectUpdateEventArgs args = new DetectUpdateEventArgs(wzUpdateLocation, dw64Size, wzHash, hashAlgorithm, wzVersion, wzTitle, wzSummary, wzContentType, wzContent, fCancel, fStopProcessingUpdates);
1457 this.OnDetectUpdate(args);
1458
1459 fCancel = args.Cancel;
src/api/burn/WixToolset.Mba.Core/EventArgs.cs
+14 -1
@@ -5,6 +5,7 @@ namespace WixToolset.Mba.Core
5 using System;
6 using System.Collections.Generic;
7 using System.Collections.ObjectModel;
8 + using System.Runtime.InteropServices;
9
10 /// <summary>
11 /// Base class for BA <see cref="EventArgs"/> classes.
@@ -328,11 +329,13 @@ namespace WixToolset.Mba.Core
329 public class DetectUpdateEventArgs : CancellableHResultEventArgs
330 {
331 /// <summary />
331 - public DetectUpdateEventArgs(string updateLocation, long size, string version, string title, string summary, string contentType, string content, bool cancelRecommendation, bool stopRecommendation)
332 + public DetectUpdateEventArgs(string updateLocation, long size, string hash, UpdateHashType hashAlgorithm, string version, string title, string summary, string contentType, string content, bool cancelRecommendation, bool stopRecommendation)
333 : base(cancelRecommendation)
334 {
335 this.UpdateLocation = updateLocation;
336 this.Size = size;
337 + this.Hash = hash;
338 + this.HashAlgorithm = hashAlgorithm;
339 this.Version = version;
340 this.Title = title;
341 this.Summary = summary;
@@ -351,6 +354,16 @@ namespace WixToolset.Mba.Core
354 /// </summary>
355 public long Size { get; private set; }
356
357 + /// <summary>
358 + /// File hash of the updated bundle.
359 + /// </summary>
360 + public string Hash { get; }
361 +
362 + /// <summary>
363 + /// The algorithm of the updated bundle's hash.
364 + /// </summary>
365 + public UpdateHashType HashAlgorithm { get; }
366 +
367 /// <summary>
368 /// Gets the version of the updated bundle.
369 /// </summary>
src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs
+4
@@ -106,6 +106,8 @@ namespace WixToolset.Mba.Core
106 /// <param name="wzUpdateLocation"></param>
107 /// <param name="dw64Size"></param>
108 /// <param name="wzVersion"></param>
109 + /// <param name="wzHash"></param>
110 + /// <param name="hashAlgorithm"></param>
111 /// <param name="wzTitle"></param>
112 /// <param name="wzSummary"></param>
113 /// <param name="wzContentType"></param>
@@ -118,6 +120,8 @@ namespace WixToolset.Mba.Core
120 int OnDetectUpdate(
121 [MarshalAs(UnmanagedType.LPWStr)] string wzUpdateLocation,
122 [MarshalAs(UnmanagedType.U8)] long dw64Size,
123 + [MarshalAs(UnmanagedType.LPWStr)] string wzHash,
124 + [MarshalAs(UnmanagedType.U4)] UpdateHashType hashAlgorithm,
125 [MarshalAs(UnmanagedType.LPWStr)] string wzVersion,
126 [MarshalAs(UnmanagedType.LPWStr)] string wzTitle,
127 [MarshalAs(UnmanagedType.LPWStr)] string wzSummary,
src/api/burn/WixToolset.Mba.Core/IBootstrapperEngine.cs
+2 -2
@@ -421,9 +421,9 @@ namespace WixToolset.Mba.Core
421 None,
422
423 /// <summary>
424 - /// SHA-1 based hash provided.
424 + /// SHA-512 based hash provided.
425 /// </summary>
426 - Sha1,
426 + Sha512,
427 }
428
429 /// <summary>
src/api/burn/balutil/inc/BalBaseBAFunctions.h
+2
@@ -133,6 +133,8 @@ public: // IBootstrapperApplication
133 virtual STDMETHODIMP OnDetectUpdate(
134 __in_z LPCWSTR /*wzUpdateLocation*/,
135 __in DWORD64 /*dw64Size*/,
136 + __in_z_opt LPCWSTR /*wzHash*/,
137 + __in BOOTSTRAPPER_UPDATE_HASH_TYPE /*hashAlgorithm*/,
138 __in LPCWSTR /*wzVersion*/,
139 __in_z LPCWSTR /*wzTitle*/,
140 __in_z LPCWSTR /*wzSummary*/,
src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h
+2
@@ -132,6 +132,8 @@ public: // IBootstrapperApplication
132 virtual STDMETHODIMP OnDetectUpdate(
133 __in_z LPCWSTR /*wzUpdateLocation*/,
134 __in DWORD64 /*dw64Size*/,
135 + __in_z_opt LPCWSTR /*wzHash*/,
136 + __in BOOTSTRAPPER_UPDATE_HASH_TYPE /*hashAlgorithm*/,
137 __in LPCWSTR /*wzVersion*/,
138 __in_z LPCWSTR /*wzTitle*/,
139 __in_z LPCWSTR /*wzSummary*/,
src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h
+1 -1
@@ -87,7 +87,7 @@ static HRESULT BalBaseBAProcOnDetectUpdate(
87 __inout BA_ONDETECTUPDATE_RESULTS* pResults
88 )
89 {
90 - return pBA->OnDetectUpdate(pArgs->wzUpdateLocation, pArgs->dw64Size, pArgs->wzVersion, pArgs->wzTitle, pArgs->wzSummary, pArgs->wzContentType, pArgs->wzContent, &pResults->fCancel, &pResults->fStopProcessingUpdates);
90 + return pBA->OnDetectUpdate(pArgs->wzUpdateLocation, pArgs->dw64Size, pArgs->wzHash, pArgs->hashAlgorithm, pArgs->wzVersion, pArgs->wzTitle, pArgs->wzSummary, pArgs->wzContentType, pArgs->wzContent, &pResults->fCancel, &pResults->fStopProcessingUpdates);
91 }
92
93 static HRESULT BalBaseBAProcOnDetectUpdateComplete(
src/api/burn/balutil/inc/IBootstrapperApplication.h
+2
@@ -63,6 +63,8 @@ DECLARE_INTERFACE_IID_(IBootstrapperApplication, IUnknown, "53C31D56-49C0-426B-A
63 STDMETHOD(OnDetectUpdate)(
64 __in_z_opt LPCWSTR wzUpdateLocation,
65 __in DWORD64 dw64Size,
66 + __in_z_opt LPCWSTR wzHash,
67 + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm,
68 __in_z LPCWSTR wzVersion,
69 __in_z_opt LPCWSTR wzTitle,
70 __in_z_opt LPCWSTR wzSummary,
src/burn/engine/detect.cpp
+20 -4
@@ -379,6 +379,7 @@ static HRESULT DetectAtomFeedUpdate(
379 ATOM_FEED* pAtomFeed = NULL;
380 APPLICATION_UPDATE_CHAIN* pApupChain = NULL;
381 BOOL fStopProcessingUpdates = FALSE;
382 + LPWSTR sczHash = NULL;
383
384 hr = AtomInitialize();
385 ExitOnFailure(hr, "Failed to initialize Atom.");
@@ -397,11 +398,25 @@ static HRESULT DetectAtomFeedUpdate(
398 for (DWORD i = 0; i < pApupChain->cEntries; ++i)
399 {
400 APPLICATION_UPDATE_ENTRY* pAppUpdateEntry = &pApupChain->rgEntries[i];
401 + APPLICATION_UPDATE_ENCLOSURE* pEnclosure = pAppUpdateEntry->rgEnclosures;
402
401 - hr = UserExperienceOnDetectUpdate(pUX, pAppUpdateEntry->rgEnclosures ? pAppUpdateEntry->rgEnclosures->wzUrl : NULL,
402 - pAppUpdateEntry->rgEnclosures ? pAppUpdateEntry->rgEnclosures->dw64Size : 0,
403 - pAppUpdateEntry->pVersion, pAppUpdateEntry->wzTitle,
404 - pAppUpdateEntry->wzSummary, pAppUpdateEntry->wzContentType, pAppUpdateEntry->wzContent, &fStopProcessingUpdates);
403 + if (pEnclosure)
404 + {
405 + hr = StrAllocHexEncode(pEnclosure->rgbDigest, pEnclosure->cbDigest, &sczHash);
406 + ExitOnFailure(hr, "Failed to encode hash as string.");
407 + }
408 +
409 + hr = UserExperienceOnDetectUpdate(pUX,
410 + pEnclosure ? pEnclosure->wzUrl : NULL,
411 + pEnclosure ? pEnclosure->dw64Size : 0,
412 + sczHash ? sczHash : L"",
413 + pEnclosure ? pEnclosure->digestAlgorithm == APUP_HASH_ALGORITHM_SHA512 ? BOOTSTRAPPER_UPDATE_HASH_TYPE_SHA512 : BOOTSTRAPPER_UPDATE_HASH_TYPE_NONE : BOOTSTRAPPER_UPDATE_HASH_TYPE_NONE,
414 + pAppUpdateEntry->pVersion,
415 + pAppUpdateEntry->wzTitle,
416 + pAppUpdateEntry->wzSummary,
417 + pAppUpdateEntry->wzContentType,
418 + pAppUpdateEntry->wzContent,
419 + &fStopProcessingUpdates);
420 ExitOnRootFailure(hr, "BA aborted detect update.");
421
422 if (fStopProcessingUpdates)
@@ -420,6 +435,7 @@ LExit:
435 ApupFreeChain(pApupChain);
436 AtomFreeFeed(pAtomFeed);
437 ReleaseStr(sczUpdateFeedTempFile);
438 + ReleaseStr(sczHash);
439 AtomUninitialize();
440
441 return hr;
src/burn/engine/userexperience.cpp
+5
@@ -1395,6 +1395,8 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate(
1395 __in BURN_USER_EXPERIENCE* pUserExperience,
1396 __in_z_opt LPCWSTR wzUpdateLocation,
1397 __in DWORD64 dw64Size,
1398 + __in_z_opt LPCWSTR wzHash,
1399 + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm,
1400 __in VERUTIL_VERSION* pVersion,
1401 __in_z_opt LPCWSTR wzTitle,
1402 __in_z_opt LPCWSTR wzSummary,
@@ -1410,6 +1412,8 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate(
1412 args.cbSize = sizeof(args);
1413 args.wzUpdateLocation = wzUpdateLocation;
1414 args.dw64Size = dw64Size;
1415 + args.wzHash = wzHash;
1416 + args.hashAlgorithm = hashAlgorithm;
1417 args.wzVersion = pVersion->sczVersion;
1418 args.wzTitle = wzTitle;
1419 args.wzSummary = wzSummary;
@@ -1426,6 +1430,7 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate(
1430 {
1431 hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT);
1432 }
1433 +
1434 *pfStopProcessingUpdates = results.fStopProcessingUpdates;
1435
1436 LExit:
src/burn/engine/userexperience.h
+2
@@ -332,6 +332,8 @@ BAAPI UserExperienceOnDetectUpdate(
332 __in BURN_USER_EXPERIENCE* pUserExperience,
333 __in_z_opt LPCWSTR wzUpdateLocation,
334 __in DWORD64 dw64Size,
335 + __in_z_opt LPCWSTR wzHash,
336 + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm,
337 __in VERUTIL_VERSION* pVersion,
338 __in_z_opt LPCWSTR wzTitle,
339 __in_z_opt LPCWSTR wzSummary,