-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathunlockgeli
executable file
·86 lines (78 loc) · 2.34 KB
/
unlockgeli
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
#!/bin/sh
# PROVIDE: unlockgeli
# REQUIRE: netwait
# BEFORE: jail
. /etc/rc.subr
name=unlockgeli
rcvar=unlockgeli_enable
start_cmd="${name}_start"
stop_cmd=":"
load_rc_config $name
: ${unlockgeli:=no}
unlockgeli_start()
{
eval pools=\${$@:-${unlockgeli_pools}}
for _g in $pools; do
echo "Unlocking $_g pool"
eval devs=\${unlockgeli_${_g}_devs}
eval key=\${unlockgeli_${_g}_key}
eval key_identityfile=\${unlockgeli_${_g}_key_identityfile}
eval key_enc_pw=\${unlockgeli_${_g}_key_enc_pw}
eval passphrase=\${unlockgeli_${_g}_passphrase}
eval passphrase_identityfile=\${unlockgeli_${_g}_passphrase_identityfile}
eval passphrase_enc_pw=\${unlockgeli_${_g}_passphrase_enc_pw}
keytempfile=/tmp/unlockgeli.key.tmp
pwtempfile=/tmp/unlockgeli.pw.tmp
echo "Downloading geli key"
scp -i ${key_identityfile} ${key} $keytempfile
if [ "$?" -ne "0" ]; then
warn "Unable to download identity file ${key}"
fi
if [ -n "${key_enc_pw}" ]; then
echo "Decrypting keyfile"
mv $keytempfile ${keytempfile}.aes
openssl enc -aes-256-cbc -a -salt -d -in ${keytempfile}.aes -out $keytempfile -k "${key_enc_pw}"
if [ "$?" -ne "0" ]; then
warn "Unable to decrypt identity file ${key}"
fi
rm -f $keytempfile.aes
fi
if [ -n "${passphrase}" ]; then
echo "Downloading geli passphrase"
scp -i ${passphrase_identityfile} ${passphrase} $pwtempfile
if [ "$?" -ne "0" ]; then
warn "Unable to download passphrase file ${passphrase}"
fi
if [ -n "${passphrase_enc_pw}" ]; then
echo "Decrypting passphrase file"
mv $pwtempfile ${pwtempfile}.aes
openssl enc -aes-256-cbc -a -salt -d -in ${pwtempfile}.aes -out $pwtempfile -k "${passphrase_enc_pw}"
if [ "$?" -ne "0" ]; then
warn "Unable to decrypt passphrase file ${passphrase}"
fi
rm -f $pwtempfile.aes
fi
fi
for _d in ${devs}; do
echo "Unlocking $_d"
if [ -n "${passphrase}" ]; then
geli attach -k $keytempfile -j $pwtempfile $_d
else
geli attach -k $keytempfile -p $_d
fi
if [ "$?" -ne "0" ]; then
warn "Unable to geli attach $_d"
fi
done
echo "Deleting temporary key file"
rm -fP $keytempfile
echo "Deleting temporary passphrase file"
rm -fP $pwtempfile
echo "Mounting unlocked zfs volumes"
zfs mount -a
done
}
case $# in
1) run_rc_command $@ ${geliunlock_list:-_ALL} ;;
*) run_rc_command $@ ;;
esac