From 654cb1e4e0510b7b8b80d73cc4c41ffd74f843e2 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 11 Oct 2023 12:13:21 +0200 Subject: [PATCH] Added AES pkcs11 tests. Signed-off-by: Pol Henarejos --- tests/scripts/aes.sh | 38 ++++++++++++++++++++++++++++++++++++++ tests/scripts/pkcs11.sh | 7 +++++++ 2 files changed, 45 insertions(+) create mode 100755 tests/scripts/aes.sh diff --git a/tests/scripts/aes.sh b/tests/scripts/aes.sh new file mode 100755 index 0000000..ae1a22b --- /dev/null +++ b/tests/scripts/aes.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +source ./tests/scripts/func.sh +reset +test $? -eq 0 || exit $? + +TEST_DATA="This is a text." + +echo "${TEST_DATA}" > test + +sc_tool() { + pkcs11-tool --module /usr/local/lib/libsc-hsm-pkcs11.so -l --pin 648219 $@ +} + +aeses=("16" "24" "32") + +for aes in ${aeses[*]}; do + echo " Test AES (AES:${aes})" + echo -n " Keygen... " + sc_tool --keygen --key-type "AES:${aes}" --id 1 --label "AES:${aes}" > /dev/null 2>&1 + test $? -eq 0 && echo -n "." || exit $? + e=$(sc_tool --list-object --type secrkey 2>&1) + test $? -eq 0 && echo -n "." || exit $? + grep -q "AES length ${aes}" <<< $e && echo -n "." || exit $? + grep -q "AES:${aes}" <<< $e && echo -e ".\t${OK}" || exit $? + + echo -n " Encryption..." + sc_tool --encrypt --id 1 --input-file test --mechanism aes-cbc > crypted.aes 2>/dev/null + test $? -eq 0 && echo -e ".\t${OK}" || exit $? + + echo -n " Decryption..." + e=$(sc_tool --decrypt --id 1 --input-file crypted.aes --mechanism aes-cbc 2>/dev/null) + test $? -eq 0 && echo -n "." || exit $? + grep -q "${TEST_DATA}" <<< $e && echo -e ".\t${OK}" || exit $? + + sc_tool --delete --type secrkey --id 1 > /dev/null 2>&1 +done +rm -rf test crypted.aes diff --git a/tests/scripts/pkcs11.sh b/tests/scripts/pkcs11.sh index bf625a2..e0f6fda 100755 --- a/tests/scripts/pkcs11.sh +++ b/tests/scripts/pkcs11.sh @@ -35,3 +35,10 @@ test $? -eq 0 || { echo -e "\t${FAIL}" exit 1 } + +echo "==== Test AES ====" +./tests/scripts/aes.sh +test $? -eq 0 || { + echo -e "\t${FAIL}" + exit 1 +}