About

Welcome to Allan's Ramblings!

Blogging about Technology and more.

Who am I?

Tag cloud

Archives

01 Mar - 31 Mar 2008
01 Apr - 30 Apr 2008
01 May - 31 May 2008
01 Jun - 30 Jun 2008
01 Aug - 31 Aug 2008
01 Sep - 30 Sep 2008
01 Oct - 31 Oct 2008
01 Nov - 30 Nov 2008
01 Feb - 28 Feb 2009
01 Mar - 31 Mar 2011
01 Jan - 31 Jan 2012

Calendar

« February 2012
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Links

The Active Network
Partners For Haiti
One Mile Clinic PNG

Search!

Last Comments

Allan Nienhuis (Cisco VPN for Win…): The Shrew.net client supp…
Allan Nienhuis (Cisco VPN for Win…): I updated the article wit…
Allan Nienhuis (Cisco VPN for Win…): I tried installing the sh…
allan (Javascript intell…): when MS ships Jquery with…

Stuff

Powered by Pivot - 1.40.5: 'Dreadwind' 
XML: RSS Feed 
XML: Atom Feed 

« Speeding up the build… | Home | Learning another lang… »

Cisco VPN for Win7 x64

09 08 09 - 00:42

The Cisco VPN client won't run on 64bit versions of windows, and Cisco has no plans to ship a 64 bit client anytime soon.  In order to get VPN working on my shiny new Windows 7 x64 install, I tried to get the Cygwin/linux vpnc client working.  I ran into a number of problems, so this post explains how it can be done and hopefully will help you avoid the same problems I had.  I spent a lot of time researching information on the 'net, and wound up tweaking steps a bit and hacking scripts myself, but much of this is based on work by Li Zhao and Salty.

NOTE: update 22 Mar 2010 - The Shrew.net client supports Win7 now, and seems to work flawlessly. It’s a much better option if you don’t already have a need for Cygwin. 


To get Cisco VPN working on an x64 Windows 7, you need:

  • Cygwin - a wonderful set of tools to emulate a linux environment on windows
  • OpenVPN - to provide a virtual TAP network adapter
  • VPNC - the VPN Client
Here's how to do it:
I turned off UAC for the purposes of getting all of this installed.  I ran into a number of permissions issues and false starts when I left it turned on.  This reduces the number of things that can go wrong in the install process, particularly with Cygwin.  Feel free to turn UAC back on after the install process if you're so inclined. 

Install Cygwin:
  • Download cygwin http://www.cygwin.com/setup.exe installer and save to your hard drive (don't just run it directly)
  • Right-click on the setup file, and 'Run as administrator'. This may not actually be neccesary but it makes me feel good.
  • Accept defaults except for local packages directory - I changed that to c:\cygwin\packages.  Saving stuff to my desktop is annoying.
  • Choose a mirror to download packages from.  Choose something physically close to you.
  • Choose the following additional packages to include:  (choose them by clicking on the word 'skip' in the 'New' column)
    • Devel > gcc-g++: C++ Compiler
    • Devel > make: The GNU version of the 'make' utility
    • Libs > libgcrypt: A general purpose crypto library based on the code from GnuPG
    • Libs > libgcrypt-devel: A general purpose crypto library based on the code from GnuPG (development)
    • Libs > libgpg-error: A library that defines common error values for GnuPG
    • Perl > perl: Larry Wall's Practical Extraction and Reporting Language
  • The rest of the cygwin install process is pretty obvious; just a couple more mouse clicks.
Install OpenVPN:
  • Download the latest OPENVPN release candidate from http://openvpn.net/index.php/open-source/downloads.html
  • Save it to your hard drive somewhere you can find it.
  • Make sure to run the installer as an administrator and in windows vista compatibility mode:  (this IS neccesary!!)
    • Open up windows explorer to that location.
    • Right click on the file you saved, and select 'properties'
      • Select the 'compatibility' tab
      • In the Compatibility mode section, check the box 'Run this program in compatibility mode for:', choose Windows Vista (service pack 2)
      • In the Privilege Level section, check the box 'Run this program as an administrator'
      • OK/Apply the settings.
  • Now run the installer.  Agree to the license agreement. 
  • Uncheck all of the options EXCEPT for: 'TAP Virtual Ethernet Adapter', and 'add shortcuts to Start Menu' (in case you want to add another vpn connection)
  • Install to default location.
  • The installer should have created a TAP adapter in Control PanelNetwork and InternetNetwork Connections.  It's probably called Local Area Connection 2.  You NEED to rename it to something without a space in the name and something you'll remember.  I called mine 'CiscoVPN'.

Build and install VPNC:
  • Download the latest release of vpnc from : http://www.unix-ag.uni-kl.de/~massar/vpnc/ I got http://www.unix-ag.uni-kl.de/~massar/vpnc/vpnc-0.5.3.tar.gz
  • Save the file to a convenient temporary location, such as c:\cygwin\tmp
  • Right click on the Cygwin Bash Shell shortcut (should be on your desktop and/or start menu) and select 'Run as administrator' to open up a cygwin bash command prompt.  IT IS CRITICAL THAT YOU RUN THIS AS ADMINISTRATOR OR YOU WILL FAIL AT CERTAIN POINTS IN THIS PROCESS SILENTLY!!!
  • Now extract the contents of the file and change to the extracted folder:
$ cd /tmp
$ tar xvfz vpnc<tab>
$ cd vpnc<tab>
  • Now, compile it with make:
$ make
$ make PREFIX=/usr install
$ mkdir /var/run/vpnc
  • For or some reason my own Cygwin install did not put /usr/sbin into the 'path' environment variable.  Not sure why that is.  You could add c:\cygwin\usrs\bin into your system path via advanced system properties in Windows, but here's how I fixed it:  I edited my .bashrc file (found in your 'home' directory: /home/<username>/.bashrc ), and added these two lines:
export PATH=${PATH}:/usr/local/bin
export PATH=${PATH}:/usr/sbin/ 
  • You'll want to logout out of the bash shell and login again to have that take effect.  REMEMBER TO 'RUN AS ADMINISTATOR'
  • You can check to make sure you can 'find' vpnc with this command:
$ which vpnc
/usr/sbin/vpnc
Repair the VPN Routing configuration script:
  • This is the bit that's broken in Win 7, or perhaps all x64 bit OS.  The script in question is: /etc/vpnc/vpnc-script-win.js.  I've posted my updated script here: Note that I added a bunch of debugging information to the script.  You can make it much quieter by removing or commenting out the two echo commands inside the run function definition on lines 17 and 19.
  • The script supplied with vpnc relies on the execution of the "route print" command to extract the default gateway on this computer.  For some reason the results of that command do not format the default gateway information in Win 7 x64 in the expected manner (perhaps other versions as well - I've seen references to this problem with Vista x64).
  • To fix the script, you need to replace the function getDefaultGateway with this one I hacked together:

function getDefaultGateway()
{
    var output =   run( "route print 0.0.0.0"  ) ;
    var pos = output.indexOf("0.0.0.0          0.0.0.0      ") + 30;
    var gw = output.substring(pos,pos+15); // max length of ip address
    gw = gw.substring(0,gw.indexOf(" ")); // trim at first space...
    echo("Default Gateway: [" + gw + "]");
    return gw;   
}

  • I suck at regular expressions so I didn't try to use them for this.  If you're better with regular expressions than I am feel free to post a comment with an improved function. 
  • I also found it neccessary to add a smal pause to the script before adding the internal routes. Without the pause, the 'route add' commands were not adding correct routes in every case. 

echo("Pausing for 4 seconds to allow the adapter to register itself correctly and therefore correct routing inferences made. You may need to supply a longer delay.");
 WScript.Sleep(4000); 

  • I put that sleep command just before line: if (env("CISCO_SPLIT_INC")) { 
  • I also noticed that after disconnecting (ctrl-c), there were still stray routes in the route table.  I'm not sure that it matters because the route to the main vpn gateway is properly removed, but I went ahead and added some code to remove all of the routes added by the script when disconnecting:

run("route delete " + env("VPNGATEWAY") + " mask 255.255.255.255");
 
 //remove internal network routes
 if (env("CISCO_SPLIT_INC")) {
  for (var i = 0 ; i < parseInt(env("CISCO_SPLIT_INC")); i++) {
   var network = env("CISCO_SPLIT_INC_" + i + "_ADDR");
   run("route delete " + network );
  }

  • Alternatively, I've posted an updated file here: Just copy that to your /etc/vpnc folder.
Create your VPNC Configuration file:
  • You need to convert your old Cisco .pcf file into a config file for vpnc in order to get the shared secret included in that file carried over correctly, and to make sure you have the ip address of the vpn gateway, etc.  So, first copy your existing cisco .pcf file into somewhere convenient.  /tmp is pretty convenient. Then run the pcf2vpnc utility:
$ cd /tmp
$ pcf2vpnc <old Cisco filename>.pcf /etc/vpnc/<profilename>.conf
  • <profilename> is whatever unique name you want it to be.  Note that we're saving the new configuration file to /etc/vpnc.  You could always copy the created file to that location later.
  • Now, edit the file it created with your favorite unix friendly editor.  Windows Notepad is no good.  Go download Notepad++ right now; I'll wait.  Got it? OK. Open the file /etc/vpnc/<profilename>.conf
  • You'll need to add a few items to the file:
Interface name <NameOfTheInterfaceYouPickedEarlier> # mine is: CiscoVPN
Interface mode tap
Pidfile /var/run/vpnc/<uniqueName>.pid # need a unique one per profile, so may as well use <profilename>.pid
Local Port 0  #auto selects a port
NAT Traversal Mode force-natt
No Detach
  • You really shouldn't do it, but you can also enter your password in this config file if you don't mind that password being there in plain text. The syntax for that is:
Xauth password <yourpassword>  # You've got a secure computer, right? Really? Are you sure?
  • If you have any trouble, you can add a debug flag to your config file:
Debug 1     # valid values: 1-3, 99.  99 = everything, including authorization information (passwords), so be careful

Putting it all together:
  • Actually there's not much to put together, you just need to use your shiny new vpnc command:
$ vpnc <profileNameWithoutExtension>
  • You could drop that command into an executable file to save a few keystrokes.  I'll leave figuring out how to launch the cygwin bash shell and executing that command from a windows batch file (and so an icon on your desktop) up to you.  


I hope this works for you, but I can't guarantee anything!  Feel free to post comments with your experiences.

Update 10 Aug 09:

I have had issues with routing within the network if the vpn concentrator provides me with a new IP address.  I'm not sure exactly why that happened or what to do in order to fix the routing - I'm not a network routing guru.  I did figure out how to work around this issue though.  In Control Panel\Network and Internet\Network Connections I went to the TCP/IPv4 settings and switched to dhcp ('obtain an IP address automatically, Obtain DNS server address automatically).  These settings are overwritten when connecting to the vpn again, but for some reason making that change clears out something so that when connecting via vpnc the routing works again.  For today anyways. :)

Cheers, 

Allan

Update 11 Aug 09:
I forgot to mention that in my research, this VPN client: http://www.shrew.net/software was mentioned by a number of folks as a valid free alternative.  It actually looks pretty good, but I didn't try it, as I wanted to get the vpnc option figured out.  I always install cygwin on my windows boxes so I didn't mind going down this route.  If anyone has experience with the shrewsoft client on x64 bit windows, please comment here.
Used tags:
three comments

I tried installing the shrew.net client today, and got bluescreens on boot on Win7 ×64. To be fair to Shrew.net, they only claim vista x64 support. So we’ll wait and see when they come out with Win7 support. Thank goodness for Windows restore points!
Allan Nienhuis () (URL) - 17 08 09 - 15:34

I updated the article with a small tweak to the script to fix cases when my routes weren’t being created properly. The route add command was running correctly, but the routing tables weren’t updated correctly. The route command does some type of assessment of how to apply the route add command based on your current network configuration, and I believe some type of adapter initialization wasn’t always being finished in time before the route add commands were being run. I noticed this when testing when I saw a brief flash of the ‘wait’ cursor while the script was running. The ‘fix’ was to simply put a few second delay in place, which is really just a hack. If anyone has an idea of what could actually be tested for before continuing with adding routes, or alternatives to the route add commands to force the correct routing, please reply here. FYI, I tried specifying both the metric and the adapter and did not see any difference in behavior.
Allan Nienhuis () (URL) - 19 08 09 - 07:34

The Shrew.net client supports Win7 now, and seems to work flawlessly. It’s a much better option if you don’t already have a need for Cygwin. I understand that Cisco has published a 64bit client as well, but I’ve not tested that.
Allan Nienhuis - 22 03 10 - 10:14


  
Remember personal info?

Emoticons / Textile


 

  (Register your username / Log in)

Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.