Skip to content

Commit

Permalink
tests/parsec-cli-tests.sh: Add RSA_KEY_SIZE flag
Browse files Browse the repository at this point in the history
This flag can be used for testing parsec on slower platforms
where RSA 2048 key operations are time consuming.

Signed-off-by: Gowtham Suresh Kumar <[email protected]>
  • Loading branch information
gowthamsk-arm committed Nov 24, 2023
1 parent 2c78cc3 commit b110aa0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ fi
./target/debug/parsec-tool --help

PARSEC_TOOL="./target/debug/parsec-tool" tests/parsec-cli-tests.sh -d
PARSEC_TOOL="./target/debug/parsec-tool" tests/parsec-cli-tests.sh -d --rsa-key-size 1024
24 changes: 19 additions & 5 deletions tests/parsec-cli-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ create_key() {
EXTRA_CREATE_KEY_ARGS=""
fi

if [ "$RSA_KEY_SIZE" -a "$1" = "RSA" ]; then
KEY_LEN="--bits $RSA_KEY_SIZE"
else
KEY_LEN=""
fi

echo
echo "- Creating an $1 key and exporting its public part"
type_lower=$(echo $1 | tr '[:upper:]' '[:lower:]')
run_cmd $PARSEC_TOOL_CMD create-${type_lower}-key --key-name $KEY $EXTRA_CREATE_KEY_ARGS
run_cmd $PARSEC_TOOL_CMD create-${type_lower}-key --key-name $KEY $EXTRA_CREATE_KEY_ARGS $KEY_LEN

if ! run_cmd $PARSEC_TOOL_CMD list-keys | tee /dev/stderr | grep -q "$KEY"; then
echo "Error: $KEY is not listed"
Expand Down Expand Up @@ -101,7 +107,7 @@ test_crypto_provider() {
test_encryption() {
# $1 - algorithm
KEY="anta-key-rsa-encrypt"
TEST_STR="$(date) Parsec public key encryption test"
TEST_STR="$(date) Parsec public key encryption"
ALG="$1"

create_key "RSA" "$KEY" "$ALG"
Expand Down Expand Up @@ -236,16 +242,19 @@ test_csr() {

test_rsa_key_bits() {
KEY="anta-key-rsa-bits"
DEFAULT_SIZE=2048

if [ -n "$1" ]; then
if [ "$RSA_KEY_SIZE" ]; then
key_size="$RSA_KEY_SIZE"
key_param="--bits $RSA_KEY_SIZE"
elif [ -n "$1" ]; then
key_size=$1
key_param="--bits $1"
else
key_size=${DEFAULT_SIZE}
key_size=2048
key_param=""
fi

echo "Creating ${key_size}-bit RSA key."
run_cmd $PARSEC_TOOL_CMD create-rsa-key --key-name $KEY $key_param
run_cmd $PARSEC_TOOL_CMD export-public-key --key-name $KEY >${MY_TMP}/checksize-${KEY}.pem
if ! run_cmd $OPENSSL rsa -pubin -text -noout -in ${MY_TMP}/checksize-${KEY}.pem | grep -q "Public-Key: (${key_size} bit)"; then
Expand All @@ -261,6 +270,7 @@ PROVIDER=
# Test both RSA PKCS#1 v1.5 (default) and RSA OAEP encryption algorithms
NO_OAEP=
NO_PKCS1_V15=
RSA_KEY_SIZE=
while [ "$#" -gt 0 ]; do
case "$1" in
-[0-9]* )
Expand All @@ -277,6 +287,9 @@ while [ "$#" -gt 0 ]; do
--no-v1.5 )
NO_PKCS1_V15="true"
;;
--rsa-key-size )
shift; RSA_KEY_SIZE=$1
;;
*)
cat <<EOF
Usage: $0 [parameter]
Expand All @@ -286,6 +299,7 @@ Usage: $0 [parameter]
-N: Test only the provider with N ID
--no-oaep: Do not test RSA-OAEP(SHA256) encryption/decryption operations
--no-v1.5: Do not test RSA-PKCS#1-v1.5 encryption/decryption operations
--rsa-key-size: Perform all RSA operations with the specified key length
Environment variables used if defined:
PARSEC_SERVICE_ENDPOINT - Parsec service API endpoint
Expand Down

0 comments on commit b110aa0

Please sign in to comment.