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