public void Authenticate()
 {
     if (httpClient != null)
     {
         this.tokenSource   = new CancellationTokenSource();
         authenticationTask = AuthenticateProcess();
     }
     else
     {
         ShrewNotifier.Log("WEB connection error for Authentication ...", ShrewConnectionStatus.Disconnected);
     }
 }
        private async Task <bool> tryAuth()
        {
            bool authenticated = false;

            ShrewNotifier.Log("Trying to auth on " + this.credentials.formLogin + " ...", ShrewConnectionStatus.Pending);
            try
            {
                Uri formUri = null;
                using (HttpResponseMessage response = await httpClient.GetAsync(this.credentials.formLogin))
                {
                    String content = await response.Content.ReadAsStringAsync();

                    formUri = response.Headers.Location;
                }
                String username = regexUserName.Match(this.credentials.username).Groups["username"].Value;
                String password = this.credentials.password;

                using (HttpResponseMessage response = await httpClient.GetAsync(formUri))
                {
                    String content = await response.Content.ReadAsStringAsync();

                    bool status = response.IsSuccessStatusCode;
                }
                String url   = formUri.AbsoluteUri.Replace(formUri.PathAndQuery, "/");
                String token = formUri.Query.Substring(1);

                var data = new Dictionary <string, string>
                {
                    { "4Tredir", this.credentials.formLogin },
                    { "magic", token },
                    { "username", username },
                    { "password", password }
                };
                using (HttpResponseMessage response = await httpClient.PostAsync(url, new FormUrlEncodedContent(data)))
                {
                    String content = await response.Content.ReadAsStringAsync();

                    authenticated = response.IsSuccessStatusCode;
                }
            }
            catch (Exception exc)
            {
                authenticated = false;
                ShrewNotifier.Log("Auth: " + exc.Message, ShrewConnectionStatus.Disconnected);
            }
            return(authenticated);
        }
 private Task AuthenticateProcess()
 {
     return(Task.Run(async() => {
         int failedAuthAttempts = 0;
         Boolean authenticated = false;
         await Task.Delay(STARTER_DELAY, tokenSource.Token);
         while (!(authenticated = await tryAuth()) && ++failedAuthAttempts <= RETRY_MAX && !tokenSource.IsCancellationRequested)
         {
             ShrewNotifier.Log("Auth retry #" + failedAuthAttempts + " of " + RETRY_MAX + " in " + RETRY_INTERVAL_MS + " ms ...", ShrewConnectionStatus.Pending);
             await Task.Delay(RETRY_INTERVAL_MS, tokenSource.Token);
         }
         if (authenticated)
         {
             ShrewNotifier.Log("Auth on " + this.credentials.formLogin + " done.", ShrewConnectionStatus.Connected);
         }
         else
         {
             ShrewNotifier.Log("Auth on " + this.credentials.formLogin + " failed!", ShrewConnectionStatus.Disconnected);
         }
         ShrewNotifier.Log("------------------------------------------------", ShrewConnectionStatus.Pending);
     }, tokenSource.Token));
 }
Beispiel #4
0
        internal void ExecuteClient()
        {
            string args = string.Format(SHREW_ARGS,
                                        credentials.siteConfigPath,
                                        credentials.username,
                                        credentials.password);

            ProcessStartInfo psi = new ProcessStartInfo(@"C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe", args);

            psi.UseShellExecute = true;
            Process clientProcess = new Process();

            clientProcess.StartInfo = psi;
            ShrewNotifier.Log("Starting new vpn client.", ShrewConnectionStatus.Pending);
            hwndShrew = IntPtr.Zero;
            clientProcess.Start();
            Thread.Sleep(1000);
            if (!this.shrewVisible)
            {
                HideShrew();
            }
        }