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: change_password.sh 							*#
     25 #* 										*#
     26 #* Description: used to change the password from a unlocked card.		*#
     27 #* Total Tests: 1 								*#
     28 #* 										*#
     29 #* Author: Anderson Briglia <anderson.briglia (at] indt.org.br> 			*#
     30 #* Anderson Lizardo <anderson.lizardo (at] indt.org.br> 				*#
     31 #* Carlos Eduardo Aguiar <carlos.aguiar (at] indt.org.br> 				*#
     32 #* 										*#
     33 #* 										*#
     34 #* 										*#
     35 #********************************************************************************#
     36 change_password()
     37 {
     38 	export TST_TOTAL=1  # Total number of test cases in this file.
     39 	# Set up LTPTMP (temporary directory used by the tests).
     40 	LTPTMP=${TMP}       # Temporary directory to create files, etc.
     41 	export TCID="change_password" # Test case identifier
     42 	export TST_COUNT=0  # Set up is initialized as test 0
     43 	RC=0                # Exit values of system commands used
     44 
     45 	echo "=== Change MMC Password ==="
     46 	keyid=$(keyctl request mmc "mmc:key")
     47 	if [ -z "$keyid" ]; then
     48 		echo "*** No protected and unlocked MMC was found. The password cannot be changed."
     49 		exit 1
     50 	fi
     51 
     52 	while [ -z "$oldpasswd" ]; do
     53 		read -s -p "Current MMC password: " oldpasswd; echo
     54 	done
     55 
     56 	while [ -z "$newpasswd" ]; do
     57 		read -s -p "New MMC password: " newpasswd; echo
     58 	done
     59 
     60 	while [ -z "$newpasswd2" ]; do
     61 		read -s -p "Retype MMC password: " newpasswd2; echo
     62 	done
     63 	if [ "$newpasswd" != "$newpasswd2" ]; then
     64 		echo "*** Passwords do not match."
     65 		exit 1
     66 	fi
     67 
     68 	if ! keyctl update $keyid "$oldpasswd$newpasswd"; then
     69 		echo "*** Wrong password!"
     70 		exit 1
     71 	fi
     72 
     73 	# Clear session keyring
     74 	# FIXME: It assumes we have only the MMC key there
     75 	keyctl clear -3
     76 
     77 	echo "Password changed."
     78 }
     79 
     80 change_password || exit $RC
     81