mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-27 11:44:02 +00:00
Vboot Reference: Spring cleaning of test scripts.
Moved duplicated code to "common.sh". Make directory detection more robust. Review URL: http://codereview.chromium.org/1101004
This commit is contained in:
39
tests/common.sh
Executable file
39
tests/common.sh
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright (c) 2010 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.
|
||||||
|
|
||||||
|
# Determine script directory.
|
||||||
|
if [[ $0 == '/'* ]];
|
||||||
|
then
|
||||||
|
SCRIPT_DIR="`dirname $0`"
|
||||||
|
elif [[ $0 == './'* ]];
|
||||||
|
then
|
||||||
|
SCRIPT_DIR="`pwd`"
|
||||||
|
else
|
||||||
|
SCRIPT_DIR="`pwd`"/"`dirname $0`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils
|
||||||
|
TEST_DIR=${SCRIPT_DIR}
|
||||||
|
TESTKEY_DIR=${SCRIPT_DIR}/testkeys
|
||||||
|
TESTCASE_DIR=${SCRIPT_DIR}/testcases
|
||||||
|
|
||||||
|
# Color output encodings.
|
||||||
|
COL_RED='\E[31;1m'
|
||||||
|
COL_GREEN='\E[32;1m'
|
||||||
|
COL_YELLOW='\E[33;1m'
|
||||||
|
COL_BLUE='\E[34;1m'
|
||||||
|
COL_STOP='\E[0;m'
|
||||||
|
|
||||||
|
hash_algos=( sha1 sha256 sha512 )
|
||||||
|
key_lengths=( 1024 2048 4096 8192 )
|
||||||
|
|
||||||
|
function check_test_keys {
|
||||||
|
if [ ! -d ${TESTKEY_DIR} ]
|
||||||
|
then
|
||||||
|
echo "You must run gen_test_keys.sh to generate test keys first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
@@ -6,14 +6,13 @@
|
|||||||
|
|
||||||
# Generate test cases for use for the RSA verify benchmark.
|
# Generate test cases for use for the RSA verify benchmark.
|
||||||
|
|
||||||
TESTCASE_DIR=fuzz_testcases
|
# Load common constants and variables.
|
||||||
TESTKEY_DIR=testkeys
|
. "$(dirname "$0")/common.sh"
|
||||||
UTIL_DIR=../utils/
|
|
||||||
TEST_FILE=test_file
|
|
||||||
TEST_FILE_SIZE=1000000
|
|
||||||
|
|
||||||
hash_algos=( sha1 sha256 sha512 )
|
# Use a different directory for fuzzing test cases.
|
||||||
key_lengths=( 1024 2048 4096 8192 )
|
TESTCASE_DIR=${SCRIPT_DIR}/fuzz_testcases
|
||||||
|
TEST_FILE=${TESTCASE_DIR}/testfile
|
||||||
|
TEST_FILE_SIZE=500000
|
||||||
|
|
||||||
# Generate public key signatures and digest on an input file for
|
# Generate public key signatures and digest on an input file for
|
||||||
# various combinations of message digest algorithms and RSA key sizes.
|
# various combinations of message digest algorithms and RSA key sizes.
|
||||||
@@ -47,22 +46,11 @@ function generate_fuzzing_images {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pre_work {
|
function pre_work {
|
||||||
# Generate a file with random bytes for signature tests.
|
# Generate a file to serve as random bytes for firmware/kernel contents.
|
||||||
echo "Generating test file..."
|
echo "Generating test file..."
|
||||||
dd if=/dev/urandom of=${TESTCASE_DIR}/${TEST_FILE} bs=${TEST_FILE_SIZE} \
|
dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
|
||||||
count=1
|
|
||||||
}
|
}
|
||||||
|
mkdir -p ${TESTCASE_DIR}
|
||||||
if [ ! -d ${TESTKEY_DIR} ]
|
|
||||||
then
|
|
||||||
echo "You must run gen_test_keys.sh to generate test keys first."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d ${TESTCASE_DIR} ]
|
|
||||||
then
|
|
||||||
mkdir ${TESTCASE_DIR}
|
|
||||||
fi
|
|
||||||
|
|
||||||
pre_work
|
pre_work
|
||||||
generate_fuzzing_images ${TESTCASE_DIR}/$TEST_FILE
|
check_test_keys
|
||||||
|
generate_fuzzing_images ${TEST_FILE}
|
||||||
|
|||||||
@@ -6,49 +6,39 @@
|
|||||||
|
|
||||||
# Generate test cases for use for the RSA verify benchmark.
|
# Generate test cases for use for the RSA verify benchmark.
|
||||||
|
|
||||||
KEY_DIR=testkeys
|
# Load common constants and variables.
|
||||||
TESTCASE_DIR=testcases
|
. "$(dirname "$0")/common.sh"
|
||||||
UTIL_DIR=../utils/
|
|
||||||
TEST_FILE=test_file
|
TEST_FILE=${TESTCASE_DIR}/test_file
|
||||||
TEST_FILE_SIZE=1000000
|
TEST_FILE_SIZE=1000000
|
||||||
|
|
||||||
hash_algos=( sha1 sha256 sha512 )
|
# Generate public key signatures on an input file for various combinations
|
||||||
key_lengths=( 1024 2048 4096 8192 )
|
# of message digest algorithms and RSA key sizes.
|
||||||
|
|
||||||
# Generate public key signatures and digest on an input file for
|
|
||||||
# various combinations of message digest algorithms and RSA key sizes.
|
|
||||||
function generate_test_signatures {
|
function generate_test_signatures {
|
||||||
|
echo "Generating test signatures..."
|
||||||
algorithmcounter=0
|
algorithmcounter=0
|
||||||
for keylen in ${key_lengths[@]}
|
for keylen in ${key_lengths[@]}
|
||||||
do
|
do
|
||||||
for hashalgo in ${hash_algos[@]}
|
for hashalgo in ${hash_algos[@]}
|
||||||
do
|
do
|
||||||
openssl dgst -${hashalgo} -binary -out $1.${hashalgo}.digest $1
|
openssl dgst -${hashalgo} -binary ${TEST_FILE} > \
|
||||||
${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \
|
${TEST_FILE}.${hashalgo}.digest
|
||||||
-pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \
|
${UTIL_DIR}/signature_digest_utility $algorithmcounter \
|
||||||
> $1.rsa${keylen}_${hashalgo}.sig
|
${TEST_FILE} | openssl rsautl \
|
||||||
|
-sign -pkcs -inkey ${TESTKEY_DIR}/key_rsa${keylen}.pem \
|
||||||
|
> ${TEST_FILE}.rsa${keylen}_${hashalgo}.sig
|
||||||
let algorithmcounter=algorithmcounter+1
|
let algorithmcounter=algorithmcounter+1
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_work {
|
# Generate a file with random bytes for signature tests.
|
||||||
# Generate a file with random bytes for signature tests.
|
function generate_test_file {
|
||||||
echo "Generating test file..."
|
echo "Generating test file..."
|
||||||
dd if=/dev/urandom of=${TESTCASE_DIR}/${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
|
dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -d "$KEY_DIR" ]
|
mkdir -p ${TESTCASE_DIR}
|
||||||
then
|
check_test_keys
|
||||||
echo "You must run gen_test_cases.sh to generate test keys first."
|
generate_test_file
|
||||||
exit 1
|
generate_test_signatures
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d "$TESTCASE_DIR" ]
|
|
||||||
then
|
|
||||||
mkdir "$TESTCASE_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
pre_work
|
|
||||||
echo "Generating test signatures..."
|
|
||||||
generate_test_signatures ${TESTCASE_DIR}/$TEST_FILE
|
|
||||||
|
|||||||
@@ -3,30 +3,25 @@
|
|||||||
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
#
|
||||||
# Generate test keys for use by the tests.
|
# Generate test keys for use by the tests.
|
||||||
|
|
||||||
KEY_DIR=testkeys
|
# Load common constants and variables.
|
||||||
key_lengths=( 1024 2048 4096 8192 )
|
. "$(dirname "$0")/common.sh"
|
||||||
UTIL_DIR=../utils/
|
|
||||||
|
|
||||||
# Generate RSA test keys of various lengths.
|
# Generate RSA test keys of various lengths.
|
||||||
function generate_keys {
|
function generate_keys {
|
||||||
for i in ${key_lengths[@]}
|
for i in ${key_lengths[@]}
|
||||||
do
|
do
|
||||||
openssl genrsa -F4 -out ${KEY_DIR}/key_rsa$i.pem $i
|
openssl genrsa -F4 -out ${TESTKEY_DIR}/key_rsa$i.pem $i
|
||||||
# Generate self-signed certificate from key.
|
# Generate self-signed certificate from key.
|
||||||
openssl req -batch -new -x509 -key ${KEY_DIR}/key_rsa$i.pem \
|
openssl req -batch -new -x509 -key ${TESTKEY_DIR}/key_rsa$i.pem \
|
||||||
-out ${KEY_DIR}/key_rsa$i.crt
|
-out ${TESTKEY_DIR}/key_rsa$i.crt
|
||||||
# Generate pre-processed key for use by RSA signature verification code.
|
# Generate pre-processed key for use by RSA signature verification code.
|
||||||
${UTIL_DIR}/dumpRSAPublicKey ${KEY_DIR}/key_rsa$i.crt \
|
${UTIL_DIR}/dumpRSAPublicKey ${TESTKEY_DIR}/key_rsa$i.crt \
|
||||||
> ${KEY_DIR}/key_rsa$i.keyb
|
> ${TESTKEY_DIR}/key_rsa$i.keyb
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -d "$KEY_DIR" ]
|
mkdir -p ${TESTKEY_DIR}
|
||||||
then
|
|
||||||
mkdir "$KEY_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
generate_keys
|
generate_keys
|
||||||
|
|||||||
@@ -6,17 +6,10 @@
|
|||||||
|
|
||||||
# Run verified boot firmware and kernel verification tests.
|
# Run verified boot firmware and kernel verification tests.
|
||||||
|
|
||||||
return_code=0
|
# Load common constants and variables.
|
||||||
hash_algos=( sha1 sha256 sha512 )
|
. "$(dirname "$0")/common.sh"
|
||||||
key_lengths=( 1024 2048 4096 8192 )
|
|
||||||
TEST_FILE=test_file
|
|
||||||
TEST_FILE_SIZE=1000000
|
|
||||||
|
|
||||||
COL_RED='\E[31;1m'
|
return_code=0
|
||||||
COL_GREEN='\E[32;1m'
|
|
||||||
COL_YELLOW='\E[33;1m'
|
|
||||||
COL_BLUE='\E[34;1m'
|
|
||||||
COL_STOP='\E[0;m'
|
|
||||||
|
|
||||||
function test_firmware_verification {
|
function test_firmware_verification {
|
||||||
algorithmcounter=0
|
algorithmcounter=0
|
||||||
@@ -26,10 +19,10 @@ function test_firmware_verification {
|
|||||||
do
|
do
|
||||||
echo -e "For Root key ${COL_YELLOW}RSA-$keylen/$hashalgo${COL_STOP}:"
|
echo -e "For Root key ${COL_YELLOW}RSA-$keylen/$hashalgo${COL_STOP}:"
|
||||||
cd ${UTIL_DIR} && ${TEST_DIR}/firmware_image_tests $algorithmcounter \
|
cd ${UTIL_DIR} && ${TEST_DIR}/firmware_image_tests $algorithmcounter \
|
||||||
${TEST_DIR}/testkeys/key_rsa8192.pem \
|
${TESTKEY_DIR}/key_rsa8192.pem \
|
||||||
${TEST_DIR}/testkeys/key_rsa8192.keyb \
|
${TESTKEY_DIR}/key_rsa8192.keyb \
|
||||||
${TEST_DIR}/testkeys/key_rsa${keylen}.pem \
|
${TESTKEY_DIR}/key_rsa${keylen}.pem \
|
||||||
${TEST_DIR}/testkeys/key_rsa${keylen}.keyb
|
${TESTKEY_DIR}/key_rsa${keylen}.keyb
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
return_code=255
|
return_code=255
|
||||||
@@ -59,10 +52,10 @@ and ${COL_YELLOW}Kernel signing algorithm RSA-${kernel_keylen}/\
|
|||||||
${kernel_hashalgo}${COL_STOP}"
|
${kernel_hashalgo}${COL_STOP}"
|
||||||
cd ${UTIL_DIR} && ${TEST_DIR}/kernel_image_tests \
|
cd ${UTIL_DIR} && ${TEST_DIR}/kernel_image_tests \
|
||||||
$firmware_algorithmcounter $kernel_algorithmcounter \
|
$firmware_algorithmcounter $kernel_algorithmcounter \
|
||||||
${TEST_DIR}/testkeys/key_rsa${firmware_keylen}.pem \
|
${TESTKEY_DIR}/key_rsa${firmware_keylen}.pem \
|
||||||
${TEST_DIR}/testkeys/key_rsa${firmware_keylen}.keyb \
|
${TESTKEY_DIR}/key_rsa${firmware_keylen}.keyb \
|
||||||
${TEST_DIR}/testkeys/key_rsa${kernel_keylen}.pem \
|
${TESTKEY_DIR}/key_rsa${kernel_keylen}.pem \
|
||||||
${TEST_DIR}/testkeys/key_rsa${kernel_keylen}.keyb
|
${TESTKEY_DIR}/key_rsa${kernel_keylen}.keyb
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
return_code=255
|
return_code=255
|
||||||
@@ -75,20 +68,7 @@ ${kernel_hashalgo}${COL_STOP}"
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine script directory.
|
check_test_keys
|
||||||
if [[ $0 == '/'* ]];
|
|
||||||
then
|
|
||||||
SCRIPT_DIR="`dirname $0`"
|
|
||||||
elif [[ $0 == './'* ]];
|
|
||||||
then
|
|
||||||
SCRIPT_DIR="`pwd`"
|
|
||||||
else
|
|
||||||
SCRIPT_DIR="`pwd`"/"`dirname $0`"
|
|
||||||
fi
|
|
||||||
UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils
|
|
||||||
KEY_DIR=${SCRIPT_DIR}/testkeys
|
|
||||||
TEST_DIR=${SCRIPT_DIR}/
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Testing high-level firmware image verification..."
|
echo "Testing high-level firmware image verification..."
|
||||||
test_firmware_verification
|
test_firmware_verification
|
||||||
|
|||||||
@@ -3,36 +3,14 @@
|
|||||||
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
|
#
|
||||||
# Run tests for RSA Signature verification.
|
# Run tests for RSA Signature verification.
|
||||||
|
|
||||||
|
# Load common constants and variables.
|
||||||
|
. "$(dirname "$0")/common.sh"
|
||||||
|
|
||||||
return_code=0
|
return_code=0
|
||||||
hash_algos=( sha1 sha256 sha512 )
|
TEST_FILE=${TESTCASE_DIR}/test_file
|
||||||
key_lengths=( 1024 2048 4096 8192 )
|
|
||||||
TEST_FILE=test_file
|
|
||||||
TEST_FILE_SIZE=1000000
|
|
||||||
|
|
||||||
COL_RED='\E[31;1m'
|
|
||||||
COL_GREEN='\E[32;1m'
|
|
||||||
COL_YELLOW='\E[33;1m'
|
|
||||||
COL_BLUE='\E[34;1m'
|
|
||||||
COL_STOP='\E[0;m'
|
|
||||||
|
|
||||||
# Generate public key signatures on an input file for various combinations
|
|
||||||
# of message digest algorithms and RSA key sizes.
|
|
||||||
function generate_signatures {
|
|
||||||
algorithmcounter=0
|
|
||||||
for keylen in ${key_lengths[@]}
|
|
||||||
do
|
|
||||||
for hashalgo in ${hash_algos[@]}
|
|
||||||
do
|
|
||||||
${UTIL_DIR}/signature_digest_utility $algorithmcounter $1 | openssl \
|
|
||||||
rsautl -sign -pkcs -inkey ${KEY_DIR}/key_rsa${keylen}.pem \
|
|
||||||
> $1.rsa${keylen}\_${hashalgo}.sig
|
|
||||||
let algorithmcounter=algorithmcounter+1
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_signatures {
|
function test_signatures {
|
||||||
algorithmcounter=0
|
algorithmcounter=0
|
||||||
@@ -42,8 +20,9 @@ function test_signatures {
|
|||||||
do
|
do
|
||||||
echo -e "For ${COL_YELLOW}RSA-$keylen and $hashalgo${COL_STOP}:"
|
echo -e "For ${COL_YELLOW}RSA-$keylen and $hashalgo${COL_STOP}:"
|
||||||
${UTIL_DIR}/verify_data $algorithmcounter \
|
${UTIL_DIR}/verify_data $algorithmcounter \
|
||||||
${KEY_DIR}/key_rsa${keylen}.keyb \
|
${TESTKEY_DIR}/key_rsa${keylen}.keyb \
|
||||||
${TEST_FILE}.rsa${keylen}_${hashalgo}.sig ${TEST_FILE}
|
${TEST_FILE}.rsa${keylen}_${hashalgo}.sig \
|
||||||
|
${TEST_FILE}
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
return_code=255
|
return_code=255
|
||||||
@@ -52,45 +31,12 @@ function test_signatures {
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
echo -e "Peforming ${COL_YELLOW}PKCS #1 v1.5 Padding Tests${COL_STOP}..."
|
echo -e "Peforming ${COL_YELLOW}PKCS #1 v1.5 Padding Tests${COL_STOP}..."
|
||||||
${TEST_DIR}/rsa_padding_test ${TEST_DIR}/testkeys/rsa_padding_test_pubkey.keyb
|
${TEST_DIR}/rsa_padding_test ${TESTKEY_DIR}/rsa_padding_test_pubkey.keyb
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_work {
|
check_test_keys
|
||||||
# Generate a file with random bytes for signature tests.
|
|
||||||
echo "Generating test file..."
|
|
||||||
dd if=/dev/urandom of=${TEST_FILE} bs=${TEST_FILE_SIZE} count=1
|
|
||||||
echo "Generating signatures..."
|
|
||||||
generate_signatures $TEST_FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup {
|
|
||||||
rm ${SCRIPT_DIR}/${TEST_FILE} ${SCRIPT_DIR}/${TEST_FILE}.*.sig
|
|
||||||
}
|
|
||||||
|
|
||||||
# Determine script directory.
|
|
||||||
if [[ $0 == '/'* ]];
|
|
||||||
then
|
|
||||||
SCRIPT_DIR="`dirname $0`"
|
|
||||||
elif [[ $0 == './'* ]];
|
|
||||||
then
|
|
||||||
SCRIPT_DIR="`pwd`"
|
|
||||||
else
|
|
||||||
SCRIPT_DIR="`pwd`"/"`dirname $0`"
|
|
||||||
fi
|
|
||||||
UTIL_DIR=`dirname ${SCRIPT_DIR}`/utils
|
|
||||||
KEY_DIR=${SCRIPT_DIR}/testkeys
|
|
||||||
TEST_DIR=${SCRIPT_DIR}/
|
|
||||||
|
|
||||||
echo "Generating test cases..."
|
|
||||||
pre_work
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Testing signature verification..."
|
echo "Testing signature verification..."
|
||||||
test_signatures
|
test_signatures
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Cleaning up..."
|
|
||||||
cleanup
|
|
||||||
|
|
||||||
exit $return_code
|
exit $return_code
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user