Skip to content

Instantly share code, notes, and snippets.

@calaveraInfo
Created September 13, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calaveraInfo/469e05d7c50b2bb4ec47555dbe2b9b77 to your computer and use it in GitHub Desktop.
Save calaveraInfo/469e05d7c50b2bb4ec47555dbe2b9b77 to your computer and use it in GitHub Desktop.
Shell script that repeats simple smart card operations many times. May be used to measure smart card performance or reliability.
#!/bin/bash
# pkcs15-tool --list-keys
# Private RSA Key [Digital Signature]: ID: 11
TEMPFILE=`mktemp`
# reading PIN into environment variable is NOT safe, DO NOT use on shared computer.
# read is built-in, manual can be shown with
# help read
read -e -s -p "PIN: " PIN
# history is written only in interactive shell, turning it off is not needed
# set -o history
for cycle in {1..60}; do
# create a message that don't need any padding - 256 bytes
cat /dev/urandom | head -c 256 > $TEMPFILE
echo "Attempt no. $cycle"
# echo is usually built-in, no need to worry about showing PIN in the process list
# to find out if it's built in run
# type echo
echo "$PIN" | pkcs15-crypt --pin - --key 11 --sign --input $TEMPFILE
if [ "$?" -ne 0 ]; then
>&2 echo "Error while signing"
exit 255;
fi
done
rm $TEMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment