echo"ERROR: scriptor is not installed! This program cannot continue!"
zenity --error --text "ERROR: scriptor is not installed!\nThis program cannot continue!\n\nUsually, scriptor is part of the pcsc-tools package."
exit
fi
opensc=$(whereis opensc-explorer)
if[[$opensc=="opensc-explorer:"]];then
echo"ERROR: opensc-explorer is not installed! This program cannot continue!"
zenity --error --text "ERROR: opensc-explorer is not installed!\nThis program cannot continue!\n\nUsually, opensc-explorer is part of the opensc package."
exit
fi
# Get card ATR
FOUND_SUPPORTED_CARD=0
echo"RESET" > $SECURE_DIRECTORY/query
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2 2>/dev/null
fi
}
hexcvt ()
{
echo""$1" "16" o p"| dc
}
authenticatecard (){
if[[$authenticated !="1"]];then
if[[ -e /etc/smartauth/slave.key ]];then
autkey=$(cat /etc/smartauth/slave.key)
else
autkey=$(zenity --entry --hide-text --title="SmartCard Transport Key" --text="Please enter the 16-character Smart Card transport key [AUT1] in hexidecimal. Example: 0123456789abcdef")
fi
if[[${#autkey} -eq 16]];then
if[[$COMMAND_MODE=="acos"]];then
# Select MF
echo"00 A4 00 00 00" > $SECURE_DIRECTORY/query
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
zenity --error --text "That transport key is incorrect!\n\nPlease remember that there are a limited number\nof failed login attempts for this key,\nafter which your SmartCard will become useless."
fi
fi
else
echo"AUT1 key not 16 characters!"
zenity --error --text "That transport key is invalid!"
fi
fi
}
get_file (){
if[[$COMMAND_MODE=="acos"]];then
# Select EF $1 under DF 1000
echo"$SELECT_FILE$1" > $SECURE_DIRECTORY/query
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
echo$(cat $SECURE_DIRECTORY/response2)
# Read binary
echo"$READ_BINARY" > $SECURE_DIRECTORY/query
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2 2>/dev/null
echo$(cat $SECURE_DIRECTORY/response2)
fi
if[[$COMMAND_MODE=="cryptoflex"]];then
# Delete old file
echo"$DELETE_FILE$1" > $SECURE_DIRECTORY/query
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2 2>/dev/null
echo$(cat $SECURE_DIRECTORY/response2)
# Create new file
createfile "FF"$1
FILE=${1/ /}
echo"put $FILE$2"| opensc-explorer
fi
}
insertnewtext (){
FOUNDTEXT=$(cat $2| grep $1)
echo$FOUNDTEXT;
if[[$FOUNDTEXT !=""]];then
echo"$1 already exists in $2"
else
echo$1 >> $2
fi
}
getcolumn (){
perl -ne '@cols = split; print "$cols['$1']\n"';
}
function loadusername {
echo"Loading username..."
authenticatecard
if[[$authenticated="1"]];then
zenity --entry --title="SmartCard Username" --text="Please enter the username of the account to be associated with this SmartCard" > $SECURE_DIRECTORY/username
update_file "10 02""$SECURE_DIRECTORY/username"
rm -f $SECURE_DIRECTORY/username
fi
}
function loadpassword {
echo"Loading password..."
authenticatecard
if[[$authenticated="1"]];then
zenity --entry --hide-text --title="SmartCard Password" --text="Please enter the password of the account that is associated with this SmartCard" > $SECURE_DIRECTORY/password
update_file "10 03""$SECURE_DIRECTORY/password"
rm -f $SECURE_DIRECTORY/password
fi
}
function loadminutes {
echo"Loading minutes..."
authenticatecard
if[[$authenticated="1"]];then
echo"$(zenity --entry --hide-text --title="SmartCard Computer Minutes" --text="Please enter the number of computer minutes for this SmartCard")" > $SECURE_DIRECTORY/password
update_file "10 05""$SECURE_DIRECTORY/password"
rm -f $SECURE_DIRECTORY/password
fi
}
function enablerestrictedmode {
echo"Enabling restricted mode..."
authenticatecard
if[[$authenticated="1"]];then
echo"SLAVE" > $SECURE_DIRECTORY/password
update_file "10 04""$SECURE_DIRECTORY/password"
rm -f $SECURE_DIRECTORY/password
fi
}
function disablerestrictedmode {
echo"Disabling restricted mode..."
authenticatecard
if[[$authenticated="1"]];then
echo"NORMAL" > $SECURE_DIRECTORY/password
update_file "10 04""$SECURE_DIRECTORY/password"
rm -f $SECURE_DIRECTORY/password
fi
}
GREETER="Welcome to the SmartCard slave authentication setup utility!\n\nCard ATR: $smartatr\nDetected: $CARD_NICE_NAME\n\nPlease select an action from the list below:"
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
echo$(cat $SECURE_DIRECTORY/response2)
# Initialize first key record in file 10FD
# Key 1, 8-byte 1DES authentication only
autkey=""
while[[${#autkey} !=16]];do
autkey=$(zenity --entry --hide-text --title="SmartCard Transport Key" --text="Please enter the new 16-character Smart Card transport key [AUT1] in hexidecimal. Example: 0123456789abcdef")
scriptor $SECURE_DIRECTORY/query 1> $SECURE_DIRECTORY/response2
echo$(cat $SECURE_DIRECTORY/response2)
fi
if[[$COMMAND_MODE=="cryptoflex"]];then
autkey4=$(zenity --entry --hide-text --title="SmartCard Transport Key" --text="Please enter the new 16-character Smart Card transport key [AUT1] in hexidecimal. Example: 0123456789abcdef")