From 914a92d16d7a0245f3cf0b42cc5e320c34d23d30 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Wed, 31 Aug 2022 16:07:08 -0400 Subject: Supply hashes to BA if present in update feed. Fixes https://github.com/wixtoolset/issues/issues/6353. --- .../inc/BootstrapperApplication.h | 2 ++ .../WixToolset.Mba.Core/BootstrapperApplication.cs | 4 ++-- src/api/burn/WixToolset.Mba.Core/EventArgs.cs | 15 +++++++++++++- .../IBootstrapperApplication.cs | 4 ++++ .../WixToolset.Mba.Core/IBootstrapperEngine.cs | 4 ++-- src/api/burn/balutil/inc/BalBaseBAFunctions.h | 2 ++ .../balutil/inc/BalBaseBootstrapperApplication.h | 2 ++ .../inc/BalBaseBootstrapperApplicationProc.h | 2 +- .../burn/balutil/inc/IBootstrapperApplication.h | 2 ++ src/burn/engine/detect.cpp | 24 ++++++++++++++++++---- src/burn/engine/userexperience.cpp | 5 +++++ src/burn/engine/userexperience.h | 2 ++ 12 files changed, 58 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h index ad3ef8a3..c65ca86b 100644 --- a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h +++ b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h @@ -870,6 +870,8 @@ struct BA_ONDETECTUPDATE_ARGS DWORD cbSize; LPCWSTR wzUpdateLocation; DWORD64 dw64Size; + LPCWSTR wzHash; + BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm; LPCWSTR wzVersion; LPCWSTR wzTitle; LPCWSTR wzSummary; diff --git a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs index fe9322ce..ecc99069 100644 --- a/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs @@ -1451,9 +1451,9 @@ namespace WixToolset.Mba.Core return args.HResult; } - int IBootstrapperApplication.OnDetectUpdate(string wzUpdateLocation, long dw64Size, string wzVersion, string wzTitle, string wzSummary, string wzContentType, string wzContent, ref bool fCancel, ref bool fStopProcessingUpdates) + 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) { - DetectUpdateEventArgs args = new DetectUpdateEventArgs(wzUpdateLocation, dw64Size, wzVersion, wzTitle, wzSummary, wzContentType, wzContent, fCancel, fStopProcessingUpdates); + DetectUpdateEventArgs args = new DetectUpdateEventArgs(wzUpdateLocation, dw64Size, wzHash, hashAlgorithm, wzVersion, wzTitle, wzSummary, wzContentType, wzContent, fCancel, fStopProcessingUpdates); this.OnDetectUpdate(args); fCancel = args.Cancel; diff --git a/src/api/burn/WixToolset.Mba.Core/EventArgs.cs b/src/api/burn/WixToolset.Mba.Core/EventArgs.cs index 2b414d91..48850fd7 100644 --- a/src/api/burn/WixToolset.Mba.Core/EventArgs.cs +++ b/src/api/burn/WixToolset.Mba.Core/EventArgs.cs @@ -5,6 +5,7 @@ namespace WixToolset.Mba.Core using System; using System.Collections.Generic; using System.Collections.ObjectModel; + using System.Runtime.InteropServices; /// /// Base class for BA classes. @@ -328,11 +329,13 @@ namespace WixToolset.Mba.Core public class DetectUpdateEventArgs : CancellableHResultEventArgs { /// - public DetectUpdateEventArgs(string updateLocation, long size, string version, string title, string summary, string contentType, string content, bool cancelRecommendation, bool stopRecommendation) + public DetectUpdateEventArgs(string updateLocation, long size, string hash, UpdateHashType hashAlgorithm, string version, string title, string summary, string contentType, string content, bool cancelRecommendation, bool stopRecommendation) : base(cancelRecommendation) { this.UpdateLocation = updateLocation; this.Size = size; + this.Hash = hash; + this.HashAlgorithm = hashAlgorithm; this.Version = version; this.Title = title; this.Summary = summary; @@ -351,6 +354,16 @@ namespace WixToolset.Mba.Core /// public long Size { get; private set; } + /// + /// File hash of the updated bundle. + /// + public string Hash { get; } + + /// + /// The algorithm of the updated bundle's hash. + /// + public UpdateHashType HashAlgorithm { get; } + /// /// Gets the version of the updated bundle. /// diff --git a/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs b/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs index 87da2191..daa95e17 100644 --- a/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs +++ b/src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs @@ -106,6 +106,8 @@ namespace WixToolset.Mba.Core /// /// /// + /// + /// /// /// /// @@ -118,6 +120,8 @@ namespace WixToolset.Mba.Core int OnDetectUpdate( [MarshalAs(UnmanagedType.LPWStr)] string wzUpdateLocation, [MarshalAs(UnmanagedType.U8)] long dw64Size, + [MarshalAs(UnmanagedType.LPWStr)] string wzHash, + [MarshalAs(UnmanagedType.U4)] UpdateHashType hashAlgorithm, [MarshalAs(UnmanagedType.LPWStr)] string wzVersion, [MarshalAs(UnmanagedType.LPWStr)] string wzTitle, [MarshalAs(UnmanagedType.LPWStr)] string wzSummary, diff --git a/src/api/burn/WixToolset.Mba.Core/IBootstrapperEngine.cs b/src/api/burn/WixToolset.Mba.Core/IBootstrapperEngine.cs index ebea6c4f..fdc9c3f6 100644 --- a/src/api/burn/WixToolset.Mba.Core/IBootstrapperEngine.cs +++ b/src/api/burn/WixToolset.Mba.Core/IBootstrapperEngine.cs @@ -421,9 +421,9 @@ namespace WixToolset.Mba.Core None, /// - /// SHA-1 based hash provided. + /// SHA-512 based hash provided. /// - Sha1, + Sha512, } /// diff --git a/src/api/burn/balutil/inc/BalBaseBAFunctions.h b/src/api/burn/balutil/inc/BalBaseBAFunctions.h index 3f99673d..9a8ac87e 100644 --- a/src/api/burn/balutil/inc/BalBaseBAFunctions.h +++ b/src/api/burn/balutil/inc/BalBaseBAFunctions.h @@ -133,6 +133,8 @@ public: // IBootstrapperApplication virtual STDMETHODIMP OnDetectUpdate( __in_z LPCWSTR /*wzUpdateLocation*/, __in DWORD64 /*dw64Size*/, + __in_z_opt LPCWSTR /*wzHash*/, + __in BOOTSTRAPPER_UPDATE_HASH_TYPE /*hashAlgorithm*/, __in LPCWSTR /*wzVersion*/, __in_z LPCWSTR /*wzTitle*/, __in_z LPCWSTR /*wzSummary*/, diff --git a/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h b/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h index c3223bee..58cc0673 100644 --- a/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h +++ b/src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h @@ -132,6 +132,8 @@ public: // IBootstrapperApplication virtual STDMETHODIMP OnDetectUpdate( __in_z LPCWSTR /*wzUpdateLocation*/, __in DWORD64 /*dw64Size*/, + __in_z_opt LPCWSTR /*wzHash*/, + __in BOOTSTRAPPER_UPDATE_HASH_TYPE /*hashAlgorithm*/, __in LPCWSTR /*wzVersion*/, __in_z LPCWSTR /*wzTitle*/, __in_z LPCWSTR /*wzSummary*/, diff --git a/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h b/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h index 3054731f..62cb85bc 100644 --- a/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h +++ b/src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h @@ -87,7 +87,7 @@ static HRESULT BalBaseBAProcOnDetectUpdate( __inout BA_ONDETECTUPDATE_RESULTS* pResults ) { - return pBA->OnDetectUpdate(pArgs->wzUpdateLocation, pArgs->dw64Size, pArgs->wzVersion, pArgs->wzTitle, pArgs->wzSummary, pArgs->wzContentType, pArgs->wzContent, &pResults->fCancel, &pResults->fStopProcessingUpdates); + 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); } static HRESULT BalBaseBAProcOnDetectUpdateComplete( diff --git a/src/api/burn/balutil/inc/IBootstrapperApplication.h b/src/api/burn/balutil/inc/IBootstrapperApplication.h index 0362e171..fba919ea 100644 --- a/src/api/burn/balutil/inc/IBootstrapperApplication.h +++ b/src/api/burn/balutil/inc/IBootstrapperApplication.h @@ -63,6 +63,8 @@ DECLARE_INTERFACE_IID_(IBootstrapperApplication, IUnknown, "53C31D56-49C0-426B-A STDMETHOD(OnDetectUpdate)( __in_z_opt LPCWSTR wzUpdateLocation, __in DWORD64 dw64Size, + __in_z_opt LPCWSTR wzHash, + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm, __in_z LPCWSTR wzVersion, __in_z_opt LPCWSTR wzTitle, __in_z_opt LPCWSTR wzSummary, diff --git a/src/burn/engine/detect.cpp b/src/burn/engine/detect.cpp index 7628b26a..25d184c1 100644 --- a/src/burn/engine/detect.cpp +++ b/src/burn/engine/detect.cpp @@ -379,6 +379,7 @@ static HRESULT DetectAtomFeedUpdate( ATOM_FEED* pAtomFeed = NULL; APPLICATION_UPDATE_CHAIN* pApupChain = NULL; BOOL fStopProcessingUpdates = FALSE; + LPWSTR sczHash = NULL; hr = AtomInitialize(); ExitOnFailure(hr, "Failed to initialize Atom."); @@ -397,11 +398,25 @@ static HRESULT DetectAtomFeedUpdate( for (DWORD i = 0; i < pApupChain->cEntries; ++i) { APPLICATION_UPDATE_ENTRY* pAppUpdateEntry = &pApupChain->rgEntries[i]; + APPLICATION_UPDATE_ENCLOSURE* pEnclosure = pAppUpdateEntry->rgEnclosures; - hr = UserExperienceOnDetectUpdate(pUX, pAppUpdateEntry->rgEnclosures ? pAppUpdateEntry->rgEnclosures->wzUrl : NULL, - pAppUpdateEntry->rgEnclosures ? pAppUpdateEntry->rgEnclosures->dw64Size : 0, - pAppUpdateEntry->pVersion, pAppUpdateEntry->wzTitle, - pAppUpdateEntry->wzSummary, pAppUpdateEntry->wzContentType, pAppUpdateEntry->wzContent, &fStopProcessingUpdates); + if (pEnclosure) + { + hr = StrAllocHexEncode(pEnclosure->rgbDigest, pEnclosure->cbDigest, &sczHash); + ExitOnFailure(hr, "Failed to encode hash as string."); + } + + hr = UserExperienceOnDetectUpdate(pUX, + pEnclosure ? pEnclosure->wzUrl : NULL, + pEnclosure ? pEnclosure->dw64Size : 0, + sczHash ? sczHash : L"", + pEnclosure ? pEnclosure->digestAlgorithm == APUP_HASH_ALGORITHM_SHA512 ? BOOTSTRAPPER_UPDATE_HASH_TYPE_SHA512 : BOOTSTRAPPER_UPDATE_HASH_TYPE_NONE : BOOTSTRAPPER_UPDATE_HASH_TYPE_NONE, + pAppUpdateEntry->pVersion, + pAppUpdateEntry->wzTitle, + pAppUpdateEntry->wzSummary, + pAppUpdateEntry->wzContentType, + pAppUpdateEntry->wzContent, + &fStopProcessingUpdates); ExitOnRootFailure(hr, "BA aborted detect update."); if (fStopProcessingUpdates) @@ -420,6 +435,7 @@ LExit: ApupFreeChain(pApupChain); AtomFreeFeed(pAtomFeed); ReleaseStr(sczUpdateFeedTempFile); + ReleaseStr(sczHash); AtomUninitialize(); return hr; diff --git a/src/burn/engine/userexperience.cpp b/src/burn/engine/userexperience.cpp index 6f84caba..28429394 100644 --- a/src/burn/engine/userexperience.cpp +++ b/src/burn/engine/userexperience.cpp @@ -1395,6 +1395,8 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate( __in BURN_USER_EXPERIENCE* pUserExperience, __in_z_opt LPCWSTR wzUpdateLocation, __in DWORD64 dw64Size, + __in_z_opt LPCWSTR wzHash, + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm, __in VERUTIL_VERSION* pVersion, __in_z_opt LPCWSTR wzTitle, __in_z_opt LPCWSTR wzSummary, @@ -1410,6 +1412,8 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate( args.cbSize = sizeof(args); args.wzUpdateLocation = wzUpdateLocation; args.dw64Size = dw64Size; + args.wzHash = wzHash; + args.hashAlgorithm = hashAlgorithm; args.wzVersion = pVersion->sczVersion; args.wzTitle = wzTitle; args.wzSummary = wzSummary; @@ -1426,6 +1430,7 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate( { hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); } + *pfStopProcessingUpdates = results.fStopProcessingUpdates; LExit: diff --git a/src/burn/engine/userexperience.h b/src/burn/engine/userexperience.h index 9f183208..e342da03 100644 --- a/src/burn/engine/userexperience.h +++ b/src/burn/engine/userexperience.h @@ -332,6 +332,8 @@ BAAPI UserExperienceOnDetectUpdate( __in BURN_USER_EXPERIENCE* pUserExperience, __in_z_opt LPCWSTR wzUpdateLocation, __in DWORD64 dw64Size, + __in_z_opt LPCWSTR wzHash, + __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashAlgorithm, __in VERUTIL_VERSION* pVersion, __in_z_opt LPCWSTR wzTitle, __in_z_opt LPCWSTR wzSummary, -- cgit v1.2.3-55-g6feb