-
Notifications
You must be signed in to change notification settings - Fork 6
/
lukspinentry
executable file
·73 lines (64 loc) · 1.95 KB
/
lukspinentry
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
#!/usr/bin/perl -w
# Copyright 2014 Daniel Jay Haskin.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use utf8;
use FileHandle;
use IPC::Open2;
use Env qw( LC_CTYPE DISPLAY SSH_TTY );
my $arg = shift(@ARGV);
# open pinentry
my $pid = "";
if ( defined($DISPLAY) && !defined($SSH_TTY) ) {
$pid = open2(*IN, *OUT, "pinentry-x11 -g") || die;
} else {
# get a tty
open F, "tty |" || die ("can't fork to tty");
my $tty = <F>;
close F;
$pid = open2(*IN, *OUT, "pinentry-curses --ttyname $tty") || die;
}
my $lctype = "en_US.UTF-8";
if ( defined($LC_CTYPE) ) {
$lctype = $LC_CTYPE;
}
print OUT "OPTION lc-ctype=$lctype\n";
############################################################################
sub getpass($) {
my $prompt = shift;
# print OUT "SETDESC LUKS Passphrase\nSETPROMPT $prompt\nGETPIN\n";
print OUT "SETPROMPT $prompt\nGETPIN\n";
while ( <IN> ) {
if ( /^OK/ ) {
next;
} elsif ( /^ERR \d+ (.*)/ ) {
print STDERR $1."\n";
exit 1;
last;
} elsif ( /^D (.*)/ ) {
return $1;
}
}
}
if ( defined($arg) && $arg eq "invalid" ) {
print OUT "SETERROR Invalid Passphrase, try again\n";
}
my $p = getpass("Enter Passphrase");
if ( defined($arg) && $arg eq "confirm" ) {
while ( $p ne getpass("Confirm Passphrase") ) {
print OUT "SETDESC Passhphrases do not match\nMESSAGE\n";
$p = getpass("Re-Enter passphrase");
}
}
print "$p";