1#!/usr/bin/expect -f 2######################################################################## 3# The Initial Developer of the Original Code is International 4# Business Machines Corporation. Portions created by IBM 5# Corporation are Copyright (C) 2007 International Business 6# Machines Corporation. All Rights Reserved. 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the Common Public License as published by 10# IBM Corporation; either version 1 of the License, or (at your option) 11# any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# Common Public License for more details. 17# 18# You should have received a copy of the Common Public License 19# along with this program; if not, a copy can be viewed at 20# http://www.opensource.org/licenses/cpl1.0.php. 21# 22# 23# Program: tpm_changeownerauth01.sh 24# Purpose: Test transitions between plain text, unicode and well-known 25# for Owner and SRK passwords, using tpm_changeownerauth from tpm-tools 26# package. 27# Pre-Conditions: Owner and SRK password must be set to a plain text 28# password before running this test. 29# 30# Author: Ramon Brandão <ramongb@br.ibm.com> 31# Date: Nov/07 32# 33######################################################################## 34 35set timeout -1 36set options {"-s" "-o"} 37 38# States if the current owner password is the Well Known secret 39set wnOpt "" 40# States if the crrent owner password is a Unicode one 41set isU "" 42 43#Prompts for the owner and SRK Passwords 44send_user "Enter the current Owner Password: " 45expect_user -re "(.*)\n" 46set ownerPasswd $expect_out(1,string) 47send_user "Enter the current SRK Password: " 48expect_user -re "(.*)\n" 49set SRKPasswd $expect_out(1,string) 50 51# Start of changeauth tests 52foreach opt $options { 53 54 if {$opt == "-s"} { 55 send_user "\n\n#############################################################\n" 56 send_user "####### Testing tpm_changeownerauth for SRK password:########\n" 57 send_user "#############################################################\n\n" 58 } else { 59 send_user "\n\n###############################################################\n" 60 send_user "####### Testing tpm_changeownerauth for OWNER password:########\n" 61 send_user "###############################################################\n\n" 62 } 63 64 # Plaintext -> Unicode 65 puts stdout "Test 1) tpm_changeownerauth \"$opt\": Changing password from PLAINTEXT to UNICODE:" 66 spawn tpm_changeownerauth $opt -n -l debug 67 sleep 1 68 expect "Enter owner password" { 69 exp_send "$ownerPasswd\r" 70 if {$opt == "-s"} { 71 expect "Enter new SRK" { 72 exp_send "$SRKPasswd\r" 73 expect "Confirm" { 74 exp_send "$SRKPasswd\r" 75 } 76 } 77 } else { 78 expect "Enter new owner" { 79 exp_send "$ownerPasswd\r" 80 expect "Confirm" { 81 exp_send "$ownerPasswd\r" 82 set isU "-g" 83 } 84 } 85 } 86 expect { 87 "ngeAuth success" { 88 expect "Tspi_Context_Close success" { 89 send_user "PLAINTEXT to UNICODE auth change SUCCEED. \n\n" 90 } 91 } 92 "*Auth*ailed" { 93 expect "Tspi_Context_Close success" { 94 send_user "PLAINTEXT to UNICODE auth change FAILED. \n\n" 95 } 96 } 97 } 98 99 } 100 sleep 4 101 102 # Unicode -> plaintext 103 puts stdout "Test 2) tpm_changeownerauth \"$opt\": Changing password from UNICODE to PLAINTEXT:" 104 spawn tpm_changeownerauth $opt $isU -l debug 105 sleep 1 106 expect "Enter owner password" { 107 exp_send "$ownerPasswd\r" 108 if {$opt == "-s"} { 109 expect "Enter new SRK" { 110 exp_send "$SRKPasswd\r" 111 expect "Confirm" { 112 exp_send "$SRKPasswd\r" 113 } 114 } 115 } else { 116 expect "Enter new owner" { 117 exp_send "$ownerPasswd\r" 118 expect "Confirm" { 119 exp_send "$ownerPasswd\r" 120 set isU "" 121 } 122 } 123 } 124 expect { 125 "ngeAuth success" { 126 expect "Tspi_Context_Close success" { 127 send_user "UNICODE to PLAINTEXT auth change SUCCEED. \n\n" 128 } 129 } 130 "*Auth*ailed" { 131 expect "Tspi_Context_Close success" { 132 send_user "UNICODE to PLAINTEXT auth change FAILED. \n\n" 133 } 134 } 135 } 136 } 137 sleep 4 138 139 # Plaintext -> Well Known 140 puts stdout "Test 3) tpm_changeownerauth \"$opt\": Changing password from PLAINTEXT to WELL KNOWN:" 141 spawn tpm_changeownerauth $opt -r -l debug 142 sleep 1 143 expect "Enter owner password" { 144 exp_send "$ownerPasswd\r" 145 if {$opt == "-o"} { 146 set wnOpt "-z" 147 } 148 expect { 149 "ngeAuth success" { 150 expect "Tspi_Context_Close success" { 151 send_user "PLAINTEXT to WELL KNOWN auth change SUCCEED. \n\n" 152 } 153 } 154 "*Auth*ailed" { 155 expect "Tspi_Context_Close success" { 156 send_user "PLAINTEXT to WELL KNOWN auth change FAILED. \n\n" 157 } 158 } 159 } 160 } 161 sleep 4 162 163 # Well Known -> Unicode 164 puts stdout "Test 4) tpm_changeownerauth \"$opt\": Changing password from WELL KNOWN to UNICODE:" 165 spawn tpm_changeownerauth $opt $wnOpt -n -l debug 166 sleep 1 167 if {$wnOpt != "-z"} { 168 expect "Enter owner password" {exp_send "$ownerPasswd\r"} 169 } 170 if {$opt == "-s"} { 171 expect "Enter new SRK" { 172 exp_send "$SRKPasswd\r" 173 expect "Confirm" { 174 exp_send "$SRKPasswd\r" 175 } 176 } 177 } else { 178 expect "Enter new owner" { 179 exp_send "$ownerPasswd\r" 180 expect "Confirm" { 181 exp_send "$ownerPasswd\r" 182 set wnOpt "" 183 set isU "-g" 184 } 185 } 186 } 187 expect { 188 "ngeAuth success" { 189 expect "Tspi_Context_Close success" { 190 send_user "WELL KNOWN to UNICODE auth change SUCCEED. \n\n" 191 } 192 } 193 "*Auth*ailed" { 194 expect "Tspi_Context_Close success" { 195 send_user "WELL KNOWN to UNICODE auth change FAILED. \n\n" 196 } 197 } 198 } 199 sleep 4 200 201 # Unicode -> Well Known 202 puts stdout "Test 5) tpm_changeownerauth \"$opt\": Changing password from UNICODE to WELL KNOWN:" 203 spawn tpm_changeownerauth $opt $isU -r -l debug 204 sleep 1 205 if {$wnOpt != "-z"} { 206 expect "Enter owner password" {exp_send "$ownerPasswd\r"} 207 } 208 if {$opt == "-o"} { 209 set wnOpt "-z" 210 } 211 expect { 212 "ngeAuth success" { 213 expect "Tspi_Context_Close success" { 214 send_user "UNICODE to WELL KNOWN auth change SUCCEED. \n\n" 215 } 216 } 217 "*Auth*ailed" { 218 expect "Tspi_Context_Close success" { 219 send_user "UNICODE to WELL KNOWN auth change FAILED. \n\n" 220 } 221 } 222 } 223 224 sleep 4 225 # Well Known -> Plain - return to the starting state 226 puts stdout "Test 6) tpm_changeownerauth \"$opt\": Changing password from WELL KNOWN to PLAIN:" 227 spawn tpm_changeownerauth $opt $wnOpt -l debug 228 sleep 1 229 if {$wnOpt != "-z"} { 230 expect "Enter owner password" {exp_send "$ownerPasswd\r"} 231 } 232 if {$opt == "-s" } { 233 expect "Enter new SRK" { 234 exp_send "$SRKPasswd\r" 235 expect "Confirm" { 236 exp_send "$SRKPasswd\r" 237 } 238 } 239 } else { 240 expect "Enter new owner" { 241 exp_send "$ownerPasswd\r" 242 expect "Confirm" { 243 exp_send "$ownerPasswd\r" 244 } 245 } 246 } 247 expect { 248 "ngeAuth succes" { 249 expect "Tspi_Context_Close success" { 250 send_user "WELL KNOWN to PLAIN auth change SUCCEED. \n\n" 251 } 252 } 253 "*Auth*ailed" { 254 expect "Tspi_Context_Close success" { 255 send_user "WELL KNOWN to PLAIN auth change FAILED. \n\n" 256 } 257 } 258 } 259 sleep 4 260} 261 262