tests: Add simple test for rwsig images

This tests that futility can correctly create and verify rwsig images.
Note that we do not test RSA 8192, as the signature is longer than
1024 bytes, and the test logic would need to be changed.

BRANCH=none
BUG=chromium:684354
TEST=make runfutiltests

Change-Id: I690e59fe8fa3e273dd81176211c58e1677fa720f
Reviewed-on: https://chromium-review.googlesource.com/438950
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Nicolas Boichat
2017-02-08 12:44:42 +08:00
committed by chrome-bot
parent 3ac811d4a5
commit f310106030
2 changed files with 47 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ ${SCRIPTDIR}/test_load_fmap.sh
${SCRIPTDIR}/test_main.sh
${SCRIPTDIR}/test_show_contents.sh
${SCRIPTDIR}/test_show_kernel.sh
${SCRIPTDIR}/test_show_rwsig.sh
${SCRIPTDIR}/test_show_vs_verify.sh
${SCRIPTDIR}/test_show_usbpd1.sh
${SCRIPTDIR}/test_sign_firmware.sh

View File

@@ -0,0 +1,46 @@
#!/bin/bash -eux
# Copyright 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
me=${0##*/}
TMP="$me.tmp"
# Work in scratch directory
cd "$OUTDIR"
DATADIR="${SCRIPTDIR}/data"
TESTKEYS=${SRCDIR}/tests/testkeys
# Do not test 8192 as the signature length is > 1024 bytes
SIGS="1024 2048 4096"
HASHES="SHA1 SHA256 SHA512"
set -o pipefail
for s in $SIGS; do
echo -n "$s " 1>&3
for h in $HASHES; do
pemfile=${TESTKEYS}/key_rsa${s}.pem
outfile=${TMP}.${s}_${h}.new
infile=${DATADIR}/random_noise.bin
outkeys=${TMP}.${s}_${h}
outsig=${TMP}.${s}_${h}.signature
${FUTILITY} create --desc "Test key" --hash_alg ${h} \
${pemfile} ${outkeys}
${FUTILITY} sign --type rwsig --prikey ${outkeys}.vbprik2 \
${infile} ${outsig}
dd if=/dev/zero bs=$((4096 + 1024)) count=1 of=${outfile}
dd if=${infile} of=${outfile} conv=notrunc
dd if=${outsig} of=${outfile} bs=4096 seek=1 conv=notrunc
${FUTILITY} show --type rwsig --pubkey ${outkeys}.vbpubk2 ${outfile}
done
done
# cleanup
rm -rf ${TMP}*
exit 0