def ApplyEncryption(fvclient, username, password): """Turn encryption on.""" # Supply entropy to the system before csfde uses /dev/random. try: entropy = util.RetrieveEntropy() util.SupplyEntropy(entropy) except util.EntropyError, e: raise Error('Entropy operations failed: %s' % str(e))
def testSupplyEntropy(self): entropy = 'entropy' file_mock = mock.Mock(spec=file) mock_open = mock.Mock(spec=open) mock_open.return_value = file_mock util.SupplyEntropy(entropy, open_=mock_open) mock_open.assert_called_once_with('/dev/random', 'w') file_mock.write.assert_called_once_with(entropy)
def testSupplyEntropy(self): mock_open = self.mox.CreateMockAnything() entropy = 'entropy' mock_open('/dev/random', 'w').AndReturn(mock_open) mock_open.write(entropy).AndReturn(None) mock_open.close().AndReturn(None) self.mox.ReplayAll() util.SupplyEntropy(entropy, open_=mock_open) self.mox.VerifyAll()
def ApplyEncryption(fvclient, username, password): """Turn encryption on.""" # Supply entropy to the system. try: entropy = util.RetrieveEntropy() util.SupplyEntropy(entropy) except util.EntropyError as e: raise Error('Entropy operations failed: %s' % str(e)) # Use "fdesetup" on Mac OS 10.8+ (Mountain Lion). logging.debug('Using fdesetup to enable FileVault') tool = FullDiskEncryptionSetup(username, password) volume_uuid, recovery_token = tool.EnableEncryption() fvclient.SetOwner(username) return volume_uuid, recovery_token
def ApplyEncryption(fvclient, username, password): """Turn encryption on.""" # Supply entropy to the system before csfde uses /dev/random. try: entropy = util.RetrieveEntropy() util.SupplyEntropy(entropy) except util.EntropyError as e: raise Error('Entropy operations failed: %s' % str(e)) if os.path.exists(FullDiskEncryptionSetup.PATH): # Use "fdesetup" on Mac OS 10.8+ (Mountain Lion). logging.debug('Using fdesetup to enable FileVault') tool = FullDiskEncryptionSetup(username, password) else: # Fall back on "csfde" for Mac OS 10.7 (Lion) and below. logging.debug('Using csfde to enable FileVault') tool = CoreStorageFullDiskEncryption(username, password) volume_uuid, recovery_token = tool.EnableEncryption() fvclient.SetOwner(username) return volume_uuid, recovery_token