decrypt_opensc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. # Why not use "openct-tool rwait" instead of polling opensc-tool exit status?
  3. # Well openct daemon has to be running which interferes with pcscd since both
  4. # implement reader drivers, my particular CCID reader (SCM SCR331-LC1) doesn't
  5. # work with the CCID driver in openct, however it does work with pcscd.
  6. # Why not use "opensc-tool --wait" instead of polling opensc-tool exit status?
  7. # Although opensc-tool --help reports that there is a --wait option, it doesn't
  8. # seem to be implemented.
  9. check_card() {
  10. cardfound=0
  11. if /usr/bin/opensc-tool -n >/dev/null 2>&1; then
  12. cardfound=1
  13. fi
  14. }
  15. wait_card() {
  16. check_card
  17. if [ $cardfound = 0 ] ; then
  18. echo "Waiting for Smart Card..." >&2
  19. tries=0
  20. while [ $cardfound = 0 ] && [ $tries -lt 60 ] ; do
  21. sleep 1
  22. check_card
  23. tries=$(($tries + 1))
  24. done
  25. if [ $cardfound = 0 ] ; then
  26. echo 'Failed to find Smart Card card!' >&2
  27. exit 1
  28. fi
  29. fi
  30. }
  31. wait_card
  32. if [ -x /bin/plymouth ] && plymouth --ping; then
  33. # Get pin number from plymouth
  34. /usr/bin/pkcs15-crypt --decipher --input "$1" --pkcs1 --raw \
  35. --pin "$(plymouth ask-for-password --prompt "Enter pin for $CRYPTTAB_NAME: ")"
  36. else
  37. # Get pin number from console
  38. /usr/bin/pkcs15-crypt --decipher --input "$1" --pkcs1 --raw </dev/console 2>/dev/console
  39. fi
  40. exit $?