Skip to content

Commit

Permalink
yourfritz-host: workaround "number of zero blocks going into md5 calc…
Browse files Browse the repository at this point in the history
…ulation" bug

Most probably an AVM bug in their signing code.

In case ./var/signature tarball member starts exactly 1 KB before the end of a 10KB block
only 2 zero-blocks (both 512 bytes big) are taken into account while calculating the md5 sum,
in all other cases 4 zero-blocks (2 for ./var/signature + 2 for EoA marker) are considered.


git-svn-id: http://svn.freetz.org/trunk@14861 f5190166-0702-4917-9039-51ec32eddaf5
  • Loading branch information
er13 committed Sep 6, 2018
1 parent 4078d45 commit 080e519
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
@@ -0,0 +1,24 @@
--- signimage/sign_image
+++ signimage/sign_image
@@ -362,7 +354,11 @@
# blocks with a size of 512 octets) #
# #
####################################################################################
-"$YF_SIGNIMAGE_DD" if=/dev/zero of="$tmp/1K.bin" bs=512 count=2 status=none 2>/dev/null
+zero_blocks_in_md5=4 # 2 blocks ./var/signature member + 2 blocks EOA marker
+if [ $(( ( copy_blocks + 2 ) % 20 )) -eq 0 ]; then
+ zero_blocks_in_md5=2 # 2 blocks ./var/signature member only
+fi
+"$YF_SIGNIMAGE_DD" if=/dev/zero of="$tmp/zero_blocks_in_md5.bin" bs=512 count=$zero_blocks_in_md5 status=none 2>/dev/null
####################################################################################
# #
# generate the signature file #
@@ -374,7 +370,7 @@
# #
##################################A#################################################
echo -en "Signing the image hash (\x1B[1m$hash_algo\x1B[0m) with RSA key from \x1B[1m${name_prefix}.${private_extension}\x1B[0m ... " 1>&2
-"$YF_SIGNIMAGE_DD" if="$image_file" bs=512 count=$copy_blocks status=none 2>&1 | cat - "$tmp/1K.bin" "$tmp/1K.bin" |
+"$YF_SIGNIMAGE_DD" if="$image_file" bs=512 count=$copy_blocks status=none 2>&1 | cat - "$tmp/zero_blocks_in_md5.bin" |
"$YF_SIGNIMAGE_OPENSSL" dgst -$hash_algo -sign "${name_prefix}.${private_extension}" -out "$tmp/var/signature" -passin "pass:$KEYPASSWORD"
rc=$?
if [ $rc -eq 0 ]; then
@@ -0,0 +1,17 @@
--- signimage/sign_image
+++ signimage/sign_image
@@ -343,14 +343,6 @@
fi
####################################################################################
# #
-# prepare a temporary directory and cleanup on exit #
-# #
-####################################################################################
-tmp=$(mktemp -d)
-[ $? -eq 127 ] && tmp="/tmp/tmp.$(date +%s).$$" && mkdir -p "$tmp"
-trap "rm -r \"$tmp\"" EXIT HUP
-####################################################################################
-# #
# create a subdirectory 'var' to prepare a TAR file of our signature later #
# #
####################################################################################

0 comments on commit 080e519

Please sign in to comment.