// Decompiled with JetBrains decompiler // Type: Rei.Fs.Webdav.PassportAuthHelper // Assembly: Rei.Fs.Webdav, Version=1.13.2.18288, Culture=neutral, PublicKeyToken=null // MVID: D30DD1E3-8520-48B5-AAE5-C87970350A82 // Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\Rei.Fs.Webdav.dll using Microsoft.VisualBasic.CompilerServices; using System; using System.IO; using System.Net; namespace Rei.Fs.Webdav { public class PassportAuthHelper { private static Uri _InitialRedirectorUri = new Uri("https://nexus.passport.com/rdr/pprdr.asp"); private static Uri _LoginUri; public string UserAgent; public int ReadWriteTimeout; public int ConnectTimeout; public CookieContainer CookieContainer; public IWebProxy Proxy; public string GroupName; public static Uri InitialRedirectorUri { get { return PassportAuthHelper._InitialRedirectorUri; } } public static bool CheckPassportAuth(HttpWebResponse res) { return res.StatusCode == HttpStatusCode.Found && res.Headers[HttpResponseHeader.WwwAuthenticate] != null && res.Headers[HttpResponseHeader.WwwAuthenticate].Trim().StartsWith("Passport1.4 "); } private HttpWebRequest CreateRequest(Uri uri) { HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(uri); httpWebRequest.UserAgent = this.UserAgent; httpWebRequest.Proxy = this.Proxy; httpWebRequest.ReadWriteTimeout = this.ReadWriteTimeout; httpWebRequest.Timeout = this.ConnectTimeout; httpWebRequest.CookieContainer = this.CookieContainer; httpWebRequest.ConnectionGroupName = this.GroupName; httpWebRequest.KeepAlive = false; httpWebRequest.PreAuthenticate = false; httpWebRequest.AllowAutoRedirect = false; return httpWebRequest; } public Uri GetPassportLoginUri() { if ((object) PassportAuthHelper._LoginUri != null) return PassportAuthHelper._LoginUri; try { HttpWebRequest request = this.CreateRequest(PassportAuthHelper._InitialRedirectorUri); request.Method = "GET"; using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { string[] strArray = response.Headers["PassportURLs"].Split(','); int num1 = 0; int num2 = checked (strArray.Length - 1); int index = num1; while (index <= num2) { if (strArray[index].Contains("DALogin")) { PassportAuthHelper._LoginUri = new Uri("https://" + strArray[index].Substring(checked (strArray[index].IndexOf("=") + 1))); return PassportAuthHelper._LoginUri; } checked { ++index; } } } throw new UnauthorizedException("Cannot access Passport authentication system.", (Exception) null, false); } catch (Exception ex) { ProjectData.SetProjectError(ex); throw new UnauthorizedException("Cannot access Passport authentication system.", ex, false); } } public string GetPassportToken(HttpWebResponse orgres, string user, string pass) { string str1 = orgres.Headers[HttpResponseHeader.WwwAuthenticate].Trim(); int startIndex = str1.IndexOf(" "); string str2 = str1.Substring(startIndex).Trim(); string str3 = string.Format("Passport1.4 sign-in={0},pwd={1},OrgVerb={2},OrgUrl={3},{4}", (object) Uri.EscapeDataString(user), (object) Uri.EscapeDataString(pass), (object) orgres.Method, (object) orgres.ResponseUri.AbsoluteUri, (object) str2); try { HttpWebRequest request = this.CreateRequest(this.GetPassportLoginUri()); request.Method = "GET"; request.Headers.Add(HttpRequestHeader.Authorization, str3); using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { string str4 = response.Headers["Authentication-Info"].Trim(); string[] strArray = str4.Substring(checked (str4.IndexOf(' ') + 1)).Split(','); int num1 = 0; int num2 = checked (strArray.Length - 1); int index = num1; while (index <= num2) { if (strArray[index].Contains("from-PP")) return "Passport1.4 " + strArray[index]; checked { ++index; } } } throw new UnauthorizedException("Passport login failure", (Exception) null, true); } catch (WebException ex) { ProjectData.SetProjectError((Exception) ex); WebException webException = ex; using (WebResponse response = webException.Response) { using (new StreamReader(response.GetResponseStream())) ; } throw new UnauthorizedException("Passport login failure", (Exception) webException, true); } catch (Exception ex) { ProjectData.SetProjectError(ex); throw new UnauthorizedException("Passport login failure", ex, true); } } public bool ResetConnection() { bool flag = true; if ((object) PassportAuthHelper._LoginUri != null) { ServicePoint servicePoint = ServicePointManager.FindServicePoint(PassportAuthHelper._LoginUri); flag &= servicePoint.CloseConnectionGroup(""); } ServicePoint servicePoint1 = ServicePointManager.FindServicePoint(PassportAuthHelper._InitialRedirectorUri); return flag & servicePoint1.CloseConnectionGroup(""); } } }