-
Notifications
You must be signed in to change notification settings - Fork 2
/
filevault_escrow_model.php
66 lines (56 loc) · 1.96 KB
/
filevault_escrow_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// @author gmarnin
use CFPropertyList\CFPropertyList;
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
class Filevault_escrow_model extends \Model
{
private $cryptokey;
public function __construct($serial = '')
{
parent::__construct('id', 'filevault_escrow'); //primary key, tablename
$this->rs['id'] = 0;
$this->rs['serial_number'] = $serial;
$this->rs['enableddate'] = '';
$this->rs['enableduser'] = '';
$this->rs['lvguuid'] = '';
$this->rs['lvuuid'] = '';
$this->rs['pvuuid'] = '';
$this->rs['recoverykey'] = '';
$this->rs['hddserial'] = '';
if( ! conf('encryption_key')){
throw new \Exception("No encryption key found in config", 1);
}
$this->cryptokey = Key::loadFromAsciiSafeString(conf('encryption_key'));
if ($serial) {
$this->retrieve_record($serial);
if($this->recoverykey){
try {
$this->recoverykey = Crypto::decrypt($this->recoverykey, $this->cryptokey);
}catch (\Exception $e) {
$this->recoverykey = $e->getMessage();
}
}
}
$this->serial = $serial;
}
public function process($data)
{
$parser = new CFPropertyList();
$parser->parse($data);
$plist = array_change_key_case($parser->toArray(), CASE_LOWER);
foreach (array('enableddate', 'enableduser', 'lvguuid', 'lvuuid', 'pvuuid', 'recoverykey', 'hddserial') as $item) {
if (isset($plist[$item])) {
$this->$item = $plist[$item];
} else {
$this->$item = '';
}
}
if( ! $this->recoverykey){
throw new \Exception("No Recovery Key found!", 1);
}
// Encrypt recoverykey
$this->recoverykey = Crypto::encrypt($this->recoverykey, $this->cryptokey);
$this->save();
}
}