Add initialize with pkcs11-tool test script.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2023-09-05 19:56:04 +02:00
parent 9f08d612ae
commit 433e509c94
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3
2 changed files with 52 additions and 1 deletions

44
tests/scripts/initialize.sh Executable file
View File

@ -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 $?

View File

@ -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"