Skip to content

Commit 491272c

Browse files
committed
Config option (compability with encryptssh): Skip passphrase to run next hook
1 parent 680f09c commit 491272c

3 files changed

Lines changed: 57 additions & 22 deletions

File tree

README.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Table of Contents
3333
* [Enable ykfde initramfs hook](#enable-ykfde-initramfs-hook)
3434
* [Enable NFC support in ykfde initramfs hook (experimental)](#enable-nfc-support-in-ykfde-initramfs-hook-experimental)
3535
* [Enable ykfde suspend service (experimental)](#enable-ykfde-suspend-service-experimental)
36+
* [Use ykfde with encryptssh](#use-ykfde-with-encryptssh)
3637
* [License](#license)
3738

3839
# Design
@@ -62,7 +63,7 @@ It will be hashed using the *SHA256* algorithm to achieve constant byte length (
6263

6364
Hashing function:
6465

65-
```
66+
```bash
6667
printf 123456abcdef | sha256sum | awk '{print $1}'
6768
```
6869

@@ -84,20 +85,20 @@ Keep in mind that the above doesn't protect you from physical tampering like *ev
8485

8586
The easiest way is to install package from [official Arch Linux repository](https://www.archlinux.org/packages/community/any/yubikey-full-disk-encryption/).
8687

87-
```
88+
```bash
8889
sudo pacman -Syu yubikey-full-disk-encryption
8990
```
9091

9192
## From Github using 'makepkg'
9293

93-
```
94+
```bash
9495
wget https://raw.githubusercontent.com/agherzan/yubikey-full-disk-encryption/master/PKGBUILD
9596
makepkg -srci
9697
```
9798

9899
## From Github using 'make'
99100

100-
```
101+
```bash
101102
git clone https://github.com/agherzan/yubikey-full-disk-encryption.git
102103
cd yubikey-full-disk-encryption
103104
sudo make install
@@ -112,7 +113,7 @@ When installing by using `make` you also need to install [yubikey-personalizatio
112113

113114
First of all you need to [setup a configuration slot](https://wiki.archlinux.org/index.php/Yubikey#Setup_the_slot) for *YubiKey HMAC-SHA1 Challenge-Response* mode using a command similar to:
114115

115-
```
116+
```bash
116117
ykpersonalize -v -2 -ochal-resp -ochal-hmac -ohmac-lt64 -oserial-api-visible -ochal-btn-trig
117118
```
118119

@@ -136,7 +137,7 @@ You may instead enable *HMAC-SHA1 Challenge-Response* mode using graphical inter
136137

137138
Open the [/etc/ykfde.conf](https://github.com/agherzan/yubikey-full-disk-encryption/blob/master/src/ykfde.conf) file and adjust it for your needs. Alternatively to setting `YKFDE_DISK_UUID` and `YKFDE_LUKS_NAME`, you can use `cryptdevice` kernel parameter. The [syntax](https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Configuring_the_kernel_parameters) is compatible with Arch's `encrypt` hook. After making your changes [regenerate initramfs](https://wiki.archlinux.org/index.php/Mkinitcpio#Image_creation_and_activation):
138139

139-
```
140+
```bash
140141
sudo mkinitcpio -P
141142
```
142143

@@ -148,15 +149,15 @@ You can list existing LUKS key slots with `cryptsetup luksDump /dev/<device>`.
148149

149150
To format new *LUKS* encrypted volume, you can use [ykfde-format](https://github.com/agherzan/yubikey-full-disk-encryption/blob/master/src/ykfde-format) script which is wrapper over `cryptsetup luksFormat` command:
150151

151-
```
152+
```bash
152153
ykfde-format --cipher aes-xts-plain64 --key-size 512 --hash sha512 /dev/<device>
153154
```
154155

155156
## Enroll ykfde passphrase to existing LUKS encrypted volume
156157

157158
To enroll new ykfde passphrase to existing *LUKS* encrypted volume you can use [ykfde-enroll](https://github.com/agherzan/yubikey-full-disk-encryption/blob/master/src/ykfde-enroll) script, see `ykfde-enroll -h` for help:
158159

159-
```
160+
```bash
160161
ykfde-enroll -d /dev/<device> -s <keyslot_number>
161162
```
162163

@@ -166,7 +167,7 @@ ykfde-enroll -d /dev/<device> -s <keyslot_number>
166167

167168
To enroll new ykfde passphrase to existing *LUKS* encrypted volume protected by old ykfde passphrase you can use [ykfde-enroll](https://github.com/agherzan/yubikey-full-disk-encryption/blob/master/src/ykfde-enroll) script, see `ykfde-enroll -h` for help:
168169

169-
```
170+
```bash
170171
ykfde-enroll -d /dev/<device> -s <keyslot_number> -o
171172
```
172173

@@ -176,39 +177,39 @@ To unlock *LUKS* encrypted volume on a running system, you can use [ykfde-open](
176177

177178
As unprivileged user using udisksctl (recommended):
178179

179-
```
180+
```bash
180181
ykfde-open -d /dev/<device>
181182
```
182183

183184
As root using cryptsetup (when [udisks2](https://www.archlinux.org/packages/extra/x86_64/udisks2/) or [expect](https://www.archlinux.org/packages/extra/x86_64/expect/) aren't available):
184185

185-
```
186+
```bash
186187
ykfde-open -d /dev/<device> -n <volume_name>
187188
```
188189

189190
To print only the ykfde passphrase to the console without unlocking any volumes:
190191

191-
```
192+
```bash
192193
ykfde-open -p
193194
```
194195

195196
To test only a passphrase for a specific key slot:
196197

197-
```
198+
```bash
198199
ykfde-open -d /dev/<device> -s <keyslot_number> -t
199200
```
200201

201202
To use optional parameters, example, use an external luks header:
202203

203-
```
204+
```bash
204205
ykfde-open -d /dev/<device> -- --header /mnt/luks-header.img
205206
```
206207

207208
## Kill ykfde passphrase for existing LUKS encrypted volume
208209

209210
To kill a ykfde passphrase for existing *LUKS* encrypted volume you can use [ykfde-enroll](https://github.com/agherzan/yubikey-full-disk-encryption/blob/master/src/ykfde-enroll) script, see `ykfde-enroll -h` for help:
210211

211-
```
212+
```bash
212213
ykfde-enroll -d /dev/<device> -s <keyslot_number> -k
213214
```
214215

@@ -218,7 +219,7 @@ ykfde-enroll -d /dev/<device> -s <keyslot_number> -k
218219

219220
Edit `/etc/mkinitcpio.conf` and add the `ykfde` hook before or instead of `encrypt` hook as provided in [example](https://wiki.archlinux.org/index.php/Dm-crypt/System_configuration#Examples). Adding `ykfde` hook before `encrypt` hook will allow for a safe fallback in case of ykfde misconfiguration. You can remove `encrypt` hook later when you confim that everything is working correctly. After making your changes [regenerate initramfs](https://wiki.archlinux.org/index.php/Mkinitcpio#Image_creation_and_activation):
220221

221-
```
222+
```bash
222223
sudo mkinitcpio -P
223224
```
224225

@@ -230,7 +231,7 @@ Reboot and test your configuration.
230231

231232
NFC support is provided through [libnfc](https://www.archlinux.org/packages/community/x86_64/libnfc/) and [ykchalresp-nfc](https://aur.archlinux.org/packages/ykchalresp-nfc/) tools. Make sure you have both packages installed. Edit `/etc/ykfde.conf` and uncomment `YKFDE_NFC="1"`setting. After making your changes [regenerate initramfs](https://wiki.archlinux.org/index.php/Mkinitcpio#Image_creation_and_activation):
232233

233-
```
234+
```bash
234235
sudo mkinitcpio -P
235236
```
236237

@@ -244,18 +245,32 @@ You can enable the `ykfde-suspend` service which allows for automatically lockin
244245

245246
Edit `/etc/mkinitcpio.conf` and add `shutdown` hook as the last in `HOOKS` array. After making your changes [regenerate initramfs](https://wiki.archlinux.org/index.php/Mkinitcpio#Image_creation_and_activation):
246247

247-
```
248+
```bash
248249
sudo mkinitcpio -P
249250
```
250251

251252
Enable related systemd service:
252253

253-
```
254+
```bash
254255
systemctl enable ykfde-suspend.service
255256
```
256257

257258
Reboot and test your configuration.
258259

260+
## Use ykfde with encryptssh
261+
262+
You can configure ykfde to skip its password-fallback prompt. This allows the boot process to proceed to the next hook in the sequence (e.g., `encryptssh`) after the YubiKey polling loop finishes without a key being presented.
263+
264+
Here's how you do it with encryptssh:
265+
266+
* Follow the installation guide for [encryptssh](https://wiki.archlinux.org/title/Dm-crypt/Specialties#Busybox_based_initramfs_\(built_with_mkinitcpio\))
267+
* Edit `/etc/mkinitcpio.conf` and add `ykfde` **before** `encryptssh` in the `HOOKS` array.
268+
* Edit `/etc/ykfde.conf` and uncomment `YKFDE_SKIP_PASSWORD_PROMPT="1"`.
269+
* Regenerate the initramfs
270+
```bash
271+
sudo mkinitcpio -P
272+
```
273+
259274
# License
260275

261276
Copyright 2017 Andrei Gherzan

src/hooks/ykfde

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ YKFDE_CHALLENGE_SLOT="2"
1515
YKFDE_CHALLENGE=""
1616
YKFDE_CHALLENGE_PASSWORD_NEEDED=""
1717
YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP=""
18+
YKFDE_SKIP_PASSWORD_PROMPT=""
1819
YKFDE_USE_PLYMOUTH=""
1920

2021
message() {
@@ -82,13 +83,18 @@ EOF
8283
_tmp="$(modprobe -a -q dm-crypt >/dev/null 2>&1)"
8384

8485
local trial_nr
86+
local _rc
8587
trial_nr=1
8688
while [ "$trial_nr" -le "$YKFDE_CRYPTSETUP_TRIALS" ]; do
8789
message "Attempt #$trial_nr/$YKFDE_CRYPTSETUP_TRIALS: cryptsetup of $YKFDE_LUKS_DEV"
88-
ykfde_do_it && return 0
90+
ykfde_do_it
91+
_rc=$?
92+
[ "$_rc" -eq 0 ] && return 0
8993
trial_nr=$((trial_nr + 1))
9094
done
9195

96+
[ "$_rc" -eq 20 ] && return 0
97+
9298
# if we get here, we did NOT succeed:
9399
ykfde_err 000 "$0 Failed!"
94100
return 1
@@ -120,12 +126,20 @@ ykfde_do_it() {
120126

121127
if [ -z "$_ykfde_passphrase" ]; then
122128
if [ "$YKFDE_CHALLENGE" ] || [ "$YKFDE_CHALLENGE_PASSWORD_NEEDED" ]; then
123-
message " > Challenge-Response failed. Falling back to manual passphrase."
124-
[ "$trial_nr" -le "$YKFDE_CRYPTSETUP_TRIALS" ] && message " Press ENTER to skip and retry Challenge-Response."
129+
message " > Challenge-Response failed."
130+
if [ -z "$YKFDE_SKIP_PASSWORD_PROMPT" ]; then
131+
message " Falling back to manual passphrase."
132+
[ "$trial_nr" -le "$YKFDE_CRYPTSETUP_TRIALS" ] && message " Press ENTER to skip and retry Challenge-Response."
133+
fi
125134
else
126135
message " > Passphrase needed to unlock device."
127136
fi
128137

138+
if [ "$YKFDE_CHALLENGE" ] && [ "$YKFDE_SKIP_PASSWORD_PROMPT" ]; then
139+
[ "$DBG" ] && message " > Skipping password promp; running the next module..."
140+
return 20
141+
fi
142+
129143
printf " Enter passphrase: "
130144
if [ "$YKFDE_USE_PLYMOUTH" ]; then
131145
_ykfde_passphrase="$(plymouth ask-for-password --prompt="Enter passphrase" --dont-pause-progress)"

src/ykfde.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
# Defaults to empty, meaning NO wait.
4949
#YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP=""
5050

51+
# WARNING: DO NOT ENABLE THIS OPTION WHEN YOU DO NOT USE encryptssh OR YOU DON'T KNOW WHAT YOU ARE DOING!
52+
# After timeout (by not presenting a YubiKey) the password prompt by ykfde will be skipped. Instead the next module will be run.
53+
# Works well with encryptssh and any other hook which will decrypt your filesystem.
54+
# In /etc/mkinitcpio.conf make sure that in your hooks you have the following order: HOOKS=(... block netconf tinyssh ykfde encryptssh filesystems fsck)
55+
#YKFDE_SKIP_PASSWORD_PROMPT="1"
56+
5157
# Verbose output. It will print all secrets to terminal.
5258
# Use only for debugging.
5359
#DBG="1"

0 commit comments

Comments
 (0)