Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix branding issue with HOTP USB Security Dongles #761

Merged
merged 21 commits into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0e349c5
Update hotp-verification
alex-nitrokey Jun 9, 2020
1ba73ac
Rename CONFIG_LIBREMKEY to CONFIG_HOTPKEY
alex-nitrokey Jun 11, 2020
3424317
Quick fix to build
alex-nitrokey Jun 11, 2020
fc8c7b0
Merge branch 'hotp-verification-update' into hotp-neutral
alex-nitrokey Jun 11, 2020
4069619
Rename libremkey-hotp-verification module
alex-nitrokey Jun 11, 2020
28735a8
Add CONFIG_HOTP_BRANDING
alex-nitrokey Jun 11, 2020
53b67d2
Prepare usage of /boot/kexec_hotp_key as branding
alex-nitrokey Jun 24, 2020
407778e
Remove unintented paranthesis
alex-nitrokey Jun 24, 2020
38ba257
Include upstream updates of hotp_verification
alex-nitrokey Jun 24, 2020
aab2c32
Fix warning box title
alex-nitrokey Jun 24, 2020
92b1826
/boot needs to get mounted first
alex-nitrokey Jun 24, 2020
5867fc5
Store HOTP USB Security Key branding in /boot
alex-nitrokey Jun 24, 2020
3236f0e
Change name seal-libremkey -> seal-hotpkey
alex-nitrokey Jun 24, 2020
2fe946c
Fix termonology
alex-nitrokey Jun 24, 2020
fecb9cf
Rename CONFIG_HOTP_BRANDING to HOTP_BRANDING
alex-nitrokey Jun 24, 2020
73c9d6e
Merge branch 'hotp-verification-update' into hotp-neutral-merge
alex-nitrokey Jun 24, 2020
c2a2134
Merge remote-tracking branch 'upstream/master' into hotp-neutral
alex-nitrokey Jun 24, 2020
53dc659
Replace libremkey_htop_* by hotp_*
alex-nitrokey Jun 25, 2020
d3d4529
GitlabCI: reset cache, and investigate
szszszsz Jun 30, 2020
9c9edb0
Remove pkg-config and git version use
szszszsz Jun 30, 2020
d472c43
Fix quoting of variable
techge Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitlab-ci.yml
Expand Up @@ -8,13 +8,13 @@ stages:

build:
stage: build
retry: 2
retry: 1
cache:
paths:
- packages
- crossgcc
- build
key: "heads-$GITLAB_USER_LOGIN"
key: "heads-$GITLAB_USER_LOGIN-2"
script:
- dnf install -y @development-tools gcc-c++ gcc-gnat zlib-devel perl-Digest-MD5 perl-Digest-SHA uuid-devel pcsc-tools ncurses-devel lbzip2 libuuid-devel lzma elfutils-libelf-devel bc bzip2 bison flex git gnupg iasl m4 nasm patch python wget libusb-devel cmake automake pv bsdiff autoconf libtool cpio texinfo
- git fetch origin
Expand Down Expand Up @@ -75,6 +75,8 @@ build:
- cat ./build/qemu-coreboot/hashes.txt
- echo "Archiving qemu-coreboot logs..."
- tar zcvf ./build/qemu-coreboot/logs.tar.gz ./build/log/*
- echo "Calculate used space for cache"
- du -shc packages crossgcc build
artifacts:
paths:
- ./build/qemu-coreboot
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -428,7 +428,7 @@ bin_modules-$(CONFIG_FLASHTOOLS) += flashtools
bin_modules-$(CONFIG_NEWT) += newt
bin_modules-$(CONFIG_CAIRO) += cairo
bin_modules-$(CONFIG_FBWHIPTAIL) += fbwhiptail
bin_modules-$(CONFIG_LIBREMKEY) += libremkey-hotp-verification
bin_modules-$(CONFIG_HOTPKEY) += hotp-verification
bin_modules-$(CONFIG_MSRTOOLS) += msrtools

$(foreach m, $(bin_modules-y), \
Expand Down
2 changes: 1 addition & 1 deletion boards/librem13v2/librem13v2.config
Expand Up @@ -20,7 +20,7 @@ CONFIG_TPMTOTP=y
#CONFIG_NEWT=y
CONFIG_CAIRO=y
CONFIG_FBWHIPTAIL=y
CONFIG_LIBREMKEY=y
CONFIG_HOTPKEY=y

CONFIG_LINUX_USB=y

Expand Down
2 changes: 1 addition & 1 deletion boards/librem13v4/librem13v4.config
Expand Up @@ -20,7 +20,7 @@ CONFIG_TPMTOTP=y
#CONFIG_NEWT=y
CONFIG_CAIRO=y
CONFIG_FBWHIPTAIL=y
CONFIG_LIBREMKEY=y
CONFIG_HOTPKEY=y

CONFIG_LINUX_USB=y

Expand Down
2 changes: 1 addition & 1 deletion boards/librem15v3/librem15v3.config
Expand Up @@ -22,7 +22,7 @@ CONFIG_TPMTOTP=y
#CONFIG_NEWT=y
CONFIG_CAIRO=y
CONFIG_FBWHIPTAIL=y
CONFIG_LIBREMKEY=y
CONFIG_HOTPKEY=y

CONFIG_LINUX_USB=y

Expand Down
2 changes: 1 addition & 1 deletion boards/librem15v4/librem15v4.config
Expand Up @@ -22,7 +22,7 @@ CONFIG_TPMTOTP=y
#CONFIG_NEWT=y
CONFIG_CAIRO=y
CONFIG_FBWHIPTAIL=y
CONFIG_LIBREMKEY=y
CONFIG_HOTPKEY=y

CONFIG_LINUX_USB=y

Expand Down
Expand Up @@ -22,7 +22,7 @@ CONFIG_DROPBEAR=y
#CONFIG_NEWT=y
CONFIG_CAIRO=y
CONFIG_FBWHIPTAIL=y
CONFIG_LIBREMKEY=y
CONFIG_HOTPKEY=y

CONFIG_LINUX_USB=y
CONFIG_LINUX_E1000E=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-hotp-verification.config
Expand Up @@ -2,7 +2,7 @@ CONFIG_LOCALVERSION="heads"
CONFIG_ANY_TOOLCHAIN=y
CONFIG_MEASURED_BOOT=y
CONFIG_VENDOR_LENOVO=y
CONFIG_CBFS_SIZE=0x800000
CONFIG_CBFS_SIZE=0x710000
CONFIG_BOARD_LENOVO_X230=y
CONFIG_NO_POST=y
CONFIG_UART_PCI_ADDR=0
Expand Down
27 changes: 18 additions & 9 deletions initrd/bin/gui-init
Expand Up @@ -92,10 +92,10 @@ update_totp()
{
echo "Scan the QR code to add the new TOTP secret"
/bin/seal-totp
if [ -x /bin/libremkey_hotp_verification ]; then
echo "Once you have scanned the QR code, hit Enter to configure your Librem Key"
if [ -x /bin/hotp_verification ]; then
echo "Once you have scanned the QR code, hit Enter to configure your HOTP USB Security Dongle (e.g. Librem Key or Nitrokey)"
read
/bin/seal-libremkey
/bin/seal-hotpkey
else
echo "Once you have scanned the QR code, hit Enter to continue"
read
Expand All @@ -118,7 +118,7 @@ clean_boot_check()
[ $GPG_KEY_COUNT -ne 0 ] && return

# check for USB security token
if [ "$CONFIG_LIBREMKEY" = "y" ]; then
if [ "$CONFIG_HOTPKEY" = "y" ]; then
enable_usb
if ! gpg --card-status > /dev/null ; then
return
Expand All @@ -140,6 +140,13 @@ else
mount_boot
fi

# Use stored HOTP key branding
if [ -r /boot/kexec_hotp_key ]; then
HOTPKEY_BRANDING="$(cat /boot/kexec_hotp_key)"
else
HOTPKEY_BRANDING="HOTP USB Security Dongle"
fi

last_half=X
while true; do
MAIN_MENU_OPTIONS=""
Expand Down Expand Up @@ -188,14 +195,16 @@ while true; do
fi

if [ "$totp_confirm" = "i" -o -z "$totp_confirm" ]; then
if [ -x /bin/libremkey_hotp_verification ]; then
if [ -x /bin/hotp_verification ]; then
HOTP=`unseal-hotp`
enable_usb
if ! libremkey_hotp_verification info ; then
whiptail $CONFIG_WARNING_BG_COLOR --clear --title 'WARNING: Please Insert Your Librem Key' --msgbox "Your Librem Key was not detected.\n\nPlease insert your Librem Key" 30 90
if ! hotp_verification info ; then
whiptail $CONFIG_WARNING_BG_COLOR --clear \
--title "WARNING: Please Insert Your $HOTPKEY_BRANDING" \
--msgbox "Your $HOTPKEY_BRANDING was not detected.\n\nPlease insert your $HOTPKEY_BRANDING" 30 90
fi
# Don't output HOTP codes to screen, so as to make replay attacks harder
libremkey_hotp_verification check $HOTP
hotp_verification check $HOTP
case "$?" in
0 )
HOTP="Success"
Expand All @@ -205,7 +214,7 @@ while true; do
MAIN_MENU_BG_COLOR=$CONFIG_ERROR_BG_COLOR
;;
* )
HOTP="Error checking code, Insert Librem Key and retry"
HOTP="Error checking code, Insert $HOTPKEY_BRANDING and retry"
MAIN_MENU_BG_COLOR=$CONFIG_WARNING_BG_COLOR
;;
esac
Expand Down
6 changes: 3 additions & 3 deletions initrd/bin/kexec-seal-key
Expand Up @@ -84,9 +84,9 @@ cat "$KEY_DEVICES" | cut -d\ -f1 | xargs /bin/qubes-measure-luks \
|| die "Unable to measure the LUKS headers"
luks_pcr=`tpm calcfuturepcr -ix 16 -if /tmp/luksDump.txt`

# Librem Key loads USB modules which changes PCR5.
# In the event Librem Key is enabled, skip verification of PCR5
if [ -x /bin/libremkey_hotp_verification ]; then
# HOTP USB Secrity Dongle loads USB modules which changes PCR5.
# In the event HOTP USB Security Dongle is enabled, skip verification of PCR5
if [ -x /bin/hotp_verification ]; then
pcr_5="X"
else
pcr_5="0000000000000000000000000000000000000000"
Expand Down
39 changes: 30 additions & 9 deletions initrd/bin/seal-libremkey → initrd/bin/seal-hotpkey
@@ -1,11 +1,12 @@
#!/bin/sh
# Retrieve the sealed TOTP secret and initialize a Librem Key with it
# Retrieve the sealed TOTP secret and initialize a USB Security dongle with it

. /etc/functions

HOTP_SEALED="/tmp/secret/hotp.sealed"
HOTP_SECRET="/tmp/secret/hotp.key"
HOTP_COUNTER="/boot/kexec_hotp_counter"
HOTP_KEY="/boot/kexec_hotp_key"

mount_boot()
{
Expand All @@ -16,6 +17,13 @@ mount_boot()
fi
}

# Use stored HOTP key branding (this might be useful after OEM reset)
if [ -r /boot/kexec_hotp_key ]; then
HOTPKEY_BRANDING="$(cat /boot/kexec_hotp_key)"
else
HOTPKEY_BRANDING="HOTP USB Security Dongle"
fi

tpm nv_readvalue \
-in 4d47 \
-sz 312 \
Expand Down Expand Up @@ -49,26 +57,35 @@ mount_boot
counter_value=1

enable_usb
if ! libremkey_hotp_verification info ; then
echo "Insert your Librem Key and press Enter to configure it"
if ! hotp_verification info ; then
echo "Insert your $HOTPKEY_BRANDING and press Enter to configure it"
read
if ! libremkey_hotp_verification info ; then
if ! hotp_verification info ; then
# don't leak key on failure
shred -n 10 -z -u "$HOTP_SECRET" 2> /dev/null
die "Unable to find Librem Key"
die "Unable to find $HOTPKEY_BRANDING"
fi
fi

# Set HOTP USB Security Dongle branding based on VID
if [ ! $(lsusb | grep -q "20a0:") ]; then
HOTPKEY_BRANDING="Nitrokey"
elif [ ! $(lsusb | grep -q "316d:") ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why, but this ends up showing my Librem Key as a Nitrokey.
using:
elif lsusb | grep -q "316d:" ; then
works correctly however

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The negation is used because grep returns 0 if it found something.

Older Librem Keys had the same VID as the Nitrokeys because of a mistake done when building the firmware for it, see #761 (comment)

I could not think of a way to prevent that :(

So I am wondering, what is the return value of lsusb | grep -q "316d:" for you? If it is 0 the patch should work as intended. Does it?

Copy link
Contributor

@szszszsz szszszsz Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words first batches of the Librem Key had incorrectly set VID:PID to the same as Nitrokey Pro has, hence the confusion.
Perhaps they have changed the USB names only back then (might not show up in the lsusb, but maybe dmesg) - that would already help to differentiate between models, otherwise I do not see how to make it possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I am wondering, what is the return value of lsusb | grep -q "316d:" for you? If it is 0 the patch should work as intended. Does it?

0, and no the patch does not work correctly with my LK. It identifies as a NK without the change I mentioned above

edit: this LK is one of our new US-built ones with VID/DID 316d:4c4b. Another older one is 20a0:4108 and so identifies as a Nitrokey

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed #781 to fix

HOTPKEY_BRANDING="Librem Key"
else
HOTPKEY_BRANDING="HOTP USB Security Dongle"
fi

echo -e ""
read -s -p "Enter your Librem Key Admin PIN: " admin_pin
read -s -p "Enter your $HOTPKEY_BRANDING Admin PIN: " admin_pin
echo -e "\n"

libremkey_hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value
hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING"
if [ $? -ne 0 ]; then
echo -e "\n"
read -s -p "Error setting HOTP secret, re-enter Admin PIN and try again: " admin_pin
echo -e "\n"
if ! libremkey_hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value ; then
if ! hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING" ; then
# don't leak key on failure
shred -n 10 -z -u "$HOTP_SECRET" 2> /dev/null
die "Setting HOTP secret failed"
Expand All @@ -90,11 +107,15 @@ counter_value=`expr $counter_value + 1`
echo $counter_value > $HOTP_COUNTER \
|| die "Unable to create hotp counter file"

# Store/overwrite HOTP USB Security Dongle branding found out beforehand
echo $HOTPKEY_BRANDING > $HOTP_KEY \
|| die "Unable to store hotp key file"

#sha256sum /tmp/counter-$counter > $HOTP_COUNTER \
#|| die "Unable to create hotp counter file"
mount -o remount,ro /boot

echo -e "\nLibrem Key initialized successfully. Press Enter to continue."
echo -e "\n$HOTPKEY_BRANDING initialized successfully. Press Enter to continue."
read

exit 0
2 changes: 1 addition & 1 deletion modules/hidapi
@@ -1,2 +1,2 @@
# empty placeholder file
# This submodule is defined in modules/libremkey-hotp-verification
# This submodule is defined in modules/hotp-verification
37 changes: 37 additions & 0 deletions modules/hotp-verification
@@ -0,0 +1,37 @@
modules-$(CONFIG_HOTPKEY) += hotp-verification

hotp-verification_depends := libusb $(musl_dep)

hotp-verification_version := 5fb260e631b237a298b6dcca47bbd728f2c5ac3a
hotp-verification_dir := hotp-verification-$(hotp-verification_version)
hotp-verification_tar := nitrokey-hotp-verification-$(hotp-verification_version).tar.gz
hotp-verification_url := https://github.com/Nitrokey/nitrokey-hotp-verification/archive/$(hotp-verification_version).tar.gz
hotp-verification_hash := 5d98d158ba97fb970061d68e2c6f41582395e687b7752efb1a8038762b0e7b79

hotp-verification_target := \
$(MAKE_JOBS) \
$(CROSS_TOOLS) \

hotp-verification_output := \
hotp_verification \
hotp_initialize

hotp-verification_configure := \
INSTALL="$(INSTALL)" \
CROSS="$(CROSS)" \
$(CROSS_TOOLS) $(MAKE) LDFLAGS="$(INSTALL)/lib/libusb-1.0.so" GITVERSION="" LIBUSB_FLAGS="-I/usr/include/libusb-1.0" PKGCONFIG="" && $(MAKE) install INSTALL="$(INSTALL)"

hotp-verification_depends += hidapi
modules-y += hidapi

hidapi_version := e5ae0d30a523c565595bdfba3d5f2e9e1faf0bd0
hidapi_dir := hotp-verification-$(hotp-verification_version)/hidapi
hidapi_tar := hidapi-$(hidapi_version).tar.xz
hidapi_url := https://github.com/Nitrokey/hidapi/archive/$(hidapi_version).tar.gz
hidapi_hash := acc2a5089a8917085c2b3ebe9446065a21c760ba7e13cb54917043c4122188e0


## hidapi will be built as part of hotp-verification
## so nothing to do here (but need make to be happy)
hidapi_output := .built
hidapi_configure := echo -e 'all:\n\ttouch .built' > Makefile
37 changes: 0 additions & 37 deletions modules/libremkey-hotp-verification

This file was deleted.