Auto authenticate program for OpenVPN gui @ tk here on Saturday, March 25, 2006 1:46 PM
Google
You could also try tk Social Bookmarking Search or tk Video Search!

Saturday, March 25, 2006

Auto authenticate program for OpenVPN gui

Yesterday I was scouring the web for a way to automatically save my username and password for OpenVPN. OpenVPN, as the name suggests is an open source VPN client. While I don't really care for the TLS security that is supposed to be better than other clients, the higher powers have given strict orders to use it in order to secure my connection. Generally I hate to listen to them, but wireless security as you all may know, is not something you should bet your life on. There's no other way to connect either, so I was stuck with OpenVPN (not that this is a bad thing) or no connection at all (which is not a good thing).

So I've been using OpenVPN for a while now and everything works great. I'm using the windows gui version so the OpenVPN console won't irritate me constantly in my taskbar. And I start to notice this incredibly annoying thing that happens constantly. For some reason, my OpenVPN connection drops frequently. I do mean frequently, like 5 minutes or so. So I'll be typing stuff and this nice little dialog box will pop up asking for my username and password. Ok, it doesn't do this all the time, sometimes it'll reconnect with my authentication details and all is well. But when it wants to annoy me (and I don't know why sometimes it asks for my details and sometimes it doesn't), it'll ask me for those details everytime a connection is dropped.

And so I thought, hey, this is a gui, so there must be a way to save those details. Except there isn't any way to do that. The only way is to download around 5 packages and recompile the whole damn thing! Ok, so I stay cool headed and figure that they must offer a download with the save password option enabled. Off to their website I go, sniffing around for the hidden treasure. Nope, nothing there and I head into their forums and what do I see? A forum post stating that they do not offer that download and you'll have to go down the recompile route! The reason? They don't want users to undermine the admin's intentions by saving passwords in cleartext on their computer (I understand why). In another post, I see an OpenVPN user saying he saves his password in cleartext on his computer because he chooses cryptic passwords.

At this time, my head was about to explode. I turned to Google for help and found basically the same answer - recompile. Was I about to spend hours of my life wasted on trying to recompile something just to save my passwords? Nope. Instead Google came to my rescue once again as I found something called AutoHotkey which allows you to automate certain tasks. With this handy software, I created a simple script to fill in my username and password automatically when OpenVPN asks for it. The best part is that it allows you to build a program from that script and you can use it however you like.

Here's the script I wrote:

#Persistent
SetTimer, EnterAuth, 250
return

EnterAuth:
Process, wait, openvpn-gui.exe, 2
If %ErrorLevel% = 0
{
Run, %A_Programs%\OpenVPN\YourShortcuthere.lnk
Sleep, 2000
}
IfWinExist OpenVPN - User Authentication
{
ControlSetText, Edit1, YourUsernamehere, OpenVPN - User Authentication ahk_class #32770
ControlSetText, Edit2, YourPasswordhere, OpenVPN - User Authentication ahk_class #32770
ControlSend, Edit1, {Enter}, OpenVPN - User Authentication ahk_class #32770
}
return


What you need: AutoHotkey and the above script saved as a .ahk file.

What you need to change: YourShortcuthere.lnk, YourUsernamehere and YourPasswordhere.

What you need to do:

Option 1 - If you know what an .ovpn file is and where it's located (Confident users)

1. Create a shortcut in your OpenVPN start menu folder with these parameters: "--connect something.ovpn". This shortcut will run OpenVPN gui using settings in the specified .ovpn file. The .ovpn file is a config file for OpenVPN and is normally located in the folder where you installed OpenVPN.

2. Change YourShortcuthere.lnk to whatever you called that shortcut.

3. Then change YourUsernamehere and YourPasswordhere to your own username and password and run the autohotkey compiler to create an exe file.

4. Run the created executable and enjoy!

Option 2 - If you don't have an .ovpn file, or can't find it or just want things to work (Conservative users)

1. Download this AutoHotKey script for OpenVPN gui. This assumes you have only have one type of OpenVPN connection (true for most people). Please note that I'm also assuming you've installed OpenVPN gui in the default installation directory. Otherwise leave a comment and I'll fix you up with the proper code.

2. Open the file in notepad (or your favorite text editor) and change YourUsernamehere and YourPasswordhere to your own username and password and run the autohotkey compiler to create an exe file. Don't worry about the compiling, it's very easy to use. If you need help on this step, leave a comment.

3. Run the created executable and enjoy!


ps: If you change your password often, you could change the program to ask for your username and password and save these details into a text file. As long as there is a password file, the program will use those details. Delete that file and the program will request for them again.

Categories:
Tech

 

14 people had something to say! Why don't you join in? The more the merrier!

On 14 May, 2007 11:11, Anonymous said...

Yep, know what you mean, very frustrating.

I would prefer it to just run as a service and log on without any user intervention.

I went down a similar path as you initially and wrote a batch file using an MS util called scriptit, which does a the same sort of thing as AutoHotKey. I wasn't comfortable with the password being stored in a clear text file, so I wrote a compiled app in Visual Dialog Script with the password compiled in the exe. It's better, but not impossible to get the password from it.

No matter what you do, auto entering a saved password will undermine the security of OpenVPN, according to the developers.

On 22 September, 2007 19:37, Oliver said...

Hi - enjoyed your post - facing the same problem, but a bit of a techno idiot! Wonder if you could go through the steps once more very clearly, as I'm getting stuck on the "make a shortcut bit"!

Thanks

On 22 September, 2007 19:50, tk said...

Hi oliver, just hang on a bit while I create some screenshots of what to do.

On 22 September, 2007 20:54, tk said...

Ok, I lied about the screenshots since I've simplified some things. If you need help with compiling the script to an exe file, I'll definitely provide some screenshots this time. :)

On 19 January, 2008 13:19, Rasel Hasa said...

Good Job. I was exactly Searching this solution. Special Thanks for the script.

On 13 June, 2008 06:25, Anonymous said...

Why not use the cryptoapicert option in the ovpn file - which allows you to save the user's certificate in their Windows certificate store? Then it never asks for the password. You provided the password once to install the certificate on the computer, and therefore, it trusts your computer

On 23 July, 2008 10:21, Anonymous said...

Hey, I had the same problem, I was tired of typing in that password in the OpenVPN GUI from their website, so I wrote a new GUI with some nice features... (autoconnect, autoreconnect, save password, status window, etc)

It's written in .NET 3.5 btw

screenshots:
http://basj.org/vpngui/

if anyone is interested, mail me: sveini at horve dot no

On 24 July, 2009 04:50, Anonymous said...

Great solution, I've spent ages trying to bypass the idiot decision of OpenVPN being unable to read name/pass from file.

Anyway Basj client is great but doesn't work under W7.

Also some comments:

1) Nowadays the name of the file is "openvpn-gui-1.0.3.exe" not "openvpn-gui.exe"

2) "%A_Programs%" doesn't work for me (don't know why); I just replaced it with (old DOS school) "c:\Progra~1\" ...

3) There's no reason to have the program running after the connection is started (reconnection is a handled by openvpn-gui). So at the end of the script just replace "return" with "ExitApp"

On 05 October, 2009 10:16, Anonymous said...

i have several .ovpn files so how do i figure it out?

On 17 November, 2009 11:45, Anonymous said...

Hi, I cant get it to work. I copied the file, edited it correctly and compiled it. Open VPN launches correctly when I click the newly created executable but the window sits there asking me for my Username/password. I am on Vista

On 11 November, 2010 07:28, ASIF said...

please give compiling method

On 06 September, 2011 03:21, Anonymous said...

Thanks a lot!!

On 13 September, 2011 07:18, Anonymous said...

thanks a million for the work into automating a mindless task.
a few sugesstions which could possibly improve the second dumber option for people like me,
1) the openvpn gui has now been updated so needs updating on two different lines of script before compiling and
2)the "% sign does not work for win7 ( ? reason)instead as suggested already C:\ works like a charm
3) the default folder on the line 8 of the script refers to program files, the default for win7 64 bit is the x86 program folder .
these changes made it work like a charm
once again thanks a lot
3) the

On 03 September, 2012 20:33, Anonymous said...

I'd rather use the tool from
http://hmastuff.com/#2
to login automatically to openvpn gui app

Google
You could also try tk Social Bookmarking Search or tk Video Search!