Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RSA_KEY_SIZE flag to cli test script #114

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
tgonzalezorlandoarm marked this conversation as resolved.
Show resolved Hide resolved
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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocke but would it be worth to have a print-out of the chosen key size? Given that we have multiple ways of setting it RSA_KEY_SIZE enviroment var, --rsa-key-size or the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added now.

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
tgonzalezorlandoarm marked this conversation as resolved.
Show resolved Hide resolved
;;
*)
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
Loading