VirtualBox

Changeset 55362 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Apr 21, 2015 5:28:50 PM (10 years ago)
Author:
vboxsync
Message:

DevSmc cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r55314 r55362  
    132132
    133133
    134 
    135 #if defined(RT_OS_DARWIN)
    136 
    137 static int DarwinSmcKey(char *pabKey, uint32_t cbKey)
    138 {
    139     /*
    140      * Method as described in Amit Singh's article:
    141      *   http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
    142      */
    143     typedef struct
    144     {
    145         uint32_t   key;
    146         uint8_t    pad0[22];
    147         uint32_t   datasize;
    148         uint8_t    pad1[10];
    149         uint8_t    cmd;
    150         uint32_t   pad2;
    151         uint8_t    data[32];
    152     } AppleSMCBuffer;
    153 
    154     AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
    155 
    156     io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
    157                                                        IOServiceMatching("AppleSMC"));
    158     if (!service)
    159         return VERR_NOT_FOUND;
    160 
    161     io_connect_t    port = (io_connect_t)0;
    162     kern_return_t   kr   = IOServiceOpen(service, mach_task_self(), 0, &port);
    163     IOObjectRelease(service);
    164 
    165     if (kr != kIOReturnSuccess)
    166         return RTErrConvertFromDarwin(kr);
    167 
    168     AppleSMCBuffer  inputStruct    = { 0, {0}, 32, {0}, 5, };
    169     AppleSMCBuffer  outputStruct;
    170     size_t          cbOutputStruct = sizeof(outputStruct);
    171 
    172     for (int i = 0; i < 2; i++)
    173     {
    174         inputStruct.key = (uint32_t)(i == 0 ? 'OSK0' : 'OSK1');
    175         kr = IOConnectCallStructMethod((mach_port_t)port,
    176                                        (uint32_t)2,
    177                                        (const void *)&inputStruct,
    178                                        sizeof(inputStruct),
    179                                        (void *)&outputStruct,
    180                                        &cbOutputStruct);
    181         if (kr != kIOReturnSuccess)
    182         {
    183             IOServiceClose(port);
    184             return RTErrConvertFromDarwin(kr);
    185         }
    186 
    187         for (int j = 0; j < 32; j++)
    188             pabKey[j + i*32] = outputStruct.data[j];
    189     }
    190 
    191     IOServiceClose(port);
    192 
    193     pabKey[64] = 0;
    194 
    195     return VINF_SUCCESS;
    196 }
    197 
    198 #endif /* RT_OS_DARWIN */
    199 
    200134/* Darwin compile kludge */
    201135#undef PVM
     
    273207
    274208#ifdef RT_OS_DARWIN
     209
    275210    /*
    276      * Query it here and now.
     211     * Work done in EFI/DevSmc
    277212     */
    278     char abKeyBuf[65];
    279     int rc = DarwinSmcKey(abKeyBuf, sizeof(abKeyBuf));
    280     if (SUCCEEDED(rc))
    281     {
    282         *pStrKey = abKeyBuf;
    283         *pfGetKeyFromRealSMC = true;
    284         return rc;
    285     }
    286     LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
     213    *pfGetKeyFromRealSMC = true;
     214    int rc = VINF_SUCCESS;
    287215
    288216#else
     
    15961524            AssertRCReturn(rc, rc);
    15971525
    1598             InsertConfigString(pCfg,   "DeviceKey", strKey);
     1526            if (!fGetKeyFromRealSMC)
     1527                InsertConfigString(pCfg,   "DeviceKey", strKey);
    15991528            InsertConfigInteger(pCfg,  "GetKeyFromRealSMC", fGetKeyFromRealSMC);
    16001529        }
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