I'm trying to write a script which will establish an openvpn tunnel when the computer boots up. The main problem lies in inputting the pkcs12 password. I realise it's very bad practice to have a password stored in plain text, but I'm not too fussed about that -- the computer is very secure in all other respects so I'm pretty confident that nobody but me will be accessing it to view the password.
I have added the
--management and the
--management-query-passwords options so that the password can be input via a telnet session. This works fine when I do it manually, but when I try and do it automatically with a bash script it fails. My guess would be that either I am not doing the carridge return after the password line properly, or that some other garbage values are sneaking in to the telnet session as inputs. Here is the relevant bits of code (xxx for stuff that is classified):
$ cat user.ovpn #OpenVPN Server conf tls-client client dev tun proto udp tun-mtu 1400 remote xxxxxxxxxxxxxxxxxxx 1194 pkcs12 user.p12 cipher AES-256-CBC comp-lzo verb 3 ns-cert-type server tls-remote xxxxxxxxxxxxxxxxxxxxxxx management 127.0.0.1 5558 management-query-passwords $ cat telnet_commands.sh #!/bin/bash echo "open 127.0.0.1 5558" sleep 1 echo -e "password 'Private Key' xxxxxxxxxx\r\n" $ nohup openvpn user.ovpn & $ ./telnet_commands.sh | telnet $ #manually check whether this worked: $ telnet 127.0.0.1 5558 Escape character is '^]'. >INFO:OpenVPN Management Interface Version 1 -- type 'help' for more info >PASSWORD:Need 'Private Key' password
Obviously this is not working -- the openvpn telnet management interface is still waiting for the password to be entered.