From 433e509c9401dca8cf8d9badf605a6e4391f1dd0 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 5 Sep 2023 19:56:04 +0200 Subject: [PATCH] Add initialize with pkcs11-tool test script. Signed-off-by: Pol Henarejos --- tests/scripts/initialize.sh | 44 +++++++++++++++++++++++++++++++++++++ tests/start-up-and-test.sh | 9 +++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 tests/scripts/initialize.sh diff --git a/tests/scripts/initialize.sh b/tests/scripts/initialize.sh new file mode 100755 index 0000000..ce2fb9d --- /dev/null +++ b/tests/scripts/initialize.sh @@ -0,0 +1,44 @@ +#!/bin/bash -eu + +python3 tools/pico-hsm-tool.py --pin 648219 initialize --so-pin 57621880 --silent +test $? -eq 0 || exit $? + +# Change SO-PIN +pkcs11-tool --login --login-type so --so-pin 3537363231383830 --change-pin --new-pin 0123456789012345 +test $? -eq 0 || exit $? + +pkcs11-tool --login --login-type so --so-pin 0123456789012345 --change-pin --new-pin 3537363231383830 +test $? -eq 0 || exit $? + +# Change PIN +pkcs11-tool --login --pin 648219 --change-pin --new-pin 123456 +test $? -eq 0 || exit $? + +# Reset PIN +pkcs11-tool --login --login-type so --so-pin 3537363231383830 --init-pin --new-pin 648219 +test $? -eq 0 || exit $? + +# Change PIN +pkcs11-tool --login --pin 648219 --change-pin --new-pin 123456 +test $? -eq 0 || exit $? + +pkcs11-tool --login --pin 123456 --change-pin --new-pin 648219 +test $? -eq 0 || exit $? + +# Wrong PIN (1st and 2nd PIN_INCORRECT, 3rd PIN_LOCKED) +e=$(pkcs11-tool --login --pin 123456 -I 2>&1) +test $? -eq 1 || exit $? +grep -q CKR_PIN_INCORRECT <<< $e || exit $? +e=$(pkcs11-tool --login --pin 123456 -I 2>&1) +test $? -eq 1 || exit $? +grep -q CKR_PIN_INCORRECT <<< $e || exit $? +e=$(pkcs11-tool --login --pin 123456 -I 2>&1) +test $? -eq 1 || exit $? +grep -q CKR_PIN_LOCKED <<< $e || exit $? + +# Reset PIN +pkcs11-tool --login --login-type so --so-pin 3537363231383830 --init-pin --new-pin 648219 +test $? -eq 0 || exit $? + +pkcs11-tool --login --pin 648219 -I > /dev/null +test $? -eq 0 || exit $? diff --git a/tests/start-up-and-test.sh b/tests/start-up-and-test.sh index 9ba94b4..46b8c9a 100755 --- a/tests/start-up-and-test.sh +++ b/tests/start-up-and-test.sh @@ -8,4 +8,11 @@ sleep 2 rm -f memory.flash tar -xf tests/memory.tar.gz ./build_in_docker/pico_hsm > /dev/null & -pytest tests -W ignore::DeprecationWarning +#pytest tests -W ignore::DeprecationWarning + +chmod a+x tests/scripts/*.sh + +echo -n "Test initialization... " +./tests/scripts/initialize.sh +echo "\tok" +