diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 14:18:38 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 15:40:02 -0600 |
| commit | 3bbf1347b900ec115a12faf8f46965c9b7649696 (patch) | |
| tree | b5efc30d8990249c3bd047591c6e63549d130bdd /src | |
| parent | 931d4e4d641155ab0c90fe7717abb12db4736317 (diff) | |
| download | wix-3bbf1347b900ec115a12faf8f46965c9b7649696.tar.gz wix-3bbf1347b900ec115a12faf8f46965c9b7649696.tar.bz2 wix-3bbf1347b900ec115a12faf8f46965c9b7649696.zip | |
Add SHA512 support to apuputil.
#3992
Diffstat (limited to 'src')
| -rw-r--r-- | src/dutil/apuputil.cpp | 35 | ||||
| -rw-r--r-- | src/dutil/inc/apuputil.h | 1 | ||||
| -rw-r--r-- | src/dutil/inc/cryputil.h | 3 |
3 files changed, 29 insertions, 10 deletions
diff --git a/src/dutil/apuputil.cpp b/src/dutil/apuputil.cpp index 5bbdb8dd..bf655ecc 100644 --- a/src/dutil/apuputil.cpp +++ b/src/dutil/apuputil.cpp | |||
| @@ -2,13 +2,11 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | #define SHA256_DIGEST_LEN 32 | ||
| 6 | |||
| 7 | // prototypes | 5 | // prototypes |
| 8 | static HRESULT ProcessEntry( | 6 | static HRESULT ProcessEntry( |
| 9 | __in ATOM_ENTRY* pAtomEntry, | 7 | __in ATOM_ENTRY* pAtomEntry, |
| 10 | __in LPCWSTR wzDefaultAppId, | 8 | __in LPCWSTR wzDefaultAppId, |
| 11 | __out APPLICATION_UPDATE_ENTRY* pApupEntry | 9 | __inout APPLICATION_UPDATE_ENTRY* pApupEntry |
| 12 | ); | 10 | ); |
| 13 | static HRESULT ParseEnclosure( | 11 | static HRESULT ParseEnclosure( |
| 14 | __in ATOM_LINK* pLink, | 12 | __in ATOM_LINK* pLink, |
| @@ -192,7 +190,7 @@ extern "C" void DAPI ApupFreeChain( | |||
| 192 | static HRESULT ProcessEntry( | 190 | static HRESULT ProcessEntry( |
| 193 | __in ATOM_ENTRY* pAtomEntry, | 191 | __in ATOM_ENTRY* pAtomEntry, |
| 194 | __in LPCWSTR wzDefaultAppId, | 192 | __in LPCWSTR wzDefaultAppId, |
| 195 | __out APPLICATION_UPDATE_ENTRY* pApupEntry | 193 | __inout APPLICATION_UPDATE_ENTRY* pApupEntry |
| 196 | ) | 194 | ) |
| 197 | { | 195 | { |
| 198 | HRESULT hr = S_OK; | 196 | HRESULT hr = S_OK; |
| @@ -325,6 +323,9 @@ static HRESULT ParseEnclosure( | |||
| 325 | ) | 323 | ) |
| 326 | { | 324 | { |
| 327 | HRESULT hr = S_OK; | 325 | HRESULT hr = S_OK; |
| 326 | DWORD dwDigestLength = 0; | ||
| 327 | DWORD dwDigestStringLength = 0; | ||
| 328 | size_t cchDigestString = 0; | ||
| 328 | 329 | ||
| 329 | // First search the ATOM link's custom elements to try and find the application update enclosure information. | 330 | // First search the ATOM link's custom elements to try and find the application update enclosure information. |
| 330 | for (ATOM_UNKNOWN_ELEMENT* pElement = pLink->pUnknownElements; pElement; pElement = pElement->pNext) | 331 | for (ATOM_UNKNOWN_ELEMENT* pElement = pLink->pUnknownElements; pElement; pElement = pElement->pNext) |
| @@ -333,36 +334,50 @@ static HRESULT ParseEnclosure( | |||
| 333 | { | 334 | { |
| 334 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"digest", -1, pElement->wzElement, -1)) | 335 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"digest", -1, pElement->wzElement, -1)) |
| 335 | { | 336 | { |
| 336 | // Find the digest[@algorithm='sha256'] which is required. Everything else is ignored. | 337 | // Find the digest[@algorithm] which is required. Everything else is ignored. |
| 337 | for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext) | 338 | for (ATOM_UNKNOWN_ATTRIBUTE* pAttribute = pElement->pAttributes; pAttribute; pAttribute = pAttribute->pNext) |
| 338 | { | 339 | { |
| 340 | dwDigestLength = 0; | ||
| 339 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"algorithm", -1, pAttribute->wzAttribute, -1)) | 341 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, L"algorithm", -1, pAttribute->wzAttribute, -1)) |
| 340 | { | 342 | { |
| 341 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"md5", -1, pAttribute->wzValue, -1)) | 343 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"md5", -1, pAttribute->wzValue, -1)) |
| 342 | { | 344 | { |
| 343 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_MD5; | 345 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_MD5; |
| 346 | dwDigestLength = MD5_HASH_LEN; | ||
| 344 | } | 347 | } |
| 345 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"sha1", -1, pAttribute->wzValue, -1)) | 348 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"sha1", -1, pAttribute->wzValue, -1)) |
| 346 | { | 349 | { |
| 347 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_SHA1; | 350 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_SHA1; |
| 351 | dwDigestLength = SHA1_HASH_LEN; | ||
| 348 | } | 352 | } |
| 349 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"sha256", -1, pAttribute->wzValue, -1)) | 353 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"sha256", -1, pAttribute->wzValue, -1)) |
| 350 | { | 354 | { |
| 351 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_SHA256; | 355 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_SHA256; |
| 356 | dwDigestLength = SHA256_HASH_LEN; | ||
| 357 | } | ||
| 358 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, L"sha512", -1, pAttribute->wzValue, -1)) | ||
| 359 | { | ||
| 360 | pEnclosure->digestAlgorithm = APUP_HASH_ALGORITHM_SHA512; | ||
| 361 | dwDigestLength = SHA512_HASH_LEN; | ||
| 352 | } | 362 | } |
| 353 | break; | 363 | break; |
| 354 | } | 364 | } |
| 355 | } | 365 | } |
| 356 | 366 | ||
| 357 | if (APUP_HASH_ALGORITHM_SHA256 == pEnclosure->digestAlgorithm) | 367 | if (dwDigestLength) |
| 358 | { | 368 | { |
| 359 | if (64 != lstrlenW(pElement->wzValue)) | 369 | dwDigestStringLength = 2 * dwDigestLength; |
| 370 | |||
| 371 | hr = ::StringCchLengthW(pElement->wzValue, STRSAFE_MAX_CCH, &cchDigestString); | ||
| 372 | ExitOnFailure(hr, "Failed to get string length of digest value."); | ||
| 373 | |||
| 374 | if (dwDigestStringLength != cchDigestString) | ||
| 360 | { | 375 | { |
| 361 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 376 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); |
| 362 | ExitOnRootFailure(hr, "Invalid digest length for SHA256 algorithm."); | 377 | ExitOnRootFailure(hr, "Invalid digest length (%zu) for digest algorithm (%u).", cchDigestString, dwDigestStringLength); |
| 363 | } | 378 | } |
| 364 | 379 | ||
| 365 | pEnclosure->cbDigest = sizeof(BYTE) * SHA256_DIGEST_LEN; | 380 | pEnclosure->cbDigest = sizeof(BYTE) * dwDigestLength; |
| 366 | pEnclosure->rgbDigest = static_cast<BYTE*>(MemAlloc(pEnclosure->cbDigest, TRUE)); | 381 | pEnclosure->rgbDigest = static_cast<BYTE*>(MemAlloc(pEnclosure->cbDigest, TRUE)); |
| 367 | ExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest."); | 382 | ExitOnNull(pEnclosure->rgbDigest, hr, E_OUTOFMEMORY, "Failed to allocate memory for digest."); |
| 368 | 383 | ||
diff --git a/src/dutil/inc/apuputil.h b/src/dutil/inc/apuputil.h index 15d42f5d..f26a12b7 100644 --- a/src/dutil/inc/apuputil.h +++ b/src/dutil/inc/apuputil.h | |||
| @@ -18,6 +18,7 @@ typedef enum APUP_HASH_ALGORITHM | |||
| 18 | APUP_HASH_ALGORITHM_MD5, | 18 | APUP_HASH_ALGORITHM_MD5, |
| 19 | APUP_HASH_ALGORITHM_SHA1, | 19 | APUP_HASH_ALGORITHM_SHA1, |
| 20 | APUP_HASH_ALGORITHM_SHA256, | 20 | APUP_HASH_ALGORITHM_SHA256, |
| 21 | APUP_HASH_ALGORITHM_SHA512, | ||
| 21 | } APUP_HASH_ALGORITHM; | 22 | } APUP_HASH_ALGORITHM; |
| 22 | 23 | ||
| 23 | 24 | ||
diff --git a/src/dutil/inc/cryputil.h b/src/dutil/inc/cryputil.h index 88aa784d..02492d8a 100644 --- a/src/dutil/inc/cryputil.h +++ b/src/dutil/inc/cryputil.h | |||
| @@ -11,7 +11,10 @@ extern "C" { | |||
| 11 | 11 | ||
| 12 | // Use CRYPTPROTECTMEMORY_BLOCK_SIZE, because it's larger and thus more restrictive than RTL_ENCRYPT_MEMORY_SIZE. | 12 | // Use CRYPTPROTECTMEMORY_BLOCK_SIZE, because it's larger and thus more restrictive than RTL_ENCRYPT_MEMORY_SIZE. |
| 13 | #define CRYP_ENCRYPT_MEMORY_SIZE CRYPTPROTECTMEMORY_BLOCK_SIZE | 13 | #define CRYP_ENCRYPT_MEMORY_SIZE CRYPTPROTECTMEMORY_BLOCK_SIZE |
| 14 | #define MD5_HASH_LEN 16 | ||
| 14 | #define SHA1_HASH_LEN 20 | 15 | #define SHA1_HASH_LEN 20 |
| 16 | #define SHA256_HASH_LEN 32 | ||
| 17 | #define SHA512_HASH_LEN 64 | ||
| 15 | 18 | ||
| 16 | typedef NTSTATUS (APIENTRY *PFN_RTLENCRYPTMEMORY)( | 19 | typedef NTSTATUS (APIENTRY *PFN_RTLENCRYPTMEMORY)( |
| 17 | __inout PVOID Memory, | 20 | __inout PVOID Memory, |
