VirtualBox

Changeset 33228 in vbox


Ignore:
Timestamp:
Oct 19, 2010 1:12:31 PM (14 years ago)
Author:
vboxsync
Message:

VBoxAuthSimple now requires SHA-256 hashes, no more cleartext passwords

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/user_Frontends.xml

    r33185 r33228  
    391391            Last but not least, you have to configure users and passwords. Here is an example
    392392            for the user "john" with the password "secret":
    393             <computeroutput>VBoxManage setextradata "VM name" "VBoxAuthSimple/users/john" "secret"</computeroutput>
    394             To specify an empty password, use the special reserved value
    395             <computeroutput>[NULL]</computeroutput>.
     393            <computeroutput>VBoxManage internalcommands passwordhash "secret"</computeroutput>
     394            This will give you the hash value "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b"
     395            which you set using
     396            <computeroutput>VBoxManage setextradata "VM name" "VBoxAuthSimple/users/john"
     397            "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b"</computeroutput>.
    396398            </para>
    397399          </listitem>
     
    409411        default "external authentication module with any other module. For this,
    410412        VirtualBox provides a well-defined interface that allows you to write your
    411         own authentication module; see <xref
    412         linkend="vbox-authenticate-sdk" /> for details.</para>
     413        own authentication module; see <xref linkend="vbox-authenticate-sdk" />
     414        for details.</para>
    413415    </sect2>
    414416
  • trunk/include/iprt/sha.h

    r32569 r33228  
    3939#define RTSHA1_HASH_SIZE    20
    4040/** The length of a SHA-1 digest string. The terminator is not included. */
    41 #define RTSHA1_DIGEST_LEN  (40)
     41#define RTSHA1_STRING_LEN  (40)
    4242
    4343/**
     
    142142#define RTSHA256_HASH_SIZE      32
    143143/** The length of a SHA-256 digest string. The terminator is not included. */
    144 #define RTSHA256_DIGEST_LEN     64
     144#define RTSHA256_STRING_LEN     64
    145145
    146146/**
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r33082 r33228  
    4343#include <iprt/string.h>
    4444#include <iprt/uuid.h>
    45 
     45#include <iprt/sha.h>
    4646
    4747#include "VBoxManage.h"
     
    137137        "Commands:\n"
    138138        "\n"
    139         "%s%s%s%s%s%s%s%s%s%s%s%s"
     139        "%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
    140140        "WARNING: This is a development tool and shall only be used to analyse\n"
    141141        "         problems. It is completely unsupported and will change in\n"
     
    238238          "       Controls debug logging.\n"
    239239          "\n"
    240         : ""
     240        : "",
     241        (u64Cmd & USAGE_PASSWORDHASH)
     242        ? "  passwordhash <passsword>\n"
     243          "       Generates a password hash.\n"
     244          "\n"
     245        :
     246          ""
    241247        );
    242248}
     
    20072013
    20082014/**
     2015 * Generate a SHA-256 password hash
     2016 */
     2017int CmdGeneratePasswordHash(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
     2018{
     2019    /* one parameter, the password to hash */
     2020    if (argc != 1)
     2021        return errorSyntax(USAGE_PASSWORDHASH, "password to hash required");
     2022
     2023    uint8_t abDigest[RTSHA256_HASH_SIZE];
     2024    RTSha256(argv[0], strlen(argv[0]), abDigest);
     2025    char pszDigest[RTSHA256_STRING_LEN + 1];
     2026    RTSha256ToString(abDigest, pszDigest, sizeof(pszDigest));
     2027    RTPrintf("Password hash: %s\n", pszDigest);
     2028   
     2029    return 0;
     2030}
     2031
     2032/**
    20092033 * Wrapper for handling internal commands
    20102034 */
     
    20452069    if (!strcmp(pszCmd, "debuglog"))
    20462070        return CmdDebugLog(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
     2071    if (!strcmp(pszCmd, "passwordhash"))
     2072        return CmdGeneratePasswordHash(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
    20472073
    20482074    /* default: */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r32712 r33228  
    9797#define USAGE_DEBUGLOG              RT_BIT_64(52)
    9898#define USAGE_SETHDPARENTUUID       RT_BIT_64(53)
     99#define USAGE_PASSWORDHASH          RT_BIT_64(54)
    99100#define USAGE_ALL                   (~(uint64_t)0)
    100101/** @} */
  • trunk/src/VBox/HostServices/auth/simple/VBoxAuthSimple.cpp

    r33185 r33228  
    2424#include <iprt/cdefs.h>
    2525#include <iprt/uuid.h>
     26#include <iprt/sha.h>
    2627
    2728#include <VBox/VRDPAuth.h>
     
    8586        user = (char*)szUser;
    8687
    87     dprintf("VRDPAuth: uuid: %s, user: %s, szPassword: %s\n", uuid, user, szPassword);
    88 
    89 #if 0
    90     /* this is crude stuff, but let's keep it there as a sample */
    91     if (getenv("VBOX_VRDP_AUTH_USER") && getenv("VBOX_VRDP_AUTH_PASSWORD"))
    92     {
    93 
    94         if (   !strcmp(getenv("VBOX_VRDP_AUTH_USER"), user)
    95             && !strcmp(getenv("VBOX_VRDP_AUTH_PASSWORD"), szPassword))
    96         {
    97             result = VRDPAuthAccessGranted;
    98         }
    99     }
    100 #endif
     88    dprintf("VBoxAuth: uuid: %s, user: %s, szPassword: %s\n", uuid, user, szPassword);
    10189
    10290    ComPtr<IVirtualBox> virtualBox;
     
    10694    if (SUCCEEDED(rc))
    10795    {
    108         Bstr key = BstrFmt("VRDPAuthSimple/users/%s", user);
     96        Bstr key = BstrFmt("VBoxAuthSimple/users/%s", user);
    10997        Bstr password;
    11098
     
    120108            virtualBox->GetExtraData(key.raw(), password.asOutParam());
    121109
    122         /* we compare the password or check for special NULL marker */
    123         if (   (!password.isEmpty() && (password == szPassword))
    124             || ((password == "[NULL]") && (!szPassword || (*szPassword == '\0'))))
     110        if (!password.isEmpty())
    125111        {
    126             result = VRDPAuthAccessGranted;
     112            /* calculate hash */
     113            uint8_t abDigest[RTSHA256_HASH_SIZE];
     114            RTSha256(szPassword, strlen(szPassword), abDigest);
     115            char pszDigest[RTSHA256_STRING_LEN + 1];
     116            RTSha256ToString(abDigest, pszDigest, sizeof(pszDigest));
     117                       
     118            if (password == pszDigest)
     119                result = VRDPAuthAccessGranted;
    127120        }
    128121    }
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