mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-20 21:43:11 +00:00
286303d95c
Reading the file into a variable and then redirecting to stdin via echo() can cause the binary data to be truncated, leading to an invalid base32 value and failure to properly generate and validate the HOTP code. To resolve this, pass the file directly to hotp(), and ensure it is removed properly regardless of success or failure to prevent leakage. Fixes "Invalid base32 string" error seen when attempting to generate a new TOTP secret. Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
--- nitrokey-hotp-verification-a/Toolchain-heads.cmake 2018-05-22 09:55:46.907209235 -0700
|
|
+++ nitrokey-hotp-verification-b/Toolchain-heads.cmake 2018-05-22 09:55:26.659371966 -0700
|
|
@@ -0,0 +1,18 @@
|
|
+SET(CMAKE_SYSTEM_NAME Linux)
|
|
+SET(CMAKE_SYSTEM_VERSION 1)
|
|
+
|
|
+# Specify the cross compiler
|
|
+SET(CMAKE_C_COMPILER $ENV{INSTALL}/bin/musl-gcc)
|
|
+SET(CMAKE_CXX_COMPILER $ENV{INSTALL}/bin/musl-gcc)
|
|
+
|
|
+# Where is the target environment
|
|
+SET(CMAKE_FIND_ROOT_PATH $ENV{INSTALL})
|
|
+
|
|
+# Search for programs only in the build host directories
|
|
+SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
+
|
|
+# Search for libraries and headers only in the target directories
|
|
+SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
+SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
+
|
|
+INCLUDE_DIRECTORIES(hidapi)
|
|
--- libremkey-hotp-verification/device.c 2018-06-20 16:13:36.417804210 -0700
|
|
+++ libremkey-hotp-verification-b/device.c 2018-06-20 16:14:34.532367723 -0700
|
|
@@ -34,7 +34,7 @@
|
|
const unsigned short m_vid = 0x20a0;
|
|
const unsigned short m_pid = 0x4108;
|
|
|
|
-static const int CONNECTION_ATTEMPTS_COUNT = 80;
|
|
+static const int CONNECTION_ATTEMPTS_COUNT = 2;
|
|
|
|
static const int CONNECTION_ATTEMPT_DELAY_MICRO_SECONDS = 1000*1000/2;
|
|
|
|
--- libremkey-hotp-verification/libremkey_hotp_initialize
|
|
+++ libremkey-hotp-verification-b/libremkey_hotp_initialize
|
|
@@ -14,7 +14,7 @@ fi
|
|
PIN=$1
|
|
SECRET=$2
|
|
COUNTER=$3
|
|
-SECRET_B32=$(echo -n $SECRET | base32)
|
|
+SECRET_B32=$(cat $SECRET | base32)
|
|
|
|
libremkey_hotp_verification set $SECRET_B32 $PIN
|
|
if [ $? -ne 0 ]; then
|
|
@@ -25,7 +25,7 @@ fi
|
|
i=9
|
|
while [ "$i" -lt "$COUNTER" ]; do
|
|
echo "Updating counter to $i"
|
|
- HOTP_CODE=$(echo $SECRET | hotp $i)
|
|
+ HOTP_CODE=$(hotp $i < $SECRET)
|
|
libremkey_hotp_verification check $HOTP_CODE > /dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "HOTP check failed for counter=$i, code=$HOTP_CODE"
|
|
@@ -34,7 +34,7 @@ while [ "$i" -lt "$COUNTER" ]; do
|
|
let "i += 10"
|
|
done
|
|
|
|
-HOTP_CODE=$(echo $SECRET | hotp $COUNTER)
|
|
+HOTP_CODE=$(hotp $COUNTER < $SECRET)
|
|
libremkey_hotp_verification check $HOTP_CODE > /dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "HOTP check failed for counter=$COUNTER, code=$HOTP_CODE"
|