VirtualBox

Changeset 102398 in vbox


Ignore:
Timestamp:
Nov 30, 2023 2:03:14 PM (12 months ago)
Author:
vboxsync
Message:

Main/Unattended: Removed the more flexible solution of being able to shasum/shacrypt every variable upon request. Now only the USER_PASSWORD + ROOT_PASSWORD variables can be shacrypted via hardcoded USER_PASSWORD_SHACRYPT512 + ROOT_PASSWORD_SHACRYPT512. bugref:10551

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/UnattendedScript.cpp

    r102360 r102398  
    647647{
    648648#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)
    665650/** Uses the RTCrShaCrypt APIs to hash and crypt data. Uses a randomized salt + (recommended) default rounds. */
    666651#define SHACRYPT_AND_ASSIGN(a_szKey, a_fnHashAndCrypt, a_cbHashSize) \
     
    685670
    686671    /*
    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     /*
    698672     * Variables
    699673     */
     
    702676    else if (IS_MATCH("USER_PASSWORD"))
    703677        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);
    704680    else if (IS_MATCH("ROOT_PASSWORD"))
    705681        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);
    706684    else if (IS_MATCH("USER_FULL_NAME"))
    707685        pszValue = mpUnattended->i_getFullUserName().c_str();
     
    803781    else if (IS_MATCH("HAS_PROXY"))
    804782        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     }
    833783    /*
    834784     * Unknown variable.
     
    843793    if (ppszValue)
    844794        *ppszValue = pszValue;
    845 
    846 #undef HASH_AND_ASSIGN
    847 #undef CALCULATE_SUFFIX_LEN_IF_ENDS_WITH
    848 #undef ENDS_WITH
    849 #undef IS_MATCH
    850 
    851795    return VINF_SUCCESS;
    852796}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette