-
Notifications
You must be signed in to change notification settings - Fork 7
/
decrypt.php
executable file
·77 lines (59 loc) · 1.57 KB
/
decrypt.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
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env php
<?php
require 'vendor/autoload.php';
define('DEST_FILE', 'decrypted_accounts.txt');
use \Decrypter\Decrypter;
use \Decrypter\Exporter;
function main()
{
exitIfNotCLI();
$args = getArguments();
$decrypter = new Decrypter(
$args['xmlFile'],
$args['exportKey'],
$args['masterKey']
);
echo "Starting decryption...\n";
$decryptedAccounts = $decrypter->decrypt();
Exporter::export($decryptedAccounts, 'lastpass', $args['destFile']);
echo "=============================\n\n";
echo "Decryption ended with " . count($decryptedAccounts) . " accounts.\n";
}
function exitIfNotCLI()
{
$sapiName = strtoupper(php_sapi_name());
if ($sapiName !== 'CLI') {
echo "This script must be called from the command line.\n";
exit(1);
}
}
function getArguments()
{
global $argc, $argv;
if ($argc < 5) {
echo "Execution: ./cli.php <path-to-xml> <export-key> <master-key> <dest-file>\n";
exit(2);
}
$xmlFile = $argv[1];
$exportKey = $argv[2];
$masterKey = $argv[3];
$destFile = $argv[4];
$exportFormat = $argv[5] ?? '<default>';
if (!file_exists($xmlFile)) {
echo "The file '$xmlFile' does not exist or couldn't be read.\n";
exit(3);
}
return [
'xmlFile' => $xmlFile,
'exportKey' => $exportKey,
'masterKey' => $masterKey,
'destFile' => $destFile
];
}
try {
main();
} catch (Exception $exception) {
echo "\nSome error happened:\n";
echo($exception->getMessage()) . "\n\n";
exit(4);
}