diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-11-01 15:16:07 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-11-01 18:35:01 -0600 |
| commit | 4921664f92bb6bd39ed7fd3dd24d58108973af25 (patch) | |
| tree | 491cb08915b40708770b3b76f05eb1c98dc45691 /src | |
| parent | b5553689ed1b1bd32f854654f56935c039a9b13b (diff) | |
| download | wix-4921664f92bb6bd39ed7fd3dd24d58108973af25.tar.gz wix-4921664f92bb6bd39ed7fd3dd24d58108973af25.tar.bz2 wix-4921664f92bb6bd39ed7fd3dd24d58108973af25.zip | |
Stop encrypting hidden variables.
They were persisted in plaintext, and always had to be decrypted and sent to a separate process to actually be used.
Diffstat (limited to 'src')
| -rw-r--r-- | src/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h | 4 | ||||
| -rw-r--r-- | src/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h | 4 | ||||
| -rw-r--r-- | src/engine/condition.cpp | 2 | ||||
| -rw-r--r-- | src/engine/msiengine.cpp | 1 | ||||
| -rw-r--r-- | src/engine/search.cpp | 1 | ||||
| -rw-r--r-- | src/engine/variable.cpp | 14 | ||||
| -rw-r--r-- | src/engine/variant.cpp | 314 | ||||
| -rw-r--r-- | src/engine/variant.h | 13 | ||||
| -rw-r--r-- | src/test/BurnUnitTest/VariantTest.cpp | 50 |
9 files changed, 27 insertions, 376 deletions
diff --git a/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h b/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h index 13229c29..98a9d77d 100644 --- a/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h +++ b/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h | |||
| @@ -218,7 +218,6 @@ typedef struct _BAENGINE_FORMATSTRING_ARGS | |||
| 218 | typedef struct _BAENGINE_FORMATSTRING_RESULTS | 218 | typedef struct _BAENGINE_FORMATSTRING_RESULTS |
| 219 | { | 219 | { |
| 220 | DWORD cbSize; | 220 | DWORD cbSize; |
| 221 | // The contents of wzOut may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 222 | LPWSTR wzOut; | 221 | LPWSTR wzOut; |
| 223 | // Should be initialized to the size of wzOut. | 222 | // Should be initialized to the size of wzOut. |
| 224 | DWORD cchOut; | 223 | DWORD cchOut; |
| @@ -244,7 +243,6 @@ typedef struct _BAENGINE_GETVARIABLENUMERIC_ARGS | |||
| 244 | typedef struct _BAENGINE_GETVARIABLENUMERIC_RESULTS | 243 | typedef struct _BAENGINE_GETVARIABLENUMERIC_RESULTS |
| 245 | { | 244 | { |
| 246 | DWORD cbSize; | 245 | DWORD cbSize; |
| 247 | // The contents of llValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. | ||
| 248 | LONGLONG llValue; | 246 | LONGLONG llValue; |
| 249 | } BAENGINE_GETVARIABLENUMERIC_RESULTS; | 247 | } BAENGINE_GETVARIABLENUMERIC_RESULTS; |
| 250 | 248 | ||
| @@ -257,7 +255,6 @@ typedef struct _BAENGINE_GETVARIABLESTRING_ARGS | |||
| 257 | typedef struct _BAENGINE_GETVARIABLESTRING_RESULTS | 255 | typedef struct _BAENGINE_GETVARIABLESTRING_RESULTS |
| 258 | { | 256 | { |
| 259 | DWORD cbSize; | 257 | DWORD cbSize; |
| 260 | // The contents of wzValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroFree. | ||
| 261 | LPWSTR wzValue; | 258 | LPWSTR wzValue; |
| 262 | // Should be initialized to the size of wzValue. | 259 | // Should be initialized to the size of wzValue. |
| 263 | DWORD cchValue; | 260 | DWORD cchValue; |
| @@ -272,7 +269,6 @@ typedef struct _BAENGINE_GETVARIABLEVERSION_ARGS | |||
| 272 | typedef struct _BAENGINE_GETVARIABLEVERSION_RESULTS | 269 | typedef struct _BAENGINE_GETVARIABLEVERSION_RESULTS |
| 273 | { | 270 | { |
| 274 | DWORD cbSize; | 271 | DWORD cbSize; |
| 275 | // The contents of wzValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroFree. | ||
| 276 | LPWSTR wzValue; | 272 | LPWSTR wzValue; |
| 277 | // Should be initialized to the size of wzValue. | 273 | // Should be initialized to the size of wzValue. |
| 278 | DWORD cchValue; | 274 | DWORD cchValue; |
diff --git a/src/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h b/src/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h index becb5be3..003ff635 100644 --- a/src/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h +++ b/src/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h | |||
| @@ -78,7 +78,6 @@ typedef struct _BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS | |||
| 78 | typedef struct _BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS | 78 | typedef struct _BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS |
| 79 | { | 79 | { |
| 80 | DWORD cbSize; | 80 | DWORD cbSize; |
| 81 | // The contents of wzOut may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 82 | LPWSTR wzOut; | 81 | LPWSTR wzOut; |
| 83 | // Should be initialized to the size of wzOut. | 82 | // Should be initialized to the size of wzOut. |
| 84 | DWORD cchOut; | 83 | DWORD cchOut; |
| @@ -93,7 +92,6 @@ typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS | |||
| 93 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS | 92 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS |
| 94 | { | 93 | { |
| 95 | DWORD cbSize; | 94 | DWORD cbSize; |
| 96 | // The contents of llValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. | ||
| 97 | LONGLONG llValue; | 95 | LONGLONG llValue; |
| 98 | } BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS; | 96 | } BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS; |
| 99 | 97 | ||
| @@ -106,7 +104,6 @@ typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS | |||
| 106 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS | 104 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS |
| 107 | { | 105 | { |
| 108 | DWORD cbSize; | 106 | DWORD cbSize; |
| 109 | // The contents of wzValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroFree. | ||
| 110 | LPWSTR wzValue; | 107 | LPWSTR wzValue; |
| 111 | // Should be initialized to the size of wzValue. | 108 | // Should be initialized to the size of wzValue. |
| 112 | DWORD cchValue; | 109 | DWORD cchValue; |
| @@ -121,7 +118,6 @@ typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS | |||
| 121 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS | 118 | typedef struct _BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS |
| 122 | { | 119 | { |
| 123 | DWORD cbSize; | 120 | DWORD cbSize; |
| 124 | // The contents of wzValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroFree. | ||
| 125 | LPWSTR wzValue; | 121 | LPWSTR wzValue; |
| 126 | // Should be initialized to the size of wzValue. | 122 | // Should be initialized to the size of wzValue. |
| 127 | DWORD cchValue; | 123 | DWORD cchValue; |
diff --git a/src/engine/condition.cpp b/src/engine/condition.cpp index d6038b34..06591567 100644 --- a/src/engine/condition.cpp +++ b/src/engine/condition.cpp | |||
| @@ -434,7 +434,6 @@ static HRESULT ParseOperand( | |||
| 434 | HRESULT hr = S_OK; | 434 | HRESULT hr = S_OK; |
| 435 | LPWSTR sczFormatted = NULL; | 435 | LPWSTR sczFormatted = NULL; |
| 436 | 436 | ||
| 437 | // Symbols don't encrypt their value, so can access the value directly. | ||
| 438 | switch (pContext->NextSymbol.Type) | 437 | switch (pContext->NextSymbol.Type) |
| 439 | { | 438 | { |
| 440 | case BURN_SYMBOL_TYPE_IDENTIFIER: | 439 | case BURN_SYMBOL_TYPE_IDENTIFIER: |
| @@ -715,7 +714,6 @@ static HRESULT NextSymbol( | |||
| 715 | pContext->wzRead[n] == L'-' || | 714 | pContext->wzRead[n] == L'-' || |
| 716 | pContext->wzRead[n] == L'.'); | 715 | pContext->wzRead[n] == L'.'); |
| 717 | 716 | ||
| 718 | // Symbols don't encrypt their value, so can access the value directly. | ||
| 719 | hr = VerParseVersion(&pContext->wzRead[1], n - 1, FALSE, &pContext->NextSymbol.Value.pValue); | 717 | hr = VerParseVersion(&pContext->wzRead[1], n - 1, FALSE, &pContext->NextSymbol.Value.pValue); |
| 720 | if (FAILED(hr)) | 718 | if (FAILED(hr)) |
| 721 | { | 719 | { |
diff --git a/src/engine/msiengine.cpp b/src/engine/msiengine.cpp index 47211309..066734d0 100644 --- a/src/engine/msiengine.cpp +++ b/src/engine/msiengine.cpp | |||
| @@ -1402,7 +1402,6 @@ LExit: | |||
| 1402 | return hr; | 1402 | return hr; |
| 1403 | } | 1403 | } |
| 1404 | 1404 | ||
| 1405 | // The contents of psczProperties may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 1406 | extern "C" HRESULT MsiEngineConcatProperties( | 1405 | extern "C" HRESULT MsiEngineConcatProperties( |
| 1407 | __in_ecount(cProperties) BURN_MSIPROPERTY* rgProperties, | 1406 | __in_ecount(cProperties) BURN_MSIPROPERTY* rgProperties, |
| 1408 | __in DWORD cProperties, | 1407 | __in DWORD cProperties, |
diff --git a/src/engine/search.cpp b/src/engine/search.cpp index 1dbcf56b..065003c7 100644 --- a/src/engine/search.cpp +++ b/src/engine/search.cpp | |||
| @@ -1136,7 +1136,6 @@ static HRESULT MsiProductSearch( | |||
| 1136 | DWORD dwRelatedProducts = 0; | 1136 | DWORD dwRelatedProducts = 0; |
| 1137 | BURN_VARIANT_TYPE type = BURN_VARIANT_TYPE_NONE; | 1137 | BURN_VARIANT_TYPE type = BURN_VARIANT_TYPE_NONE; |
| 1138 | BURN_VARIANT value = { }; | 1138 | BURN_VARIANT value = { }; |
| 1139 | // We're not going to encrypt this value, so can access the value directly. | ||
| 1140 | 1139 | ||
| 1141 | switch (pSearch->MsiProductSearch.Type) | 1140 | switch (pSearch->MsiProductSearch.Type) |
| 1142 | { | 1141 | { |
diff --git a/src/engine/variable.cpp b/src/engine/variable.cpp index 8b6b318b..4bf73a9b 100644 --- a/src/engine/variable.cpp +++ b/src/engine/variable.cpp | |||
| @@ -427,9 +427,6 @@ extern "C" HRESULT VariablesParseFromXml( | |||
| 427 | hr = BVariantSetValue(&pVariables->rgVariables[iVariable].Value, &value); | 427 | hr = BVariantSetValue(&pVariables->rgVariables[iVariable].Value, &value); |
| 428 | ExitOnFailure(hr, "Failed to set value of variable: %ls", sczId); | 428 | ExitOnFailure(hr, "Failed to set value of variable: %ls", sczId); |
| 429 | 429 | ||
| 430 | hr = BVariantSetEncryption(&pVariables->rgVariables[iVariable].Value, fHidden); | ||
| 431 | ExitOnFailure(hr, "Failed to set variant encryption"); | ||
| 432 | |||
| 433 | // prepare next iteration | 430 | // prepare next iteration |
| 434 | ReleaseNullObject(pixnNode); | 431 | ReleaseNullObject(pixnNode); |
| 435 | BVariantUninitialize(&value); | 432 | BVariantUninitialize(&value); |
| @@ -509,7 +506,6 @@ extern "C" void VariablesDump( | |||
| 509 | StrSecureZeroFreeString(sczValue); | 506 | StrSecureZeroFreeString(sczValue); |
| 510 | } | 507 | } |
| 511 | 508 | ||
| 512 | // The contents of pllValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. | ||
| 513 | extern "C" HRESULT VariableGetNumeric( | 509 | extern "C" HRESULT VariableGetNumeric( |
| 514 | __in BURN_VARIABLES* pVariables, | 510 | __in BURN_VARIABLES* pVariables, |
| 515 | __in_z LPCWSTR wzVariable, | 511 | __in_z LPCWSTR wzVariable, |
| @@ -541,7 +537,6 @@ LExit: | |||
| 541 | return hr; | 537 | return hr; |
| 542 | } | 538 | } |
| 543 | 539 | ||
| 544 | // The contents of psczValue may be sensitive, if variable is hidden should keep encrypted and SecureZeroFree. | ||
| 545 | extern "C" HRESULT VariableGetString( | 540 | extern "C" HRESULT VariableGetString( |
| 546 | __in BURN_VARIABLES* pVariables, | 541 | __in BURN_VARIABLES* pVariables, |
| 547 | __in_z LPCWSTR wzVariable, | 542 | __in_z LPCWSTR wzVariable, |
| @@ -573,7 +568,6 @@ LExit: | |||
| 573 | return hr; | 568 | return hr; |
| 574 | } | 569 | } |
| 575 | 570 | ||
| 576 | // The contents of ppValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. | ||
| 577 | extern "C" HRESULT VariableGetVersion( | 571 | extern "C" HRESULT VariableGetVersion( |
| 578 | __in BURN_VARIABLES* pVariables, | 572 | __in BURN_VARIABLES* pVariables, |
| 579 | __in_z LPCWSTR wzVariable, | 573 | __in_z LPCWSTR wzVariable, |
| @@ -632,7 +626,6 @@ LExit: | |||
| 632 | return hr; | 626 | return hr; |
| 633 | } | 627 | } |
| 634 | 628 | ||
| 635 | // The contents of psczValue may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 636 | extern "C" HRESULT VariableGetFormatted( | 629 | extern "C" HRESULT VariableGetFormatted( |
| 637 | __in BURN_VARIABLES* pVariables, | 630 | __in BURN_VARIABLES* pVariables, |
| 638 | __in_z LPCWSTR wzVariable, | 631 | __in_z LPCWSTR wzVariable, |
| @@ -661,7 +654,6 @@ extern "C" HRESULT VariableSetNumeric( | |||
| 661 | { | 654 | { |
| 662 | BURN_VARIANT variant = { }; | 655 | BURN_VARIANT variant = { }; |
| 663 | 656 | ||
| 664 | // We're not going to encrypt this value, so can access the value directly. | ||
| 665 | variant.llValue = llValue; | 657 | variant.llValue = llValue; |
| 666 | variant.Type = BURN_VARIANT_TYPE_NUMERIC; | 658 | variant.Type = BURN_VARIANT_TYPE_NUMERIC; |
| 667 | 659 | ||
| @@ -678,7 +670,6 @@ extern "C" HRESULT VariableSetString( | |||
| 678 | { | 670 | { |
| 679 | BURN_VARIANT variant = { }; | 671 | BURN_VARIANT variant = { }; |
| 680 | 672 | ||
| 681 | // We're not going to encrypt this value, so can access the value directly. | ||
| 682 | variant.sczValue = (LPWSTR)wzValue; | 673 | variant.sczValue = (LPWSTR)wzValue; |
| 683 | variant.Type = fFormatted ? BURN_VARIANT_TYPE_FORMATTED : BURN_VARIANT_TYPE_STRING; | 674 | variant.Type = fFormatted ? BURN_VARIANT_TYPE_FORMATTED : BURN_VARIANT_TYPE_STRING; |
| 684 | 675 | ||
| @@ -694,7 +685,6 @@ extern "C" HRESULT VariableSetVersion( | |||
| 694 | { | 685 | { |
| 695 | BURN_VARIANT variant = { }; | 686 | BURN_VARIANT variant = { }; |
| 696 | 687 | ||
| 697 | // We're not going to encrypt this value, so can access the value directly. | ||
| 698 | variant.pValue = pValue; | 688 | variant.pValue = pValue; |
| 699 | variant.Type = BURN_VARIANT_TYPE_VERSION; | 689 | variant.Type = BURN_VARIANT_TYPE_VERSION; |
| 700 | 690 | ||
| @@ -710,7 +700,6 @@ extern "C" HRESULT VariableSetVariant( | |||
| 710 | return SetVariableValue(pVariables, wzVariable, pVariant, SET_VARIABLE_NOT_BUILTIN, TRUE); | 700 | return SetVariableValue(pVariables, wzVariable, pVariant, SET_VARIABLE_NOT_BUILTIN, TRUE); |
| 711 | } | 701 | } |
| 712 | 702 | ||
| 713 | // The contents of psczOut may be sensitive, should keep encrypted and SecureZeroFree | ||
| 714 | extern "C" HRESULT VariableFormatString( | 703 | extern "C" HRESULT VariableFormatString( |
| 715 | __in BURN_VARIABLES* pVariables, | 704 | __in BURN_VARIABLES* pVariables, |
| 716 | __in_z LPCWSTR wzIn, | 705 | __in_z LPCWSTR wzIn, |
| @@ -1092,7 +1081,6 @@ LExit: | |||
| 1092 | 1081 | ||
| 1093 | // internal function definitions | 1082 | // internal function definitions |
| 1094 | 1083 | ||
| 1095 | // The contents of psczOut may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 1096 | static HRESULT FormatString( | 1084 | static HRESULT FormatString( |
| 1097 | __in BURN_VARIABLES* pVariables, | 1085 | __in BURN_VARIABLES* pVariables, |
| 1098 | __in_z LPCWSTR wzIn, | 1086 | __in_z LPCWSTR wzIn, |
| @@ -1312,7 +1300,6 @@ LExit: | |||
| 1312 | return hr; | 1300 | return hr; |
| 1313 | } | 1301 | } |
| 1314 | 1302 | ||
| 1315 | // The contents of psczOut may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 1316 | static HRESULT GetFormatted( | 1303 | static HRESULT GetFormatted( |
| 1317 | __in BURN_VARIABLES* pVariables, | 1304 | __in BURN_VARIABLES* pVariables, |
| 1318 | __in_z LPCWSTR wzVariable, | 1305 | __in_z LPCWSTR wzVariable, |
| @@ -1581,7 +1568,6 @@ static HRESULT SetVariableValue( | |||
| 1581 | } | 1568 | } |
| 1582 | else | 1569 | else |
| 1583 | { | 1570 | { |
| 1584 | // Assume value isn't encrypted since it's not hidden. | ||
| 1585 | switch (pVariant->Type) | 1571 | switch (pVariant->Type) |
| 1586 | { | 1572 | { |
| 1587 | case BURN_VARIANT_TYPE_NONE: | 1573 | case BURN_VARIANT_TYPE_NONE: |
diff --git a/src/engine/variant.cpp b/src/engine/variant.cpp index 82f465b2..2267ee7b 100644 --- a/src/engine/variant.cpp +++ b/src/engine/variant.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | #define VARIANT_ENCRYPTION_SCOPE CRYPTPROTECTMEMORY_SAME_PROCESS | ||
| 6 | |||
| 7 | // internal function declarations | 5 | // internal function declarations |
| 8 | 6 | ||
| 9 | static HRESULT GetVersionInternal( | 7 | static HRESULT GetVersionInternal( |
| @@ -12,25 +10,6 @@ static HRESULT GetVersionInternal( | |||
| 12 | __in BOOL fSilent, | 10 | __in BOOL fSilent, |
| 13 | __out VERUTIL_VERSION** ppValue | 11 | __out VERUTIL_VERSION** ppValue |
| 14 | ); | 12 | ); |
| 15 | static HRESULT BVariantEncryptString( | ||
| 16 | __in BURN_VARIANT* pVariant, | ||
| 17 | __in BOOL fEncrypt | ||
| 18 | ); | ||
| 19 | |||
| 20 | static void BVariantRetrieveNumeric( | ||
| 21 | __in BURN_VARIANT* pVariant, | ||
| 22 | __out LONGLONG* pllValue | ||
| 23 | ); | ||
| 24 | |||
| 25 | static HRESULT BVariantRetrieveDecryptedString( | ||
| 26 | __in BURN_VARIANT* pVariant, | ||
| 27 | __out LPWSTR* psczValue | ||
| 28 | ); | ||
| 29 | |||
| 30 | static void BVariantRetrieveVersion( | ||
| 31 | __in BURN_VARIANT* pVariant, | ||
| 32 | __out VERUTIL_VERSION** ppValue | ||
| 33 | ); | ||
| 34 | 13 | ||
| 35 | // function definitions | 14 | // function definitions |
| 36 | 15 | ||
| @@ -46,38 +25,28 @@ extern "C" void BVariantUninitialize( | |||
| 46 | SecureZeroMemory(pVariant, sizeof(BURN_VARIANT)); | 25 | SecureZeroMemory(pVariant, sizeof(BURN_VARIANT)); |
| 47 | } | 26 | } |
| 48 | 27 | ||
| 49 | // The contents of pllValue may be sensitive, should keep encrypted and SecureZeroMemory. | ||
| 50 | extern "C" HRESULT BVariantGetNumeric( | 28 | extern "C" HRESULT BVariantGetNumeric( |
| 51 | __in BURN_VARIANT* pVariant, | 29 | __in BURN_VARIANT* pVariant, |
| 52 | __out LONGLONG* pllValue | 30 | __out LONGLONG* pllValue |
| 53 | ) | 31 | ) |
| 54 | { | 32 | { |
| 55 | HRESULT hr = S_OK; | 33 | HRESULT hr = S_OK; |
| 56 | LPWSTR sczValue = NULL; | ||
| 57 | VERUTIL_VERSION* pVersionValue = NULL; | ||
| 58 | 34 | ||
| 59 | switch (pVariant->Type) | 35 | switch (pVariant->Type) |
| 60 | { | 36 | { |
| 61 | case BURN_VARIANT_TYPE_NUMERIC: | 37 | case BURN_VARIANT_TYPE_NUMERIC: |
| 62 | BVariantRetrieveNumeric(pVariant, pllValue); | 38 | *pllValue = pVariant->llValue; |
| 63 | break; | 39 | break; |
| 64 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | 40 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; |
| 65 | case BURN_VARIANT_TYPE_STRING: | 41 | case BURN_VARIANT_TYPE_STRING: |
| 66 | hr = BVariantRetrieveDecryptedString(pVariant, &sczValue); | 42 | hr = StrStringToInt64(pVariant->sczValue, 0, pllValue); |
| 67 | if (SUCCEEDED(hr)) | 43 | if (FAILED(hr)) |
| 68 | { | 44 | { |
| 69 | hr = StrStringToInt64(sczValue, 0, pllValue); | 45 | hr = DISP_E_TYPEMISMATCH; |
| 70 | if (FAILED(hr)) | ||
| 71 | { | ||
| 72 | hr = DISP_E_TYPEMISMATCH; | ||
| 73 | } | ||
| 74 | } | 46 | } |
| 75 | StrSecureZeroFreeString(sczValue); | ||
| 76 | break; | 47 | break; |
| 77 | case BURN_VARIANT_TYPE_VERSION: | 48 | case BURN_VARIANT_TYPE_VERSION: |
| 78 | BVariantRetrieveVersion(pVariant, &pVersionValue); | 49 | hr = StrStringToInt64(pVariant->pValue ? pVariant->pValue->sczVersion : NULL, 0, pllValue); |
| 79 | |||
| 80 | hr = StrStringToInt64(pVersionValue->sczVersion, 0, pllValue); | ||
| 81 | if (FAILED(hr)) | 50 | if (FAILED(hr)) |
| 82 | { | 51 | { |
| 83 | hr = DISP_E_TYPEMISMATCH; | 52 | hr = DISP_E_TYPEMISMATCH; |
| @@ -91,35 +60,27 @@ extern "C" HRESULT BVariantGetNumeric( | |||
| 91 | return hr; | 60 | return hr; |
| 92 | } | 61 | } |
| 93 | 62 | ||
| 94 | // The contents of psczValue may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 95 | extern "C" HRESULT BVariantGetString( | 63 | extern "C" HRESULT BVariantGetString( |
| 96 | __in BURN_VARIANT* pVariant, | 64 | __in BURN_VARIANT* pVariant, |
| 97 | __out_z LPWSTR* psczValue | 65 | __out_z LPWSTR* psczValue |
| 98 | ) | 66 | ) |
| 99 | { | 67 | { |
| 100 | HRESULT hr = S_OK; | 68 | HRESULT hr = S_OK; |
| 101 | LONGLONG llValue = 0; | ||
| 102 | VERUTIL_VERSION* pVersionValue = NULL; | ||
| 103 | 69 | ||
| 104 | switch (pVariant->Type) | 70 | switch (pVariant->Type) |
| 105 | { | 71 | { |
| 106 | case BURN_VARIANT_TYPE_NUMERIC: | 72 | case BURN_VARIANT_TYPE_NUMERIC: |
| 107 | BVariantRetrieveNumeric(pVariant, &llValue); | 73 | hr = StrAllocFormattedSecure(psczValue, L"%I64d", pVariant->llValue); |
| 108 | if (SUCCEEDED(hr)) | 74 | ExitOnFailure(hr, "Failed to convert int64 to string."); |
| 109 | { | ||
| 110 | hr = StrAllocFormattedSecure(psczValue, L"%I64d", llValue); | ||
| 111 | ExitOnFailure(hr, "Failed to convert int64 to string."); | ||
| 112 | } | ||
| 113 | SecureZeroMemory(&llValue, sizeof(llValue)); | ||
| 114 | break; | 75 | break; |
| 115 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | 76 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; |
| 116 | case BURN_VARIANT_TYPE_STRING: | 77 | case BURN_VARIANT_TYPE_STRING: |
| 117 | hr = BVariantRetrieveDecryptedString(pVariant, psczValue); | 78 | hr = StrAllocStringSecure(psczValue, pVariant->sczValue, 0); |
| 79 | ExitOnFailure(hr, "Failed to copy string value."); | ||
| 118 | break; | 80 | break; |
| 119 | case BURN_VARIANT_TYPE_VERSION: | 81 | case BURN_VARIANT_TYPE_VERSION: |
| 120 | BVariantRetrieveVersion(pVariant, &pVersionValue); | 82 | hr = StrAllocStringSecure(psczValue, pVariant->pValue ? pVariant->pValue->sczVersion : NULL, 0); |
| 121 | 83 | ExitOnFailure(hr, "Failed to copy version value."); | |
| 122 | hr = StrAllocStringSecure(psczValue, pVersionValue->sczVersion, 0); | ||
| 123 | break; | 84 | break; |
| 124 | default: | 85 | default: |
| 125 | hr = E_INVALIDARG; | 86 | hr = E_INVALIDARG; |
| @@ -130,7 +91,6 @@ LExit: | |||
| 130 | return hr; | 91 | return hr; |
| 131 | } | 92 | } |
| 132 | 93 | ||
| 133 | // The contents of ppValue may be sensitive, should keep encrypted and SecureZeroMemory. | ||
| 134 | extern "C" HRESULT BVariantGetVersion( | 94 | extern "C" HRESULT BVariantGetVersion( |
| 135 | __in BURN_VARIANT* pVariant, | 95 | __in BURN_VARIANT* pVariant, |
| 136 | __out VERUTIL_VERSION** ppValue | 96 | __out VERUTIL_VERSION** ppValue |
| @@ -139,7 +99,6 @@ extern "C" HRESULT BVariantGetVersion( | |||
| 139 | return GetVersionInternal(pVariant, FALSE, FALSE, ppValue); | 99 | return GetVersionInternal(pVariant, FALSE, FALSE, ppValue); |
| 140 | } | 100 | } |
| 141 | 101 | ||
| 142 | // The contents of ppValue may be sensitive, should keep encrypted and SecureZeroMemory. | ||
| 143 | extern "C" HRESULT BVariantGetVersionHidden( | 102 | extern "C" HRESULT BVariantGetVersionHidden( |
| 144 | __in BURN_VARIANT* pVariant, | 103 | __in BURN_VARIANT* pVariant, |
| 145 | __in BOOL fHidden, | 104 | __in BOOL fHidden, |
| @@ -149,7 +108,6 @@ extern "C" HRESULT BVariantGetVersionHidden( | |||
| 149 | return GetVersionInternal(pVariant, fHidden, FALSE, ppValue); | 108 | return GetVersionInternal(pVariant, fHidden, FALSE, ppValue); |
| 150 | } | 109 | } |
| 151 | 110 | ||
| 152 | // The contents of ppValue may be sensitive, should keep encrypted and SecureZeroMemory. | ||
| 153 | extern "C" HRESULT BVariantGetVersionSilent( | 111 | extern "C" HRESULT BVariantGetVersionSilent( |
| 154 | __in BURN_VARIANT* pVariant, | 112 | __in BURN_VARIANT* pVariant, |
| 155 | __in BOOL fSilent, | 113 | __in BOOL fSilent, |
| @@ -167,44 +125,28 @@ static HRESULT GetVersionInternal( | |||
| 167 | ) | 125 | ) |
| 168 | { | 126 | { |
| 169 | HRESULT hr = S_OK; | 127 | HRESULT hr = S_OK; |
| 170 | LONGLONG llValue = 0; | ||
| 171 | LPWSTR sczValue = NULL; | ||
| 172 | VERUTIL_VERSION* pValue = NULL; | ||
| 173 | 128 | ||
| 174 | switch (pVariant->Type) | 129 | switch (pVariant->Type) |
| 175 | { | 130 | { |
| 176 | case BURN_VARIANT_TYPE_NUMERIC: | 131 | case BURN_VARIANT_TYPE_NUMERIC: |
| 177 | BVariantRetrieveNumeric(pVariant, &llValue); | 132 | hr = VerVersionFromQword(pVariant->llValue, ppValue); |
| 178 | |||
| 179 | hr = VerVersionFromQword(llValue, ppValue); | ||
| 180 | break; | 133 | break; |
| 181 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | 134 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; |
| 182 | case BURN_VARIANT_TYPE_STRING: | 135 | case BURN_VARIANT_TYPE_STRING: |
| 183 | hr = BVariantRetrieveDecryptedString(pVariant, &sczValue); | 136 | hr = VerParseVersion(pVariant->sczValue, 0, FALSE, ppValue); |
| 184 | if (SUCCEEDED(hr)) | 137 | if (SUCCEEDED(hr) && !fSilent && (*ppValue)->fInvalid) |
| 185 | { | 138 | { |
| 186 | hr = VerParseVersion(sczValue, 0, FALSE, ppValue); | 139 | LogId(REPORT_WARNING, MSG_INVALID_VERSION_COERSION, fHidden ? L"*****" : pVariant->sczValue); |
| 187 | if (FAILED(hr)) | ||
| 188 | { | ||
| 189 | hr = DISP_E_TYPEMISMATCH; | ||
| 190 | } | ||
| 191 | else if (!fSilent && (*ppValue)->fInvalid) | ||
| 192 | { | ||
| 193 | LogId(REPORT_WARNING, MSG_INVALID_VERSION_COERSION, fHidden ? L"*****" : sczValue); | ||
| 194 | } | ||
| 195 | } | 140 | } |
| 196 | StrSecureZeroFreeString(sczValue); | ||
| 197 | break; | 141 | break; |
| 198 | case BURN_VARIANT_TYPE_VERSION: | 142 | case BURN_VARIANT_TYPE_VERSION: |
| 199 | BVariantRetrieveVersion(pVariant, &pValue); | 143 | if (!pVariant->pValue) |
| 200 | |||
| 201 | if (!pValue) | ||
| 202 | { | 144 | { |
| 203 | *ppValue = NULL; | 145 | *ppValue = NULL; |
| 204 | } | 146 | } |
| 205 | else | 147 | else |
| 206 | { | 148 | { |
| 207 | hr = VerCopyVersion(pValue, ppValue); | 149 | hr = VerCopyVersion(pVariant->pValue, ppValue); |
| 208 | } | 150 | } |
| 209 | break; | 151 | break; |
| 210 | default: | 152 | default: |
| @@ -221,7 +163,6 @@ extern "C" HRESULT BVariantSetNumeric( | |||
| 221 | ) | 163 | ) |
| 222 | { | 164 | { |
| 223 | HRESULT hr = S_OK; | 165 | HRESULT hr = S_OK; |
| 224 | BOOL fEncrypt = pVariant->fEncryptString; | ||
| 225 | 166 | ||
| 226 | if (BURN_VARIANT_TYPE_FORMATTED == pVariant->Type || | 167 | if (BURN_VARIANT_TYPE_FORMATTED == pVariant->Type || |
| 227 | BURN_VARIANT_TYPE_STRING == pVariant->Type) | 168 | BURN_VARIANT_TYPE_STRING == pVariant->Type) |
| @@ -231,7 +172,6 @@ extern "C" HRESULT BVariantSetNumeric( | |||
| 231 | memset(pVariant, 0, sizeof(BURN_VARIANT)); | 172 | memset(pVariant, 0, sizeof(BURN_VARIANT)); |
| 232 | pVariant->llValue = llValue; | 173 | pVariant->llValue = llValue; |
| 233 | pVariant->Type = BURN_VARIANT_TYPE_NUMERIC; | 174 | pVariant->Type = BURN_VARIANT_TYPE_NUMERIC; |
| 234 | BVariantSetEncryption(pVariant, fEncrypt); | ||
| 235 | 175 | ||
| 236 | return hr; | 176 | return hr; |
| 237 | } | 177 | } |
| @@ -244,7 +184,6 @@ extern "C" HRESULT BVariantSetString( | |||
| 244 | ) | 184 | ) |
| 245 | { | 185 | { |
| 246 | HRESULT hr = S_OK; | 186 | HRESULT hr = S_OK; |
| 247 | BOOL fEncrypt = pVariant->fEncryptString; | ||
| 248 | 187 | ||
| 249 | if (!wzValue) // if we're nulling out the string, make the variable NONE. | 188 | if (!wzValue) // if we're nulling out the string, make the variable NONE. |
| 250 | { | 189 | { |
| @@ -257,11 +196,6 @@ extern "C" HRESULT BVariantSetString( | |||
| 257 | { | 196 | { |
| 258 | memset(pVariant, 0, sizeof(BURN_VARIANT)); | 197 | memset(pVariant, 0, sizeof(BURN_VARIANT)); |
| 259 | } | 198 | } |
| 260 | else | ||
| 261 | { | ||
| 262 | // We're about to copy an unencrypted value. | ||
| 263 | pVariant->fEncryptString = FALSE; | ||
| 264 | } | ||
| 265 | 199 | ||
| 266 | hr = StrAllocStringSecure(&pVariant->sczValue, wzValue, cchValue); | 200 | hr = StrAllocStringSecure(&pVariant->sczValue, wzValue, cchValue); |
| 267 | ExitOnFailure(hr, "Failed to copy string."); | 201 | ExitOnFailure(hr, "Failed to copy string."); |
| @@ -270,7 +204,6 @@ extern "C" HRESULT BVariantSetString( | |||
| 270 | } | 204 | } |
| 271 | 205 | ||
| 272 | LExit: | 206 | LExit: |
| 273 | BVariantSetEncryption(pVariant, fEncrypt); | ||
| 274 | return hr; | 207 | return hr; |
| 275 | } | 208 | } |
| 276 | 209 | ||
| @@ -280,7 +213,6 @@ extern "C" HRESULT BVariantSetVersion( | |||
| 280 | ) | 213 | ) |
| 281 | { | 214 | { |
| 282 | HRESULT hr = S_OK; | 215 | HRESULT hr = S_OK; |
| 283 | BOOL fEncryptValue = pVariant->fEncryptString; | ||
| 284 | 216 | ||
| 285 | if (!pValue) // if we're nulling out the version, make the variable NONE. | 217 | if (!pValue) // if we're nulling out the version, make the variable NONE. |
| 286 | { | 218 | { |
| @@ -298,8 +230,6 @@ extern "C" HRESULT BVariantSetVersion( | |||
| 298 | pVariant->Type = BURN_VARIANT_TYPE_VERSION; | 230 | pVariant->Type = BURN_VARIANT_TYPE_VERSION; |
| 299 | } | 231 | } |
| 300 | 232 | ||
| 301 | BVariantSetEncryption(pVariant, fEncryptValue); | ||
| 302 | |||
| 303 | return hr; | 233 | return hr; |
| 304 | } | 234 | } |
| 305 | 235 | ||
| @@ -309,10 +239,6 @@ extern "C" HRESULT BVariantSetValue( | |||
| 309 | ) | 239 | ) |
| 310 | { | 240 | { |
| 311 | HRESULT hr = S_OK; | 241 | HRESULT hr = S_OK; |
| 312 | LONGLONG llValue = 0; | ||
| 313 | LPWSTR sczValue = NULL; | ||
| 314 | VERUTIL_VERSION* pVersionValue = NULL; | ||
| 315 | BOOL fEncrypt = pVariant->fEncryptString; | ||
| 316 | 242 | ||
| 317 | switch (pValue->Type) | 243 | switch (pValue->Type) |
| 318 | { | 244 | { |
| @@ -320,35 +246,19 @@ extern "C" HRESULT BVariantSetValue( | |||
| 320 | BVariantUninitialize(pVariant); | 246 | BVariantUninitialize(pVariant); |
| 321 | break; | 247 | break; |
| 322 | case BURN_VARIANT_TYPE_NUMERIC: | 248 | case BURN_VARIANT_TYPE_NUMERIC: |
| 323 | hr = BVariantGetNumeric(pValue, &llValue); | 249 | hr = BVariantSetNumeric(pVariant, pValue->llValue); |
| 324 | if (SUCCEEDED(hr)) | ||
| 325 | { | ||
| 326 | hr = BVariantSetNumeric(pVariant, llValue); | ||
| 327 | } | ||
| 328 | SecureZeroMemory(&llValue, sizeof(llValue)); | ||
| 329 | break; | 250 | break; |
| 330 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | 251 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; |
| 331 | case BURN_VARIANT_TYPE_STRING: | 252 | case BURN_VARIANT_TYPE_STRING: |
| 332 | hr = BVariantGetString(pValue, &sczValue); | 253 | hr = BVariantSetString(pVariant, pValue->sczValue, 0, BURN_VARIANT_TYPE_FORMATTED == pValue->Type); |
| 333 | if (SUCCEEDED(hr)) | ||
| 334 | { | ||
| 335 | hr = BVariantSetString(pVariant, sczValue, 0, BURN_VARIANT_TYPE_FORMATTED == pValue->Type); | ||
| 336 | } | ||
| 337 | StrSecureZeroFreeString(sczValue); | ||
| 338 | break; | 254 | break; |
| 339 | case BURN_VARIANT_TYPE_VERSION: | 255 | case BURN_VARIANT_TYPE_VERSION: |
| 340 | hr = BVariantGetVersionSilent(pValue, TRUE, &pVersionValue); | 256 | hr = BVariantSetVersion(pVariant, pValue->pValue); |
| 341 | if (SUCCEEDED(hr)) | ||
| 342 | { | ||
| 343 | hr = BVariantSetVersion(pVariant, pVersionValue); | ||
| 344 | } | ||
| 345 | break; | 257 | break; |
| 346 | default: | 258 | default: |
| 347 | hr = E_INVALIDARG; | 259 | hr = E_INVALIDARG; |
| 348 | } | 260 | } |
| 349 | ExitOnFailure(hr, "Failed to copy variant."); | 261 | ExitOnFailure(hr, "Failed to copy variant value."); |
| 350 | |||
| 351 | hr = BVariantSetEncryption(pVariant, fEncrypt); | ||
| 352 | 262 | ||
| 353 | LExit: | 263 | LExit: |
| 354 | return hr; | 264 | return hr; |
| @@ -359,50 +269,7 @@ extern "C" HRESULT BVariantCopy( | |||
| 359 | __out BURN_VARIANT* pTarget | 269 | __out BURN_VARIANT* pTarget |
| 360 | ) | 270 | ) |
| 361 | { | 271 | { |
| 362 | HRESULT hr = S_OK; | 272 | return BVariantSetValue(pTarget, pSource); |
| 363 | LONGLONG llValue = 0; | ||
| 364 | LPWSTR sczValue = NULL; | ||
| 365 | VERUTIL_VERSION* pVersionValue = 0; | ||
| 366 | |||
| 367 | BVariantUninitialize(pTarget); | ||
| 368 | |||
| 369 | switch (pSource->Type) | ||
| 370 | { | ||
| 371 | case BURN_VARIANT_TYPE_NONE: | ||
| 372 | break; | ||
| 373 | case BURN_VARIANT_TYPE_NUMERIC: | ||
| 374 | hr = BVariantGetNumeric(pSource, &llValue); | ||
| 375 | if (SUCCEEDED(hr)) | ||
| 376 | { | ||
| 377 | hr = BVariantSetNumeric(pTarget, llValue); | ||
| 378 | } | ||
| 379 | SecureZeroMemory(&llValue, sizeof(llValue)); | ||
| 380 | break; | ||
| 381 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | ||
| 382 | case BURN_VARIANT_TYPE_STRING: | ||
| 383 | hr = BVariantGetString(pSource, &sczValue); | ||
| 384 | if (SUCCEEDED(hr)) | ||
| 385 | { | ||
| 386 | hr = BVariantSetString(pTarget, sczValue, 0, BURN_VARIANT_TYPE_FORMATTED == pSource->Type); | ||
| 387 | } | ||
| 388 | StrSecureZeroFreeString(sczValue); | ||
| 389 | break; | ||
| 390 | case BURN_VARIANT_TYPE_VERSION: | ||
| 391 | hr = BVariantGetVersionSilent(pSource, TRUE, &pVersionValue); | ||
| 392 | if (SUCCEEDED(hr)) | ||
| 393 | { | ||
| 394 | hr = BVariantSetVersion(pTarget, pVersionValue); | ||
| 395 | } | ||
| 396 | break; | ||
| 397 | default: | ||
| 398 | hr = E_INVALIDARG; | ||
| 399 | } | ||
| 400 | ExitOnFailure(hr, "Failed to copy variant."); | ||
| 401 | |||
| 402 | hr = BVariantSetEncryption(pTarget, pSource->fEncryptString); | ||
| 403 | |||
| 404 | LExit: | ||
| 405 | return hr; | ||
| 406 | } | 273 | } |
| 407 | 274 | ||
| 408 | extern "C" HRESULT BVariantChangeType( | 275 | extern "C" HRESULT BVariantChangeType( |
| @@ -412,7 +279,6 @@ extern "C" HRESULT BVariantChangeType( | |||
| 412 | { | 279 | { |
| 413 | HRESULT hr = S_OK; | 280 | HRESULT hr = S_OK; |
| 414 | BURN_VARIANT variant = { }; | 281 | BURN_VARIANT variant = { }; |
| 415 | BOOL fEncrypt = pVariant->fEncryptString; | ||
| 416 | 282 | ||
| 417 | if (pVariant->Type == type) | 283 | if (pVariant->Type == type) |
| 418 | { | 284 | { |
| @@ -449,143 +315,7 @@ extern "C" HRESULT BVariantChangeType( | |||
| 449 | BVariantUninitialize(pVariant); | 315 | BVariantUninitialize(pVariant); |
| 450 | memcpy_s(pVariant, sizeof(BURN_VARIANT), &variant, sizeof(BURN_VARIANT)); | 316 | memcpy_s(pVariant, sizeof(BURN_VARIANT), &variant, sizeof(BURN_VARIANT)); |
| 451 | SecureZeroMemory(&variant, sizeof(BURN_VARIANT)); | 317 | SecureZeroMemory(&variant, sizeof(BURN_VARIANT)); |
| 452 | BVariantSetEncryption(pVariant, fEncrypt); | ||
| 453 | 318 | ||
| 454 | LExit: | 319 | LExit: |
| 455 | return hr; | 320 | return hr; |
| 456 | } | 321 | } |
| 457 | |||
| 458 | extern "C" HRESULT BVariantSetEncryption( | ||
| 459 | __in BURN_VARIANT* pVariant, | ||
| 460 | __in BOOL fEncrypt | ||
| 461 | ) | ||
| 462 | { | ||
| 463 | HRESULT hr = S_OK; | ||
| 464 | |||
| 465 | if (pVariant->fEncryptString == fEncrypt) | ||
| 466 | { | ||
| 467 | // The requested encryption state is already applied. | ||
| 468 | ExitFunction(); | ||
| 469 | } | ||
| 470 | |||
| 471 | switch (pVariant->Type) | ||
| 472 | { | ||
| 473 | case BURN_VARIANT_TYPE_NONE: | ||
| 474 | case BURN_VARIANT_TYPE_NUMERIC: | ||
| 475 | case BURN_VARIANT_TYPE_VERSION: | ||
| 476 | hr = S_OK; | ||
| 477 | break; | ||
| 478 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | ||
| 479 | case BURN_VARIANT_TYPE_STRING: | ||
| 480 | hr = BVariantEncryptString(pVariant, fEncrypt); | ||
| 481 | break; | ||
| 482 | default: | ||
| 483 | hr = E_INVALIDARG; | ||
| 484 | } | ||
| 485 | ExitOnFailure(hr, "Failed to set the variant's encryption state"); | ||
| 486 | pVariant->fEncryptString = fEncrypt; | ||
| 487 | |||
| 488 | LExit: | ||
| 489 | return hr; | ||
| 490 | } | ||
| 491 | |||
| 492 | static HRESULT BVariantEncryptString( | ||
| 493 | __in BURN_VARIANT* pVariant, | ||
| 494 | __in BOOL fEncrypt | ||
| 495 | ) | ||
| 496 | { | ||
| 497 | HRESULT hr = S_OK; | ||
| 498 | SIZE_T cbData = 0; | ||
| 499 | |||
| 500 | if (NULL == pVariant->sczValue) | ||
| 501 | { | ||
| 502 | ExitFunction(); | ||
| 503 | } | ||
| 504 | |||
| 505 | cbData = MemSize(pVariant->sczValue); | ||
| 506 | if (-1 == cbData) | ||
| 507 | { | ||
| 508 | hr = E_INVALIDARG; | ||
| 509 | ExitOnFailure(hr, "Failed to get the size of the string"); | ||
| 510 | } | ||
| 511 | |||
| 512 | DWORD remainder = fEncrypt ? cbData % CRYP_ENCRYPT_MEMORY_SIZE : 0; | ||
| 513 | DWORD extraNeeded = 0 < remainder ? CRYP_ENCRYPT_MEMORY_SIZE - remainder : 0; | ||
| 514 | if ((MAXDWORD - extraNeeded) < cbData) | ||
| 515 | { | ||
| 516 | hr = E_INVALIDDATA; | ||
| 517 | ExitOnFailure(hr, "The string is too big: size %u", cbData); | ||
| 518 | } | ||
| 519 | else if (0 < extraNeeded) | ||
| 520 | { | ||
| 521 | cbData += extraNeeded; | ||
| 522 | LPVOID pvNew = NULL; | ||
| 523 | hr = MemReAllocSecure(static_cast<LPVOID>(pVariant->sczValue), cbData, TRUE, &pvNew); | ||
| 524 | ExitOnFailure(hr, "Failed to resize the string so it could be encrypted"); | ||
| 525 | pVariant->sczValue = static_cast<LPWSTR>(pvNew); | ||
| 526 | } | ||
| 527 | |||
| 528 | if (fEncrypt) | ||
| 529 | { | ||
| 530 | hr = CrypEncryptMemory(pVariant->sczValue, static_cast<DWORD>(cbData), VARIANT_ENCRYPTION_SCOPE); | ||
| 531 | } | ||
| 532 | else | ||
| 533 | { | ||
| 534 | hr = CrypDecryptMemory(pVariant->sczValue, static_cast<DWORD>(cbData), VARIANT_ENCRYPTION_SCOPE); | ||
| 535 | } | ||
| 536 | |||
| 537 | LExit: | ||
| 538 | return hr; | ||
| 539 | } | ||
| 540 | |||
| 541 | static void BVariantRetrieveNumeric( | ||
| 542 | __in BURN_VARIANT* pVariant, | ||
| 543 | __out LONGLONG* pllValue | ||
| 544 | ) | ||
| 545 | { | ||
| 546 | Assert(NULL != pllValue); | ||
| 547 | |||
| 548 | *pllValue = pVariant->llValue; | ||
| 549 | } | ||
| 550 | |||
| 551 | // The contents of psczValue may be sensitive, should keep encrypted and SecureZeroFree. | ||
| 552 | static HRESULT BVariantRetrieveDecryptedString( | ||
| 553 | __in BURN_VARIANT* pVariant, | ||
| 554 | __out LPWSTR* psczValue | ||
| 555 | ) | ||
| 556 | { | ||
| 557 | HRESULT hr = S_OK; | ||
| 558 | |||
| 559 | if (!pVariant->sczValue) | ||
| 560 | { | ||
| 561 | *psczValue = NULL; | ||
| 562 | ExitFunction(); | ||
| 563 | } | ||
| 564 | |||
| 565 | if (pVariant->fEncryptString) | ||
| 566 | { | ||
| 567 | hr = BVariantEncryptString(pVariant, FALSE); | ||
| 568 | ExitOnFailure(hr, "Failed to decrypt string"); | ||
| 569 | } | ||
| 570 | |||
| 571 | hr = StrAllocStringSecure(psczValue, pVariant->sczValue, 0); | ||
| 572 | ExitOnFailure(hr, "Failed to copy value."); | ||
| 573 | |||
| 574 | if (pVariant->fEncryptString) | ||
| 575 | { | ||
| 576 | hr = BVariantEncryptString(pVariant, TRUE); | ||
| 577 | } | ||
| 578 | |||
| 579 | LExit: | ||
| 580 | return hr; | ||
| 581 | } | ||
| 582 | |||
| 583 | static void BVariantRetrieveVersion( | ||
| 584 | __in BURN_VARIANT* pVariant, | ||
| 585 | __out VERUTIL_VERSION** ppValue | ||
| 586 | ) | ||
| 587 | { | ||
| 588 | Assert(ppValue); | ||
| 589 | |||
| 590 | *ppValue = pVariant->pValue; | ||
| 591 | } | ||
diff --git a/src/engine/variant.h b/src/engine/variant.h index 34d7a187..e460005b 100644 --- a/src/engine/variant.h +++ b/src/engine/variant.h | |||
| @@ -30,7 +30,6 @@ typedef struct _BURN_VARIANT | |||
| 30 | LPWSTR sczValue; | 30 | LPWSTR sczValue; |
| 31 | }; | 31 | }; |
| 32 | BURN_VARIANT_TYPE Type; | 32 | BURN_VARIANT_TYPE Type; |
| 33 | BOOL fEncryptString; | ||
| 34 | } BURN_VARIANT; | 33 | } BURN_VARIANT; |
| 35 | 34 | ||
| 36 | 35 | ||
| @@ -79,7 +78,6 @@ HRESULT BVariantSetVersion( | |||
| 79 | BVariantSetValue - Convenience function that calls BVariantUninitialize, | 78 | BVariantSetValue - Convenience function that calls BVariantUninitialize, |
| 80 | BVariantSetNumeric, BVariantSetString, or | 79 | BVariantSetNumeric, BVariantSetString, or |
| 81 | BVariantSetVersion based on the type of pValue. | 80 | BVariantSetVersion based on the type of pValue. |
| 82 | The encryption state of pVariant is preserved. | ||
| 83 | ********************************************************************/ | 81 | ********************************************************************/ |
| 84 | HRESULT BVariantSetValue( | 82 | HRESULT BVariantSetValue( |
| 85 | __in BURN_VARIANT* pVariant, | 83 | __in BURN_VARIANT* pVariant, |
| @@ -87,8 +85,6 @@ HRESULT BVariantSetValue( | |||
| 87 | ); | 85 | ); |
| 88 | /******************************************************************** | 86 | /******************************************************************** |
| 89 | BVariantCopy - creates a copy of pSource. | 87 | BVariantCopy - creates a copy of pSource. |
| 90 | The encryption state of pTarget is set to | ||
| 91 | the encryption state of pSource. | ||
| 92 | ********************************************************************/ | 88 | ********************************************************************/ |
| 93 | HRESULT BVariantCopy( | 89 | HRESULT BVariantCopy( |
| 94 | __in BURN_VARIANT* pSource, | 90 | __in BURN_VARIANT* pSource, |
| @@ -98,15 +94,6 @@ HRESULT BVariantChangeType( | |||
| 98 | __in BURN_VARIANT* pVariant, | 94 | __in BURN_VARIANT* pVariant, |
| 99 | __in BURN_VARIANT_TYPE type | 95 | __in BURN_VARIANT_TYPE type |
| 100 | ); | 96 | ); |
| 101 | /******************************************************************** | ||
| 102 | BVariantSetEncryption - sets the encryption state of pVariant. | ||
| 103 | If the encryption state matches the requested | ||
| 104 | state, this function does nothing. | ||
| 105 | ********************************************************************/ | ||
| 106 | HRESULT BVariantSetEncryption( | ||
| 107 | __in BURN_VARIANT* pVariant, | ||
| 108 | __in BOOL fEncrypt | ||
| 109 | ); | ||
| 110 | 97 | ||
| 111 | #if defined(__cplusplus) | 98 | #if defined(__cplusplus) |
| 112 | } | 99 | } |
diff --git a/src/test/BurnUnitTest/VariantTest.cpp b/src/test/BurnUnitTest/VariantTest.cpp index 34328f53..43899a2b 100644 --- a/src/test/BurnUnitTest/VariantTest.cpp +++ b/src/test/BurnUnitTest/VariantTest.cpp | |||
| @@ -68,7 +68,7 @@ namespace Bootstrapper | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | private: | 70 | private: |
| 71 | void InitFormattedValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 71 | void InitFormattedValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL /*fHidden*/, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 72 | { | 72 | { |
| 73 | HRESULT hr = S_OK; | 73 | HRESULT hr = S_OK; |
| 74 | pValue->Type = BURN_VARIANT_TYPE_FORMATTED; | 74 | pValue->Type = BURN_VARIANT_TYPE_FORMATTED; |
| @@ -78,34 +78,18 @@ namespace Bootstrapper | |||
| 78 | 78 | ||
| 79 | hr = BVariantCopy(pValue, pActualValue); | 79 | hr = BVariantCopy(pValue, pActualValue); |
| 80 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | 80 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); |
| 81 | |||
| 82 | if (fHidden) | ||
| 83 | { | ||
| 84 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 85 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 86 | |||
| 87 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 88 | } | ||
| 89 | } | 81 | } |
| 90 | 82 | ||
| 91 | void InitNoneValue(BURN_VARIANT* pValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 83 | void InitNoneValue(BURN_VARIANT* pValue, BOOL /*fHidden*/, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 92 | { | 84 | { |
| 93 | HRESULT hr = S_OK; | 85 | HRESULT hr = S_OK; |
| 94 | pValue->Type = BURN_VARIANT_TYPE_NONE; | 86 | pValue->Type = BURN_VARIANT_TYPE_NONE; |
| 95 | 87 | ||
| 96 | hr = BVariantCopy(pValue, pActualValue); | 88 | hr = BVariantCopy(pValue, pActualValue); |
| 97 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | 89 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); |
| 98 | |||
| 99 | if (fHidden) | ||
| 100 | { | ||
| 101 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 102 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 103 | |||
| 104 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 105 | } | ||
| 106 | } | 90 | } |
| 107 | 91 | ||
| 108 | void InitNumericValue(BURN_VARIANT* pValue, LONGLONG llValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 92 | void InitNumericValue(BURN_VARIANT* pValue, LONGLONG llValue, BOOL /*fHidden*/, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 109 | { | 93 | { |
| 110 | HRESULT hr = S_OK; | 94 | HRESULT hr = S_OK; |
| 111 | pValue->Type = BURN_VARIANT_TYPE_NUMERIC; | 95 | pValue->Type = BURN_VARIANT_TYPE_NUMERIC; |
| @@ -113,17 +97,9 @@ namespace Bootstrapper | |||
| 113 | 97 | ||
| 114 | hr = BVariantCopy(pValue, pActualValue); | 98 | hr = BVariantCopy(pValue, pActualValue); |
| 115 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | 99 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); |
| 116 | |||
| 117 | if (fHidden) | ||
| 118 | { | ||
| 119 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 120 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 121 | |||
| 122 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 123 | } | ||
| 124 | } | 100 | } |
| 125 | 101 | ||
| 126 | void InitStringValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 102 | void InitStringValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL /*fHidden*/, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 127 | { | 103 | { |
| 128 | HRESULT hr = S_OK; | 104 | HRESULT hr = S_OK; |
| 129 | pValue->Type = BURN_VARIANT_TYPE_STRING; | 105 | pValue->Type = BURN_VARIANT_TYPE_STRING; |
| @@ -133,17 +109,9 @@ namespace Bootstrapper | |||
| 133 | 109 | ||
| 134 | hr = BVariantCopy(pValue, pActualValue); | 110 | hr = BVariantCopy(pValue, pActualValue); |
| 135 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | 111 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); |
| 136 | |||
| 137 | if (fHidden) | ||
| 138 | { | ||
| 139 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 140 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 141 | |||
| 142 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 143 | } | ||
| 144 | } | 112 | } |
| 145 | 113 | ||
| 146 | void InitVersionValue(BURN_VARIANT* pValue, LPCWSTR wzValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue) | 114 | void InitVersionValue(BURN_VARIANT* pValue, LPCWSTR wzValue, BOOL /*fHidden*/, LPCWSTR wz, BURN_VARIANT* pActualValue) |
| 147 | { | 115 | { |
| 148 | HRESULT hr = S_OK; | 116 | HRESULT hr = S_OK; |
| 149 | VERUTIL_VERSION* pVersion = NULL; | 117 | VERUTIL_VERSION* pVersion = NULL; |
| @@ -159,14 +127,6 @@ namespace Bootstrapper | |||
| 159 | 127 | ||
| 160 | hr = BVariantCopy(pValue, pActualValue); | 128 | hr = BVariantCopy(pValue, pActualValue); |
| 161 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); | 129 | NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz); |
| 162 | |||
| 163 | if (fHidden) | ||
| 164 | { | ||
| 165 | hr = BVariantSetEncryption(pActualValue, TRUE); | ||
| 166 | NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz); | ||
| 167 | |||
| 168 | NativeAssert::True(pActualValue->fEncryptString); | ||
| 169 | } | ||
| 170 | } | 130 | } |
| 171 | finally | 131 | finally |
| 172 | { | 132 | { |
