using System; using System.Collections.Generic; using System.Text; using System.Net; namespace Intel.Manageability { /// /// A class that represents the connection information. /// This covers basic TCP connectivity: hostname, port, TLS or not, via web proxy or not, /// or via SOCKS proxy or not. /// public class ConnectionInfo : ICloneable { #region ICloneable interface implementation /// /// Clone - return a new copy of this object. /// /// public object Clone() { SocksProxy newSocksProxy = null; if (this.SoxProxy != null) { newSocksProxy = new SocksProxy(); newSocksProxy.Host = this.SoxProxy.Host; newSocksProxy.Password = this.SoxProxy.Password; newSocksProxy.Port = this.SoxProxy.Port; newSocksProxy.UserName = this.SoxProxy.UserName; } string host = (string)this.Host.Clone(); string username = (string)this.UserName.Clone(); string password = (string)this.Password.Clone(); string certificate = (string)this.Certificate.Clone(); ConnectionInfo newObj = new ConnectionInfo(host, username, password, this.Secure, certificate, this.Auth, this.Proxy, newSocksProxy); return newObj; } #endregion /// /// Enum that represents the authentication type /// public enum AuthMethod { /// /// HTTP Digest access authentication /// Digest, /// /// HTTP Kerberos access authentication /// Kerberos } /// /// Class which represents a SOCKS proxy. /// XXX: This might should be replaced with an IWebProxy. /// public class SocksProxy { /// /// Hostname / IP of the machine to connect. /// public string Host { get; set; } /// /// Port of the machine to connect. /// public int Port { get; set; } /// /// User name of the machine to connect. /// public string UserName { get; set; } /// /// Password of the machine to connect. /// public string Password { get; set; } } /// /// Constructor /// /// Hostname / IP of the machine to connect. /// User name of the machine to connect. /// Password of the machine to connect. /// Indicates whether or not to use TLS in the connection. /// Certificate name (as it appears in the subject field of the certificate). /// Enum that represents the authentication type. /// Indicates whether or not to use a proxy in the connection. /// Indicate whether to use a SOCKS proxy. public ConnectionInfo(string host, string userName, string password, bool secure, string certificate, AuthMethod auth, IWebProxy proxy, SocksProxy socksProxy) { Host = host; UserName = userName; if (UserName == null) { UserName = ""; } Password = password; if (Password == null) { Password = ""; } Secure = secure; Certificate = certificate; if (Certificate == null) { Certificate = ""; } Auth = auth; Proxy = proxy; SoxProxy = socksProxy; } /// /// Hostname / IP of the machine to connect. /// public string Host { set; get; } /// /// User name of the machine to connect. /// public string UserName { set; get; } /// /// Password of the machine to connect. /// public string Password { set; get; } /// /// Full URI (e.g. http://hostname:16992/wsman) /// public Uri HostUri { get { UriBuilder newUri = new UriBuilder((Secure ? "https" : "http"), Host, (Secure ? 16993 : 16992), "wsman"); return newUri.Uri; } } /// /// Indicates whether or not to use TLS in the connection. /// public bool Secure { set; get; } /// /// Certificate name (as it appears in the subject field of the certificate) /// public string Certificate { get; set; } /// /// Enum that represents the authentication type /// public AuthMethod Auth { set; get; } /// /// Indicates whether or not to use a proxy in the connection. /// public IWebProxy Proxy { set; get; } /// /// Use a SOCKS proxy. Needed for redirection connections. /// public SocksProxy SoxProxy { get; set; } } /// /// This class represents a management session: the host to connect to and how /// (as represented in the ConnectionInfo), and the management transport to use, /// which should be either "ws-man", "soap", or "none". /// public class ManagedSystem : ICloneable { /// /// WS-Man Connection. /// public const string TRANSPORT_WS_MAN = "ws-man"; /// /// Soap Connection. /// public const string TRANSPORT_SOAP = "soap"; // not used much right now #region ICloneable interface implementation /// /// Clone - return a new copy of this object. /// /// public object Clone() { ConnectionInfo i = (ConnectionInfo)this.ConnectionInfo.Clone(); ManagedSystem m = new ManagedSystem(i, this.TransportMechanism); return m; } #endregion /// /// The connection information for this session. /// public ConnectionInfo ConnectionInfo { get; set; } /// /// The transport mechanism to use /// public string TransportMechanism { get; set; } /// /// Constructor. /// /// The connection information for this session. /// The transport mechanism to use public ManagedSystem(ConnectionInfo info, string transport) { ConnectionInfo = info; TransportMechanism = transport; } /// /// Constructor. /// /// The connection information for this session. public ManagedSystem(ConnectionInfo info) { ConnectionInfo = info; TransportMechanism = TRANSPORT_WS_MAN; } } }