Changeset 102398 in vbox
- Timestamp:
- Nov 30, 2023 2:03:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/UnattendedScript.cpp
r102360 r102398 647 647 { 648 648 #define IS_MATCH(a_szMatch) \ 649 (cchNameWithoutSuffix == sizeof(a_szMatch) - 1U && memcmp(pchName, a_szMatch, sizeof(a_szMatch) - 1U) == 0) 650 #define ENDS_WITH(a_szMatch) \ 651 ( cchName \ 652 && cchName >= sizeof(a_szMatch) - 1U \ 653 && memcmp(&pchName[cchName - (sizeof(a_szMatch) - 1U)], a_szMatch, sizeof(a_szMatch) - 1U) == 0) 654 #define CALCULATE_SUFFIX_LEN_IF_ENDS_WITH(a_szSuff) \ 655 if (ENDS_WITH(a_szSuff)) \ 656 cchNameWithoutSuffix = cchName - (sizeof(a_szSuff) - 1U); 657 #define HASH_AND_ASSIGN(a_abData, a_cbData, a_fnHash, a_cbHashSize) \ 658 do { \ 659 uint8_t abHash[a_cbHashSize]; \ 660 a_fnHash(a_abData, a_cbData, abHash); \ 661 char szDigest[a_cbHashSize * 4]; \ 662 a_fnHash##ToString(abHash, szDigest, sizeof(szDigest)); \ 663 pszValue = rstrTmp.assign(szDigest, strlen(szDigest)).c_str(); \ 664 } while (0) 649 (cchName == sizeof(a_szMatch) - 1U && memcmp(pchName, a_szMatch, sizeof(a_szMatch) - 1U) == 0) 665 650 /** Uses the RTCrShaCrypt APIs to hash and crypt data. Uses a randomized salt + (recommended) default rounds. */ 666 651 #define SHACRYPT_AND_ASSIGN(a_szKey, a_fnHashAndCrypt, a_cbHashSize) \ … … 685 670 686 671 /* 687 * Calculate the variable name length w/o any suffixes we want to handle down below.688 */689 size_t cchNameWithoutSuffix = cchName;690 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_SHACRYPT512");691 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_SHACRYPT256");692 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_SHA512");693 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_SHA256");694 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_SHA1");695 CALCULATE_SUFFIX_LEN_IF_ENDS_WITH("_MD5");696 697 /*698 672 * Variables 699 673 */ … … 702 676 else if (IS_MATCH("USER_PASSWORD")) 703 677 pszValue = mpUnattended->i_getPassword().c_str(); 678 else if (IS_MATCH("USER_PASSWORD_SHACRYPT512")) 679 SHACRYPT_AND_ASSIGN(mpUnattended->i_getPassword().c_str(), RTCrShaCrypt512, RTSHA512_HASH_SIZE); 704 680 else if (IS_MATCH("ROOT_PASSWORD")) 705 681 pszValue = mpUnattended->i_getPassword().c_str(); 682 else if (IS_MATCH("ROOT_PASSWORD_SHACRYPT512")) 683 SHACRYPT_AND_ASSIGN(mpUnattended->i_getPassword().c_str(), RTCrShaCrypt512, RTSHA512_HASH_SIZE); 706 684 else if (IS_MATCH("USER_FULL_NAME")) 707 685 pszValue = mpUnattended->i_getFullUserName().c_str(); … … 803 781 else if (IS_MATCH("HAS_PROXY")) 804 782 pszValue = mpUnattended->i_getProxy().isNotEmpty() ? "1" : "0"; 805 806 /*807 * Hash output, if needed.808 *809 * Keep them ordered, strongest first (most likely nowadays).810 * Add more here once we need them.811 */812 if (pszValue)813 {814 /*815 * SHAcrypt stuff.816 */817 if (ENDS_WITH("_SHACRYPT512"))818 SHACRYPT_AND_ASSIGN(pszValue, RTCrShaCrypt512, RTSHA512_HASH_SIZE);819 else if (ENDS_WITH("_SHACRYPT256"))820 SHACRYPT_AND_ASSIGN(pszValue, RTCrShaCrypt256, RTSHA256_HASH_SIZE);821 /*822 * Regular hashing.823 */824 else if (ENDS_WITH("_SHA512"))825 HASH_AND_ASSIGN(pszValue, strlen(pszValue), RTSha512, RTSHA512_HASH_SIZE);826 else if (ENDS_WITH("_SHA256"))827 HASH_AND_ASSIGN(pszValue, strlen(pszValue), RTSha256, RTSHA256_HASH_SIZE);828 else if (ENDS_WITH("_SHA1"))829 HASH_AND_ASSIGN(pszValue, strlen(pszValue), RTSha1, RTSHA1_HASH_SIZE);830 else if (ENDS_WITH("_MD5"))831 HASH_AND_ASSIGN(pszValue, strlen(pszValue), RTMd5, RTMD5_HASH_SIZE);832 }833 783 /* 834 784 * Unknown variable. … … 843 793 if (ppszValue) 844 794 *ppszValue = pszValue; 845 846 #undef HASH_AND_ASSIGN847 #undef CALCULATE_SUFFIX_LEN_IF_ENDS_WITH848 #undef ENDS_WITH849 #undef IS_MATCH850 851 795 return VINF_SUCCESS; 852 796 }
Note:
See TracChangeset
for help on using the changeset viewer.