- 時間撮記:
- 2015-3-4 下午02:36:39 (10 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r54592 r54625 3380 3380 { 3381 3381 memcpy(pbKey, aPassword.c_str(), cbKey); 3382 3383 /* Scramble content to make retrieving the key more difficult. */ 3384 rc = RTMemSaferScramble(pbKey, cbKey); 3385 AssertRC(rc); 3382 3386 SecretKey *pKey = new SecretKey(pbKey, cbKey, !!aClearOnSuspend); 3383 3387 /* Add the key to the map */ … … 4546 4550 4547 4551 /** 4548 * Removes the key interfaces from all disk attachments, useful when 4549 * changing the key store or dropping it. 4552 * Initializes the secret key interface on all configured attachments. 4553 * 4554 * @returns COM status code. 4550 4555 */ 4551 HRESULT Console::i_ clearDiskEncryptionKeysOnAllAttachments(void)4556 HRESULT Console::i_initSecretKeyIfOnAllAttachments(void) 4552 4557 { 4553 4558 HRESULT hrc = S_OK; … … 4571 4576 { 4572 4577 const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[i]; 4573 4574 4578 /* 4575 4579 * Query storage controller, port and device … … 4630 4634 4631 4635 /** 4632 * Configures the encryption support for the disk which have encryption conigured4633 * with the configured key.4636 * Removes the key interfaces from all disk attachments with the given key ID. 4637 * Useful when changing the key store or dropping it. 4634 4638 * 4635 4639 * @returns COM status code. 4636 * @param aId The ID of the password.4640 * @param aId The ID to look for. 4637 4641 */ 4638 HRESULT Console::i_c onfigureEncryptionForDisk(const com::Utf8Str &strId)4642 HRESULT Console::i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId) 4639 4643 { 4640 4644 HRESULT hrc = S_OK; … … 4652 4656 4653 4657 hrc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments)); 4654 if (FAILED(hrc)) 4655 return hrc; 4658 AssertComRCReturnRC(hrc); 4656 4659 4657 4660 /* Find the correct attachment. */ … … 4678 4681 hrc = pBase->GetProperty(Bstr("CRYPT/KeyId").raw(), bstrKeyId.asOutParam()); 4679 4682 if (hrc == VBOX_E_OBJECT_NOT_FOUND) 4683 { 4684 hrc = S_OK; 4680 4685 continue; 4686 } 4687 else if (FAILED(hrc)) 4688 break; 4689 4690 if (strId.equals(Utf8Str(bstrKeyId))) 4691 { 4692 4693 /* 4694 * Query storage controller, port and device 4695 * to identify the correct driver. 4696 */ 4697 ComPtr<IStorageController> pStorageCtrl; 4698 Bstr storageCtrlName; 4699 LONG lPort, lDev; 4700 ULONG ulStorageCtrlInst; 4701 4702 hrc = pAtt->COMGETTER(Controller)(storageCtrlName.asOutParam()); 4703 AssertComRC(hrc); 4704 4705 hrc = pAtt->COMGETTER(Port)(&lPort); 4706 AssertComRC(hrc); 4707 4708 hrc = pAtt->COMGETTER(Device)(&lDev); 4709 AssertComRC(hrc); 4710 4711 hrc = mMachine->GetStorageControllerByName(storageCtrlName.raw(), pStorageCtrl.asOutParam()); 4712 AssertComRC(hrc); 4713 4714 hrc = pStorageCtrl->COMGETTER(Instance)(&ulStorageCtrlInst); 4715 AssertComRC(hrc); 4716 4717 StorageControllerType_T enmCtrlType; 4718 hrc = pStorageCtrl->COMGETTER(ControllerType)(&enmCtrlType); 4719 AssertComRC(hrc); 4720 const char *pcszDevice = i_convertControllerTypeToDev(enmCtrlType); 4721 4722 StorageBus_T enmBus; 4723 hrc = pStorageCtrl->COMGETTER(Bus)(&enmBus); 4724 AssertComRC(hrc); 4725 4726 unsigned uLUN; 4727 hrc = Console::i_convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); 4728 AssertComRC(hrc); 4729 4730 PPDMIBASE pIBase = NULL; 4731 PPDMIMEDIA pIMedium = NULL; 4732 int rc = PDMR3QueryDriverOnLun(ptrVM.rawUVM(), pcszDevice, ulStorageCtrlInst, uLUN, "VD", &pIBase); 4733 if (RT_SUCCESS(rc)) 4734 { 4735 if (pIBase) 4736 { 4737 pIMedium = (PPDMIMEDIA)pIBase->pfnQueryInterface(pIBase, PDMIMEDIA_IID); 4738 if (pIMedium) 4739 { 4740 rc = pIMedium->pfnSetSecKeyIf(pIMedium, NULL, mpIfSecKeyHlp); 4741 Assert(RT_SUCCESS(rc) || rc == VERR_NOT_SUPPORTED); 4742 } 4743 } 4744 } 4745 } 4746 } 4747 4748 return hrc; 4749 } 4750 4751 /** 4752 * Configures the encryption support for the disk which have encryption conigured 4753 * with the configured key. 4754 * 4755 * @returns COM status code. 4756 * @param strId The ID of the password. 4757 */ 4758 HRESULT Console::i_configureEncryptionForDisk(const com::Utf8Str &strId) 4759 { 4760 HRESULT hrc = S_OK; 4761 SafeIfaceArray<IMediumAttachment> sfaAttachments; 4762 4763 AutoCaller autoCaller(this); 4764 AssertComRCReturnRC(autoCaller.rc()); 4765 4766 /* Get the VM - must be done before the read-locking. */ 4767 SafeVMPtr ptrVM(this); 4768 if (!ptrVM.isOk()) 4769 return ptrVM.rc(); 4770 4771 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 4772 4773 hrc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(sfaAttachments)); 4774 if (FAILED(hrc)) 4775 return hrc; 4776 4777 /* Find the correct attachment. */ 4778 for (unsigned i = 0; i < sfaAttachments.size(); i++) 4779 { 4780 const ComPtr<IMediumAttachment> &pAtt = sfaAttachments[i]; 4781 ComPtr<IMedium> pMedium; 4782 ComPtr<IMedium> pBase; 4783 Bstr bstrKeyId; 4784 4785 hrc = pAtt->COMGETTER(Medium)(pMedium.asOutParam()); 4786 if (FAILED(hrc)) 4787 break; 4788 4789 /* Skip non hard disk attachments. */ 4790 if (pMedium.isNull()) 4791 continue; 4792 4793 /* Get the UUID of the base medium and compare. */ 4794 hrc = pMedium->COMGETTER(Base)(pBase.asOutParam()); 4795 if (FAILED(hrc)) 4796 break; 4797 4798 hrc = pBase->GetProperty(Bstr("CRYPT/KeyId").raw(), bstrKeyId.asOutParam()); 4799 if (hrc == VBOX_E_OBJECT_NOT_FOUND) 4800 { 4801 hrc = S_OK; 4802 continue; 4803 } 4681 4804 else if (FAILED(hrc)) 4682 4805 break; … … 6258 6381 else 6259 6382 { 6260 /* Unconfigure disk encryption from all attachments. */ 6261 i_clearDiskEncryptionKeysOnAllAttachments(); 6262 6263 /* Clear any keys we have stored. */ 6264 for (SecretKeyMap::iterator it = m_mapSecretKeys.begin(); 6265 it != m_mapSecretKeys.end(); 6266 it++) 6267 delete it->second; 6268 m_mapSecretKeys.clear(); 6383 /* Remove keys which are supposed to be removed on a VM suspend. */ 6384 SecretKeyMap::iterator it = m_mapSecretKeys.begin(); 6385 while (it != m_mapSecretKeys.end()) 6386 { 6387 SecretKey *pKey = it->second; 6388 if (pKey->m_fRemoveOnSuspend) 6389 { 6390 /* Unconfigure disk encryption from all attachments associated with this key. */ 6391 i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(it->first); 6392 6393 AssertMsg(!pKey->m_cRefs, ("No one should access the stored key at this point anymore!\n")); 6394 delete pKey; 6395 m_mapSecretKeys.erase(it++); 6396 } 6397 else 6398 it++; 6399 } 6269 6400 } 6270 6401 … … 8426 8557 * get notified about missing keys. 8427 8558 */ 8428 that->i_ clearDiskEncryptionKeysOnAllAttachments();8559 that->i_initSecretKeyIfOnAllAttachments(); 8429 8560 break; 8430 8561 } … … 10460 10591 SecretKey *pKey = (*it).second; 10461 10592 10462 ASMAtomicIncU32(&pKey->m_cRefs); 10593 uint32_t cRefs = ASMAtomicIncU32(&pKey->m_cRefs); 10594 if (cRefs == 1) 10595 { 10596 int rc = RTMemSaferUnscramble(pKey->m_pbKey, pKey->m_cbKey); 10597 AssertRC(rc); 10598 } 10463 10599 *ppszPassword = (const char *)pKey->m_pbKey; 10464 10600 return VINF_SUCCESS; … … 10481 10617 { 10482 10618 SecretKey *pKey = (*it).second; 10483 ASMAtomicDecU32(&pKey->m_cRefs); 10619 uint32_t cRefs = ASMAtomicDecU32(&pKey->m_cRefs); 10620 if (!cRefs) 10621 { 10622 int rc = RTMemSaferScramble(pKey->m_pbKey, pKey->m_cbKey); 10623 AssertRC(rc); 10624 } 10484 10625 return VINF_SUCCESS; 10485 10626 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器