Home | History | Annotate | Download | only in mmc_security
      1 #!/bin/bash
      2 #********************************************************************************#
      3 #* 										*#
      4 #* Copyright (c) 2005 Instituto Nokia de Tecnologia - INdT - Manaus Brazil 	*#
      5 #* 										*#
      6 #* This program is free software; you can redistribute it and#or modify 	*#
      7 #* it under the terms of the GNU General Public License as published by 	*#
      8 #* the Free Software Foundation; either version 2 of the License, or 		*#
      9 #* (at your option) any later version. 						*#
     10 #* 										*#
     11 #* This program is distributed in the hope that it will be useful, 		*#
     12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of 		*#
     13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 			*#
     14 #* the GNU General Public License for more details. 				*#
     15 #* 										*#
     16 #* You should have received a copy of the GNU General Public License 		*#
     17 #* along with this program; if not, write to the Free Software 			*#
     18 #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 	*#
     19 #* 										*#
     20 #********************************************************************************#
     21 
     22 #********************************************************************************#
     23 #* 										*#
     24 #* File: ask_password.sh 							*#
     25 #* 										*#
     26 #* Description: get the password from userspace. It's called when unlocking 	*#
     27 #* the card or assigning a new password to an unlocked card. 			*#
     28 #* Return        - zero on success						*#
     29 #*               - non zero on failure. return value from commands ($RC)	*#
     30 #* Total Tests: 1 								*#
     31 #*										*#
     32 #* Author: Anderson Briglia <anderson.briglia (at] indt.org.br> 			*#
     33 #* Anderson Lizardo <anderson.lizardo (at] indt.org.br> 				*#
     34 #* Carlos Eduardo Aguiar <carlos.aguiar (at] indt.org.br> 				*#
     35 #* 										*#
     36 #* 										*#
     37 #* 										*#
     38 #********************************************************************************#
     39 
     40 ask_password()
     41 {
     42 	export TST_TOTAL=1  # Total number of test cases in this file.
     43 	# Set up LTPTMP (temporary directory used by the tests).
     44 	LTPTMP=${TMP}       # Temporary directory to create files, etc.
     45 	export TCID="ask_password" # Test case identifier
     46 	export TST_COUNT=0  # Set up is initialized as test 0
     47 	RC=0                # Exit values of system commands used
     48 
     49 	USER_CONSOLE=/dev/ttyS0
     50 	{
     51 		echo "=== Unlock Protected MMC ==="
     52 		while [ -z "$passwd" ]; do
     53 			read -s -p "MMC password: " passwd; echo
     54 		done
     55 		if ! keyctl instantiate $1 "$passwd" $2 &>/dev/null; then
     56 			echo "*** Wrong password! The card was not unlocked."
     57 			exit 1
     58 		fi
     59 		echo "Password accepted."
     60 
     61 		exit 0
     62 	} &> $USER_CONSOLE < $USER_CONSOLE
     63 }
     64 
     65 ask_password || exit $RC
     66