#!/usr/bin/expect -f set timeout 5 set send_slow {10 .001} set sshUser "sshuser" set sshIP "192.168.1.254" set sshPass "sshPass12345" set exportPass [exec cat /scripts/vpncert-asa.txt] #set log "/root/vpncert.log" #log_file -noappend $log #log_user 0 spawn ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=+ssh-rsa -o StrictHostKeyChecking=no $sshUser@$sshIP expect "password:" send -- "$sshPass\r" expect ">" send -- "enable\r" expect "Password:" send -- "$sshPass\r" expect "#" #log_user 1 send -- "configure terminal\r" expect "(config)#" send -- "no crypto ca trustpoint ca_le\r" expect { "]:" {send -- "yes\r"; exp_continue} "(config)#" } send -- "crypto ca trustpoint ca_le\r" expect "trustpoint)#" send -- "enrollment terminal\r" expect "#" send -- "exit\r" expect "(config)#" #log_user 0 send -- "crypto ca import ca_le pkcs12 $exportPass\r" expect "itself:" send -- [exec cat /root/gate.base64]\n send -s "quit\r" # % The CA cert is not self-signed. # % Do you also want to create trustpoints for CAs higher in the hierarchy? [yes/no]: # OR # % You already have RSA or ECDSA keys named ca_le. # % If you replace them, all device certs issued using these keys # % will be removed. # % Do you really want to replace them? [yes/no]: expect { "]:" {send -- "yes\r"; exp_continue} "(config)#" } #log_user 1 send -- "ssl trust-point ca_le outside\r" expect "(config)#" send -- "exit\r" expect "#" send -- "exit\r" expect eof