276 lines
9.3 KiB
C#
276 lines
9.3 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Rei.Fs.Webdav.ConnectionSetting
|
|
// 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.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Net;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace Rei.Fs.Webdav
|
|
{
|
|
[Serializable]
|
|
public class ConnectionSetting : ConnectionSettingBase
|
|
{
|
|
public bool UseDefaultCredential;
|
|
public List<string> ClientCertificates;
|
|
public bool UsePreAuthentication_Basic;
|
|
public bool UsePreAuthentication_WSSE;
|
|
private string[] pAuthModules;
|
|
[XmlIgnore]
|
|
public SslProtocols DisableTlsVersions;
|
|
public string URIRequestEncoding;
|
|
public string URIResponseEncoding;
|
|
public string CredentialEncoding;
|
|
public bool DontRequestGzip;
|
|
public bool DontRequestDeflate;
|
|
public bool RequestTranslatef;
|
|
public bool DontExpect100;
|
|
public bool SendEmptyPUT;
|
|
public bool DontUpdateProperty;
|
|
public bool UseFullUriInDestinationHeader;
|
|
public string UploadCompression;
|
|
public bool DontVerifyContentRange;
|
|
public bool RedirectionCollectionOnly;
|
|
public bool RemoveLastSlashOnMKCOL;
|
|
public bool DisableUploadResume;
|
|
|
|
public ConnectionSetting()
|
|
{
|
|
this.UseDefaultCredential = false;
|
|
this.UsePreAuthentication_Basic = false;
|
|
this.UsePreAuthentication_WSSE = false;
|
|
this.AuthModules = new string[0];
|
|
this.DisableTlsVersions = SslProtocols.None;
|
|
this.ClientCertificates = new List<string>();
|
|
this.URIRequestEncoding = "UTF-8";
|
|
this.URIResponseEncoding = "UTF-8";
|
|
this.CredentialEncoding = "UTF-8";
|
|
this.DontRequestGzip = false;
|
|
this.DontRequestDeflate = false;
|
|
this.RequestTranslatef = true;
|
|
this.DontExpect100 = false;
|
|
this.SendEmptyPUT = false;
|
|
this.DontUpdateProperty = false;
|
|
this.UseFullUriInDestinationHeader = true;
|
|
this.DontVerifyContentRange = false;
|
|
this.RedirectionCollectionOnly = false;
|
|
this.RemoveLastSlashOnMKCOL = true;
|
|
this.UploadCompression = "None";
|
|
this.DisableUploadResume = true;
|
|
}
|
|
|
|
public static string TypeName
|
|
{
|
|
get
|
|
{
|
|
return "WebDAV";
|
|
}
|
|
}
|
|
|
|
public static bool TryCreate(Uri target, ref ConnectionSettingBase c)
|
|
{
|
|
if (Operators.CompareString(target.Scheme, Uri.UriSchemeHttp, false) != 0 && Operators.CompareString(target.Scheme, Uri.UriSchemeHttps, false) != 0)
|
|
return false;
|
|
c = (ConnectionSettingBase) new ConnectionSetting();
|
|
c.TargetUri = target;
|
|
return true;
|
|
}
|
|
|
|
public new static Icon GetDefaultFavicon()
|
|
{
|
|
return Rei.Fs.Webdav.My.Resources.Resources.WebDAVFolder;
|
|
}
|
|
|
|
public override SecureType SecureType
|
|
{
|
|
get
|
|
{
|
|
return Operators.CompareString(this.TargetUri.Scheme, Uri.UriSchemeHttps, false) == 0 ? SecureType.Secure : SecureType.None;
|
|
}
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public string[] AuthModules
|
|
{
|
|
get
|
|
{
|
|
return this.pAuthModules;
|
|
}
|
|
set
|
|
{
|
|
if (value == null)
|
|
value = new string[0];
|
|
this.pAuthModules = value;
|
|
}
|
|
}
|
|
|
|
[Browsable(false)]
|
|
[XmlElement("AuthModules")]
|
|
public string AuthModules_ForSerialization
|
|
{
|
|
get
|
|
{
|
|
return string.Join(",", this.pAuthModules);
|
|
}
|
|
set
|
|
{
|
|
this.pAuthModules = value.Split(new char[2]
|
|
{
|
|
' ',
|
|
','
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
|
}
|
|
}
|
|
|
|
[XmlElement("DisableTlsVersions")]
|
|
[Browsable(false)]
|
|
public string DisableTlsVersions_ForSerialization
|
|
{
|
|
get
|
|
{
|
|
string str = "";
|
|
if ((this.DisableTlsVersions & SslProtocols.Ssl2) != SslProtocols.None)
|
|
str += "ssl2 ";
|
|
if ((this.DisableTlsVersions & SslProtocols.Ssl3) != SslProtocols.None)
|
|
str += "ssl3 ";
|
|
if ((this.DisableTlsVersions & SslProtocols.Tls) != SslProtocols.None)
|
|
str += "tls10 ";
|
|
if ((this.DisableTlsVersions & SslProtocols.Tls11) != SslProtocols.None)
|
|
str += "tls11 ";
|
|
if ((this.DisableTlsVersions & SslProtocols.Tls12) != SslProtocols.None)
|
|
str += "tls12 ";
|
|
return str.Trim();
|
|
}
|
|
set
|
|
{
|
|
this.DisableTlsVersions = SslProtocols.None;
|
|
value = value.ToLowerInvariant();
|
|
if (value.Contains("ssl2"))
|
|
this.DisableTlsVersions = this.DisableTlsVersions | SslProtocols.Ssl2;
|
|
if (value.Contains("ssl3"))
|
|
this.DisableTlsVersions = this.DisableTlsVersions | SslProtocols.Ssl3;
|
|
if (value.Contains("tls10"))
|
|
this.DisableTlsVersions = this.DisableTlsVersions | SslProtocols.Tls;
|
|
if (value.Contains("tls11"))
|
|
this.DisableTlsVersions = this.DisableTlsVersions | SslProtocols.Tls11;
|
|
if (!value.Contains("tls12"))
|
|
return;
|
|
this.DisableTlsVersions = this.DisableTlsVersions | SslProtocols.Tls12;
|
|
}
|
|
}
|
|
|
|
public override FsBase GetBaseClient()
|
|
{
|
|
return (FsBase) this.InnerGetClient();
|
|
}
|
|
|
|
public WebdavFs InnerGetClient()
|
|
{
|
|
WebdavFs webdavFs = new WebdavFs(this);
|
|
webdavFs.UseDefaultCredential = this.UseDefaultCredential;
|
|
webdavFs.UsePreAuthentication_Basic = this.UsePreAuthentication_Basic;
|
|
webdavFs.UsePreAuthentication_WSSE = this.UsePreAuthentication_WSSE;
|
|
webdavFs.AuthModules = this.AuthModules;
|
|
webdavFs.DisableTlsVersions = this.DisableTlsVersions;
|
|
X509Store x509Store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
|
|
x509Store.Open(OpenFlags.ReadOnly);
|
|
try
|
|
{
|
|
int num1 = 0;
|
|
int num2 = checked (this.ClientCertificates.Count - 1);
|
|
int index1 = num1;
|
|
while (index1 <= num2)
|
|
{
|
|
int num3 = 0;
|
|
int num4 = checked (x509Store.Certificates.Count - 1);
|
|
int index2 = num3;
|
|
while (index2 <= num4)
|
|
{
|
|
if (Operators.CompareString(this.ClientCertificates[index1], x509Store.Certificates[index2].Thumbprint, false) == 0)
|
|
{
|
|
webdavFs.ClientCertificates.Add(x509Store.Certificates[index2]);
|
|
break;
|
|
}
|
|
checked { ++index2; }
|
|
}
|
|
checked { ++index1; }
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
x509Store.Close();
|
|
}
|
|
webdavFs.URIRequestEncoding = Encoding.GetEncoding(this.URIRequestEncoding.Trim());
|
|
webdavFs.URIResponseEncoding = Encoding.GetEncoding(this.URIResponseEncoding.Trim());
|
|
webdavFs.CredentialEncoding = Encoding.GetEncoding(this.CredentialEncoding.Trim());
|
|
webdavFs.DontRequestGzip = this.DontRequestGzip;
|
|
webdavFs.DontRequestDeflate = this.DontRequestDeflate;
|
|
webdavFs.RequestTranslatef = this.RequestTranslatef;
|
|
webdavFs.DontExpect100 = this.DontExpect100;
|
|
webdavFs.SendEmptyPUT = this.SendEmptyPUT;
|
|
webdavFs.DontUpdateProperty = this.DontUpdateProperty;
|
|
webdavFs.UseFullUriInDestinationHeader = this.UseFullUriInDestinationHeader;
|
|
webdavFs.DontVerifyContentRange = this.DontVerifyContentRange;
|
|
webdavFs.RedirectionCollectionOnly = this.RedirectionCollectionOnly;
|
|
webdavFs.UploadCompression = this.UploadCompression;
|
|
webdavFs.RemoveLastSlashOnMKCOL = this.RemoveLastSlashOnMKCOL;
|
|
webdavFs.DisableUploadResume = this.DisableUploadResume;
|
|
if (this.Proxy == ProxyType.Default)
|
|
webdavFs.Proxy = WebRequest.GetSystemWebProxy();
|
|
else if (this.Proxy == ProxyType.Specify)
|
|
{
|
|
int length = this.ProxyUserName.IndexOf("\\");
|
|
NetworkCredential networkCredential = length < 0 ? new NetworkCredential(this.ProxyUserName, this.ProxyPassword) : new NetworkCredential(this.ProxyUserName.Substring(checked (length + 1)), this.ProxyPassword, this.ProxyUserName.Substring(0, length));
|
|
webdavFs.Proxy = (IWebProxy) new WebProxy(this.ProxyUri, this.ProxyByPassLocal, this.ProxyByPassList, (ICredentials) networkCredential);
|
|
}
|
|
else
|
|
webdavFs.Proxy = (IWebProxy) null;
|
|
webdavFs.ConnectTimeout = this.ConnectTimeout;
|
|
webdavFs.ReadWriteTimeout = this.ReadWriteTimeout;
|
|
return webdavFs;
|
|
}
|
|
|
|
public override Form GetSettingForm()
|
|
{
|
|
return (Form) new ConnectionSettingForm();
|
|
}
|
|
|
|
public override bool DoAuthorization(Uri target, bool PersistSelectable)
|
|
{
|
|
using (AuthDialog authDialog = new AuthDialog())
|
|
{
|
|
authDialog.Target = target.ToString();
|
|
authDialog.UserName = this.UserName;
|
|
authDialog.Password = this.Password;
|
|
if (PersistSelectable && !this.DontSave)
|
|
{
|
|
authDialog.ShowRememberCheckBox = true;
|
|
authDialog.Remember = false;
|
|
}
|
|
else
|
|
{
|
|
authDialog.ShowRememberCheckBox = false;
|
|
authDialog.Remember = true;
|
|
}
|
|
if (authDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.SetUserPass(authDialog.UserName, authDialog.Password);
|
|
if (authDialog.Remember)
|
|
this.NeedPersist = true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|