aboutsummaryrefslogtreecommitdiffstats
path: root/hook/ykfde
blob: be75694a0701f15148ee0f3051c64777df044e2f (about) (plain) (blame)
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
#!/bin/sh

run_hook() {
	ykfde_slot="${ykfde_slot:-1}"
	ykfde_count=0

	if [ -s /ykfde-challenge ]; then
		modprobe -a -q usbhid >/dev/null 2>&1

		if [ "${ykfde_twofactor}" = "y" ]; then
			echo -n "Please give two factor key for Yubikey: "
			stty -echo
			read TWOFACTOR
			stty echo
			echo
		else
			TWOFACTOR=""
		fi

		# Any chance to get this more efficient? Without polling and without long sleep times would be great.
		while ! ykchalresp -${ykfde_slot} "${TWOFACTOR}$(cat /ykfde-challenge)" > /crypto_keyfile.bin 2>/dev/null; do
			if [ $((ykfde_count++)) -gt 10 ]; then
				msg ":: No Yubikey presend, fallback to interactive mode"
				rm -f /ykfde-challenge
				return 1
			fi
			sleep 0.3
		done

		msg ":: Created crypto keyfile using Yubikey, handing over to encrypt hook"
		rm -f /ykfde-challenge
	else
		msg ":: No challenge found, falling back to interactive mode"
		return 1
	fi
}