Skip to content

Commit a12f931

Browse files
committed
Add support for yubikey-manager
Because yubikey-personalization is not under active development, I add support for yubikey-manager. It works fine on my machine for format, enroll and open. I did not test NFC because I do not have NFC machine. For hooks, I added ykman and od, it should work. README should be modified if this commit is approved.
1 parent dcaac00 commit a12f931

File tree

6 files changed

+73
-29
lines changed

6 files changed

+73
-29
lines changed

src/hooks/ykfde

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ YKFDE_CHALLENGE=""
1616
YKFDE_CHALLENGE_PASSWORD_NEEDED=""
1717
YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP=""
1818
YKFDE_USE_PLYMOUTH=""
19+
export CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1
1920

2021
message() {
2122
if [ "$YKFDE_USE_PLYMOUTH" ]; then
@@ -192,8 +193,8 @@ ykfde_challenge_response() {
192193
while [ -z "$_yubikey_detected" ] && [ -z "$_yubikey_nfc_detected" ]; do
193194
_endtime="$(date +%s)"
194195
_usedtime=$((_endtime - _starttime))
195-
[ "$DBG" ] && message " (used time:$_usedtime, timeout:$_yubikey_timeout) 'ykinfo -$YKFDE_CHALLENGE_SLOT': "
196-
_tmp="$(ykinfo -"$YKFDE_CHALLENGE_SLOT" 2>&1)"
196+
[ "$DBG" ] && message " (used time:$_usedtime, timeout:$_yubikey_timeout) 'ykman otp info': "
197+
_tmp="$(ykman otp info | grep -q "$YKFDE_CHALLENGE_SLOT: programmed" 2>&1)"
197198
_rc=$?
198199
[ "$DBG" ] && message "[$_rc] '$_tmp'"
199200
if [ "$_rc" -eq 0 ]; then
@@ -232,9 +233,10 @@ ykfde_challenge_response() {
232233

233234
if [ "$_yubikey_detected" ]; then
234235
while [ -z "$_ykfde_response" ]; do
235-
[ "$DBG" ] && message " Running: 'ykchalresp -$YKFDE_CHALLENGE_SLOT $YKFDE_CHALLENGE'..."
236+
YKFDE_REAL_CHALLENGE="$(printf '%s' "$YKFDE_CHALLENGE" | od --endian=big -t x1 -An | tr -d ' ,\n')"
237+
[ "$DBG" ] && message " Running: 'ykman otp calculate $YKFDE_CHALLENGE_SLOT $YKFDE_REAL_CHALLENGE'..."
236238
message " Remember to touch the device if necessary."
237-
_ykfde_response="$(printf %s "$YKFDE_CHALLENGE" | ykchalresp -"$YKFDE_CHALLENGE_SLOT" -i- | tr -d '\n')"
239+
_ykfde_response="$(printf '%s' "$YKFDE_REAL_CHALLENGE" | ykman otp calculate "$YKFDE_CHALLENGE_SLOT" -- | tr -d '\n')"
238240
[ "$DBG" ] && message " Received response: '$_ykfde_response'"
239241
done
240242
fi

src/install/ykfde

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ build() {
2222
add_all_modules "/crypto/"
2323
fi
2424

25+
base_files=$(pacman -Ql python | awk '{print $2}' | /bin/grep -E '.py$|.so$')
26+
for file in $base_files
27+
do
28+
add_file $file
29+
done
30+
31+
python_ver=$(python -V | awk -F'[" ",.]' '{print $2"."$3}')
32+
add_full_dir "/usr/lib/python${python_ver}/site-packages/zipp"
33+
add_full_dir "/usr/lib/python${python_ver}/site-packages/cryptography"
34+
add_full_dir "/usr/lib/python${python_ver}/site-packages/cffi"
35+
add_full_dir "/usr/lib/python${python_ver}/site-packages/smartcard"
36+
add_full_dir "/usr/lib/python${python_ver}/site-packages/fido2"
37+
add_full_dir "/usr/lib/python${python_ver}/site-packages/importlib_metadata"
38+
add_full_dir "/usr/lib/python${python_ver}/site-packages/ykman"
39+
add_full_dir "/usr/lib/python${python_ver}/site-packages/yubikit"
40+
add_full_dir "/usr/lib/python${python_ver}/site-packages/click"
41+
add_full_dir "/usr/lib/python${python_ver}/site-packages/keyring"
42+
add_binary "/usr/lib/python${python_ver}/site-packages/_cffi_backend.cpython-311-x86_64-linux-gnu.so"
43+
2544
add_binary "cryptsetup"
2645
add_binary "dmsetup"
2746
add_file "/usr/lib/udev/rules.d/10-dm.rules"
@@ -31,10 +50,12 @@ build() {
3150

3251
# cryptsetup calls pthread_create(), which dlopen()s libgcc_s.so.1
3352
add_binary "/usr/lib/libgcc_s.so.1"
34-
53+
add_binary "/usr/lib/libssl.so.3"
54+
add_binary "/usr/lib/libpcsclite.so.1"
55+
add_binary "python"
56+
add_binary "ykman"
57+
add_binary "od"
3558
add_binary "tr"
36-
add_binary "ykchalresp"
37-
add_binary "ykinfo"
3859
add_binary "date"
3960
add_binary "sleep"
4061
add_binary "printf"

src/ykfde-enroll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ while getopts ":d:s:ckovh" opt; do
8484
esac
8585
done
8686

87-
YKFDE_SLOT_CHECK="$(ykinfo -q -"$YKFDE_CHALLENGE_SLOT")"
88-
[ "$DBG" ] && printf '%s\n' " > YubiKey slot status 'ykinfo -q -$YKFDE_CHALLENGE_SLOT': $YKFDE_SLOT_CHECK"
87+
YKFDE_SLOT_CHECK="$(ykman otp info | grep "$YKFDE_CHALLENGE_SLOT" | awk '{print $3}')"
88+
[ "$DBG" ] && printf '%s\n' " > YubiKey slot status 'ykman otp info': slot $YKFDE_CHALLENGE_SLOT: $YKFDE_SLOT_CHECK"
8989

90-
if [ "$YKFDE_SLOT_CHECK" != 1 ]; then
90+
if [ "$YKFDE_SLOT_CHECK" != "programmed" ]; then
9191
printf '%s\n' "ERROR: Chosen YubiKey slot '$YKFDE_CHALLENGE_SLOT' isn't configured. Please choose slot configured for 'HMAC-SHA1 Challenge-Response' mode in '/etc/ykfde.conf'"
9292
exit 1
9393
fi
@@ -144,9 +144,10 @@ if [ -z "$YKFDE_CHALLENGE" ]; then
144144
fi
145145

146146
while [ -z "$YKFDE_RESPONSE" ]; do
147-
[ "$DBG" ] && printf '%s\n' " Running: 'ykchalresp -$YKFDE_CHALLENGE_SLOT $YKFDE_CHALLENGE'..."
147+
YKFDE_REAL_CHALLENGE="$(printf '%s' "$YKFDE_CHALLENGE" | od --endian=big -t x1 -An | tr -d ' ,\n')"
148+
[ "$DBG" ] && printf '%s\n' " Running: 'ykman otp calculate $YKFDE_CHALLENGE_SLOT $YKFDE_REAL_CHALLENGE'..."
148149
echo " Remember to touch the device if necessary."
149-
YKFDE_RESPONSE="$(printf %s "$YKFDE_CHALLENGE" | ykchalresp -"$YKFDE_CHALLENGE_SLOT" -i- | tr -d '\n')" || true
150+
YKFDE_RESPONSE="$(printf '%s' "$YKFDE_REAL_CHALLENGE" | ykman otp calculate "$YKFDE_CHALLENGE_SLOT" -- | tr -d '\n')" || true
150151
[ "$DBG" ] && printf '%s\n' " Received response: '$YKFDE_RESPONSE'"
151152
done
152153

@@ -190,9 +191,10 @@ if [ "$YKFDE_OLD_YUBIKEY" ]; then
190191
fi
191192

192193
while [ -z "$YKFDE_OLD_RESPONSE" ]; do
193-
[ "$DBG" ] && printf '%s\n' " Running: 'ykchalresp -$YKFDE_CHALLENGE_SLOT $YKFDE_OLD_CHALLENGE'..."
194+
YKFDE_REAL_OLD_CHALLENGE=$(printf '%s' "$YKFDE_OLD_CHALLENGE" | od --endian=big -t x1 -An | tr -d ' ,\n')
195+
[ "$DBG" ] && printf '%s\n' " Running: 'ykman otp calculate $YKFDE_CHALLENGE_SLOT $YKFDE_REAL_OLD_CHALLENGE'..."
194196
echo " Remember to touch the old device if necessary."
195-
YKFDE_OLD_RESPONSE="$(printf %s "$YKFDE_OLD_CHALLENGE" | ykchalresp -"$YKFDE_CHALLENGE_SLOT" -i- | tr -d '\n')" || true
197+
YKFDE_OLD_RESPONSE="$(printf '%s' "$YKFDE_REAL_OLD_CHALLENGE" | ykman otp calculate "$YKFDE_CHALLENGE_SLOT" -- | tr -d '\n')" || true
196198
[ "$DBG" ] && printf '%s\n' " Received response: '$YKFDE_OLD_RESPONSE'"
197199
done
198200

src/ykfde-format

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ else
1919
echo "WARNING: Can't access /etc/ykfde.conf. Falling back to defaults."
2020
fi
2121

22-
YKFDE_SLOT_CHECK="$(ykinfo -q -"$YKFDE_CHALLENGE_SLOT")"
23-
[ "${DBG:-}" ] && printf '%s\n' " > YubiKey slot status 'ykinfo -q -$YKFDE_CHALLENGE_SLOT': $YKFDE_SLOT_CHECK"
22+
YKFDE_SLOT_CHECK="$(ykman otp info | grep "$YKFDE_CHALLENGE_SLOT" | awk '{print $3}')"
23+
[ "${DBG:-}" ] && printf '%s\n' " > YubiKey slot status 'ykman otp info': slot $YKFDE_CHALLENGE_SLOT: $YKFDE_SLOT_CHECK"
2424

25-
if [ "$YKFDE_SLOT_CHECK" != 1 ]; then
25+
if [ "$YKFDE_SLOT_CHECK" != "programmed" ]; then
2626
printf '%s\n' "ERROR: Chosen YubiKey slot '$YKFDE_CHALLENGE_SLOT' isn't configured. Please choose slot configured for 'HMAC-SHA1 Challenge-Response' mode in '/etc/ykfde.conf'"
2727
exit 1
2828
fi
@@ -54,9 +54,10 @@ if [ -z "$YKFDE_CHALLENGE" ]; then
5454
fi
5555

5656
while [ -z "$YKFDE_RESPONSE" ]; do
57-
[ "${DBG:-}" ] && printf '%s\n' " Running: 'ykchalresp -$YKFDE_CHALLENGE_SLOT $YKFDE_CHALLENGE'..."
57+
YKFDE_REAL_CHALLENGE="$(printf '%s' "$YKFDE_CHALLENGE" | od --endian=big -t x1 -An | tr -d ' ,\n')"
58+
[ "${DBG:-}" ] && printf '%s\n' " Running: 'ykman otp calculate $YKFDE_CHALLENGE_SLOT $YKFDE_REAL_CHALLENGE'..."
5859
echo " Remember to touch the device if necessary."
59-
YKFDE_RESPONSE="$(printf %s "$YKFDE_CHALLENGE" | ykchalresp -"$YKFDE_CHALLENGE_SLOT" -i- | tr -d '\n')" || true
60+
YKFDE_RESPONSE="$(printf '%s' "$YKFDE_REAL_CHALLENGE" | ykman otp calculate "$YKFDE_CHALLENGE_SLOT" -- | tr -d '\n')" || true
6061
[ "${DBG:-}" ] && printf '%s\n' " Received response: '$YKFDE_RESPONSE'"
6162
done
6263

src/ykfde-open

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ done
9393

9494
shift "$((OPTIND - 1))"
9595

96-
YKFDE_SLOT_CHECK="$(ykinfo -q -"$YKFDE_CHALLENGE_SLOT")"
97-
[ "$DBG" ] && printf '%s\n' " > YubiKey slot status 'ykinfo -q -$YKFDE_CHALLENGE_SLOT': $YKFDE_SLOT_CHECK"
96+
YKFDE_SLOT_CHECK="$(ykman otp info | grep "$YKFDE_CHALLENGE_SLOT" | awk '{print $3}')"
97+
[ "$DBG" ] && printf '%s\n' " > YubiKey slot status 'ykman otp info': slot $YKFDE_CHALLENGE_SLOT: $YKFDE_SLOT_CHECK"
9898

99-
if [ "$YKFDE_SLOT_CHECK" != 1 ]; then
99+
if [ "$YKFDE_SLOT_CHECK" != "programmed" ]; then
100100
printf '%s\n' "ERROR: Chosen YubiKey slot '$YKFDE_CHALLENGE_SLOT' isn't configured. Please choose slot configured for 'HMAC-SHA1 Challenge-Response' mode in '/etc/ykfde.conf'"
101101
exit 1
102102
fi
@@ -140,9 +140,10 @@ while [ -z "$YKFDE_CHALLENGE" ]; do
140140
done
141141

142142
while [ -z "$YKFDE_RESPONSE" ]; do
143-
[ "$DBG" ] && printf '%s\n' " Running: 'ykchalresp -$YKFDE_CHALLENGE_SLOT $YKFDE_CHALLENGE'..."
143+
YKFDE_REAL_CHALLENGE="$(printf '%s' "$YKFDE_CHALLENGE" | od --endian=big -t x1 -An | tr -d ' ,\n')"
144+
[ "$DBG" ] && printf '%s\n' " Running: 'ykman otp calculate $YKFDE_CHALLENGE_SLOT $YKFDE_REAL_CHALLENGE'..."
144145
echo " Remember to touch the device if necessary."
145-
YKFDE_RESPONSE="$(printf %s "$YKFDE_CHALLENGE" | ykchalresp -"$YKFDE_CHALLENGE_SLOT" -i- | tr -d '\n')" || true
146+
YKFDE_RESPONSE="$(printf '%s' "$YKFDE_REAL_CHALLENGE" | ykman otp calculate "$YKFDE_CHALLENGE_SLOT" -- | tr -d '\n')" || true
146147
[ "$DBG" ] && printf '%s\n' " Received response: '$YKFDE_RESPONSE'"
147148
done
148149

testrun.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,41 @@ truncate -s 20M "$YKFDE_TMPFILE"
3737

3838
cleanup() {
3939
rm -f "$YKFDE_TMPFILE"
40+
rm -rf initramfs
4041
}
4142
trap cleanup EXIT
4243

4344
echo "INFO: Testing 'ykfde-format' script."
44-
DBG=1 ykfde-format "$YKFDE_TMPFILE"
45+
DBG=1 bash "$(pwd)/src/ykfde-format" "$YKFDE_TMPFILE"
4546
echo "Test 'ykfde-format' script successfully passed."
4647

4748
echo "INFO: Testing 'ykfde-enroll' script."
4849
printf '%s\n' "test" | cryptsetup luksFormat "$YKFDE_TMPFILE"
4950
echo "INFO: Old LUKS passphrase is 'test'."
50-
ykfde-enroll -d "$YKFDE_TMPFILE" -s 7 -v
51+
bash "$(pwd)/src/ykfde-enroll" -d "$YKFDE_TMPFILE" -s 7 -v
5152
echo "Test 'ykfde-enroll' script successfully passed."
5253

5354
echo "INFO: Testing 'ykfde-open' script."
54-
ykfde-open -d "$YKFDE_TMPFILE" -n ykfde-test -v
55+
bash "$(pwd)/src/ykfde-open" -d "$YKFDE_TMPFILE" -n ykfde-test -v
5556
cryptsetup close ykfde-test
5657
echo "Test 'ykfde-open' script successfully passed."
5758

58-
echo "All tests successfully passed."
59-
59+
echo "INFO: Testing initramfs..."
60+
mkdir -p "$(pwd)/initramfs"
61+
mkinitcpio -d "$(pwd)/initramfs"
62+
status=1
63+
status=$(chroot "$(pwd)/initramfs" /bin/sh -c "export CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1; ykman otp info; exit 0" 2>&1 | awk '
64+
{
65+
if ($0 ~ /No YubiKey detected/) {
66+
print "0";
67+
exit 0;
68+
}
69+
}'
70+
)
71+
if [[ "$status" == 0 ]]
72+
then
73+
echo "All tests successfully passed."
74+
else
75+
echo "The image didnot pass the test, please file a bug report to: https://github.com/agherzan/yubikey-full-disk-encryption/issues"
76+
fi
6077
exit 0

0 commit comments

Comments
 (0)