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