-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmasterpassword_generate.pl
118 lines (97 loc) · 2.64 KB
/
masterpassword_generate.pl
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl
# by Ian Vitek
#
# Takes 2 arguments.
# The first argument is the masterpassword that creates the encrypted code
# for masterpassword.pl.
# The second argument is the supersecret string that will be concatenated
# to the unique identifier for the masterpassword.pl generating script.
#
use Crypt::CBC;
use Getopt::Std;
use Term::ReadKey;
getopts('m:s:hv');
$ktemp="a";
$mtemp="a";
die "usage: $0 -m masterpassword -s supersecret_string\n" if($opt_h);
if (length($opt_m)>0) {
$k=$opt_m;
} else {
while($ktemp ne $k) {
ReadMode 2;
print "Enter encryption password: ";
chomp($ktemp = <STDIN>);
print "\n";
print "Enter encryption password again: ";
chomp($k = <STDIN>);
print "\n";
ReadMode 0;
}
}
if (length($opt_s)>0) {
$m=$opt_s;
} else {
while($mtemp ne $m) {
ReadMode 2;
print "Enter supersecret password: ";
chomp($mtemp = <STDIN>);
print "\n";
print "Enter supersecret again: ";
chomp($m = <STDIN>);
print "\n";
ReadMode 0;
}
}
while (length $k<32) { $k=$k . "\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04";}
$key=substr $k,0,32;
$c = Crypt::CBC->new( -key => $key,
-cipher => 'Twofish2'
);
$m=~s/\'/\\\'/g;
$text='$mp=\'' . $m .'\';$pass=sha256_base64($mp . $m);';
$encrypted=$c->encrypt_hex($text);
warn "Debug:\n$key\n$text\n$encrypted\n\n" if $opt_v;
$mps=<<'EOT1';
#!/usr/bin/perl
# by Ian Vitek
#
# Takes 2 arguments.
# First argument is the masterpassword that decrypts the hidden encryption
# algorithm to generate a unique password for argument 2 (e.g IP-address)
#
use Crypt::CBC;
use Digest::SHA qw(sha256_base64);
use Getopt::Std;
use Term::ReadKey;
getopts('m:u:hv');
die "usage: $0 -m masterpassword -u unique_string\n" if($opt_h);
if (length($opt_m)>0) {
$k=$opt_m;
} else {
ReadMode 2;
print "Enter encryption password: ";
chomp($k = <STDIN>);
print "\n";
ReadMode 0;
}
if (length($opt_u)>0) {
$m=$opt_u;
} else {
print "Enter unique string (e.g. IP): ";
chomp($m = <STDIN>);
print "\n";
}
EOT1
$mps=$mps . '$code="' . $encrypted . '";';
$mps=$mps . <<'EOT2';
while (length $k<32) { $k=$k . "\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04\x01\x02\x03\x04";}
$key=substr $k,0,32;
$c = Crypt::CBC->new( -key => $key,
-cipher => 'Twofish2'
);
eval $c->decrypt_hex($code);
$password=substr $pass,0,24;
print "$password\n";
EOT2
open(MP,">masterpassword.pl");
print MP $mps;