L2tp connection with PresharedKey

May 18, 2009 at 1:48 PM

Hi all

I want to use a preshared key for my l2tp over ipsec connection entry ( pre-shared key for IPSec authentication).

this is my sample code :

                    entry.UpdateCredentials(RasPreSharedKey.Client, "sharedKey" );
                    entry.ExtendedOptions = RasEntryExtendedOptions.UsePreSharedKey;

when i use RasDialer class too dial l2tp connection , in many cases this error occurs :

"This connection is already being dialed"

I must restart my computer to solve the problem.

furthermore , sometimes  i use a wrong shared key for testing purposes.

why this error occurs?

Is there anythig wrong with this code ?

May 18, 2009 at 3:07 PM

The problem is with the RasDialer component not disposed of properly as stated in the help documentation. With that particular component if Dispose is not called, Windows cannot report status information to the component and the dial attempt hangs; which is what you're experiencing right now. Typically when in development, people like to start dialing the connection and hit stop or abort the process. Windows cannot stop a connection attempt that it hasn't initiated since it (for whatever reason) cannot figure out the handle of the connection.

To resolve your problem, ensure your application ALWAYS calls the Dispose method on that component before the process terminates. And if you are testing something that does dial a connection, ensure you are not terminating the process when you have a connection attempt already pending.

I've made every effort when Dispose is called to ensure any pending connection attempts are cancelled by the component and all resources are released.

May 19, 2009 at 6:32 AM
Edited May 19, 2009 at 9:20 AM

Thanks jeff

my problem not solved.

I dial the connection asynchronously.

Which method is appropriate for calling dialer.Dispose() ?


May 19, 2009 at 1:05 PM

Either dial method (synchronous or asynchronous) will work.

I don't know how your application has been written so I can't give much information, but if you're using Windows Forms and your dialer is defined at the class level you can put dialer.Dispose(); in the Form_Closing event. However, if you're aborting the process there isn't anything I can do about that. You need to ensure you're closing the form properly when working on your software.

May 19, 2009 at 5:16 PM

That's right, thanks

Oct 14, 2009 at 1:11 PM

Hi Jeff, GREAT work on DotRas.

I have the same problem as the original poster, problem is I need to provide preshared key and also user/password.

I see the original method, UpdateCredentials(RasPreSharedKey.Client, "sharedKey" ) is missing from the latest release... Also ExtendedOptions prop. is missing...

Also, if I update credentials twice, once with user/pwd, secon time with preshared key, will the first item be overriden?



Oct 14, 2009 at 2:53 PM

They aren't missing, you just need to make sure you're using the WINXP or higher build. Windows 2000 doesn't support preshared keys which is why it isn't available in the WIN2K build.

As for your other question, I have no idea. You can always try it and let me know so I can make a note of it in the DotRas SDK so others don't have to guess.

Oct 15, 2009 at 7:06 PM
Edited Oct 15, 2009 at 7:07 PM

I downloaded the trunk version of the project, and the methods were there. In the DotRas v1.1 release source code, they are missing :)

Anyway, I fixed my problem, in order to provide both username/password and preshared key, you need to do:

RasEntry entryL2TP = RasEntry.CreateVpnEntry(l2tpConName, ip, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));

entryL2TP.UpdateCredentials(new NetworkCredential(username, password));

entryL2TP.ExtendedOptions = RasEntryExtendedOptions.UsePreSharedKey;
entryL2TP.UpdateCredentials(RasPreSharedKey.Client, sharedKey);

I want to make a small donation because your project saved me quite a lot of time I would have wasted otherwise, with WinAPI. Do you have a donate button somewhere?



Oct 15, 2009 at 10:45 PM

They aren't missing from the source code in the release, you have to add the appropriate compilation symbol to change the version of Windows it's being built for. Those symbols are all defined on the home page of this project if you need to know which are used for what OS.

No I do not have any way of taking donations right now. I have been debating about doing so to help offset the countless hours I've put into this project to get it where it's at today, but as of right now I have nothing available.