(nothing here yet)
RJ Bacon (with a Major Company providing Internet services) suggests an approach to avoiding embedded passwords in Expect scripts. Feel free to format this for reaper friendly and improve/fix.
Procedure to prompt for key - shameless pilfer from Mr. Libes' "Exloring Expect"
proc getpass pwprompt { set oldmode [stty -echo -raw] send_user "\n $pwprompt" set timeout -1 expect_user -re "(.*)\n" send_user "\n" eval stty $oldmode return $expect_out(1,string) }
Procedure to encrypt device passwords
proc utility_encrypt {pd filename} { global key HOME catch [exec echo "$pd" | des -e -k $key -b > $HOME/pwdir/$filename] return }
Procedure to decrypt device passwords
proc utility_decrypt filename { global key HOME catch {exec cat $HOME/pwdir/$filename | des -d -b -k $key} dpd return $dpd }
You can use utility_encrypt in a setup program, and provide functionality that allows new passwords to be added to the encrypted files as they are implemented.
Lets assume the encrypted password files are organized by device type and separated with "\n". Then the mechanics of the program look something like this:
#user launches program to log into a Foo systems Bar device: ... proc foo_login_proc {device_name} { global key sid set decrypted_all [utility_decrypt foo_passwords.enc] for {set i 0} {$i <= [llength $decrypted_all]} {incr i} { set foo_pws($i) [lindex $decrypted_all $i] } #loop through foo_pws array using exp_send/expect until login successful... interact exit } ... set user [exec whoami] set key [getpass "Enter password for $user: "] spawn -noecho telnet foo1.bar set sid($device_name) $spawn_id detect_device_prompt ;# expect proc that detects this is a foo device and launches the appropriate proc ...
[Start by looking at source protection.]
[Follow up by locating information about writing secure Tcl scripts]
Finally, consider using interactive prompting rather than hard coding passwords ...