public static FrontEndConnection CreateFrontEndConnection( string identifier, ConnectionBuilderSettings settings, params object[] parameters) { Type t = GenericClassIdentifierFactory.FindTypeForIdentifier <FrontEndConnection>(identifier); if (t == null) { return(null); } FrontEndConnectionAttribute attr = (FrontEndConnectionAttribute)t.GetCustomAttributes(typeof(FrontEndConnectionAttribute), false)[0]; if (attr.ConnectionBuilder != null) { IConnectionBuilder connectionBuilder = (IConnectionBuilder) GenericClassIdentifierFactory.CreateInstance(attr.ConnectionBuilder, parameters); connectionBuilder.Settings = settings; return(connectionBuilder.SetupConnection()); } else { return(GenericClassIdentifierFactory.CreateFromClassIdentifierOrType <FrontEndConnection>(identifier, parameters)); } }
public override void Execute(string[] commandline) { if (commandline.Length < 2) { _console.Out.WriteLine("Error: [connection_name] not specified"); return; } //string[] arguments = new string[commandline.Length - 2]; // if(arguments.Length > 0) //Array.Copy(commandline, 2, arguments, 0, arguments.Length); IDictionary<string, string> arguments = _console.SplitArguments(commandline[2], 0); //FrontEndConnection conn = GenericClassIdentifierFactory.CreateFromClassIdentifierOrType<FrontEndConnection>(commandline[1], arguments); ConnectionBuilderSettings settings = new ConnectionBuilderSettings(RequestSecret); FrontEndConnection conn = ConnectionFactory.CreateFrontEndConnection(commandline[1], settings, arguments); if (conn == null) { _console.Out.WriteLine("Error: could not create connection '{0}' identifier not found or cannot construct, run connection_create_info for more information"); return; } conn.Connect(); ClientContext ctx = EndpointContext.CreateClientEndpointContext(conn); ctx.TPMClient.SetRequestSecretCallback(_console.AsyncSecretRequestCallback); _console.SetValue("client_context", ctx); }
public static FrontEndConnection CreateFrontEndConnection( string identifier, ConnectionBuilderSettings settings, params object[] parameters) { Type t = GenericClassIdentifierFactory.FindTypeForIdentifier<FrontEndConnection>(identifier); if( t == null) return null; FrontEndConnectionAttribute attr = (FrontEndConnectionAttribute)t.GetCustomAttributes(typeof(FrontEndConnectionAttribute), false)[0]; if(attr.ConnectionBuilder != null) { IConnectionBuilder connectionBuilder = (IConnectionBuilder) GenericClassIdentifierFactory.CreateInstance(attr.ConnectionBuilder, parameters); connectionBuilder.Settings = settings; return connectionBuilder.SetupConnection(); } else return GenericClassIdentifierFactory.CreateFromClassIdentifierOrType<FrontEndConnection>(identifier, parameters); }
public static IDictionary<string, TPMSession> EstablischConnection(string filename) { IDictionary<string, TPMSession> sessions = new Dictionary<string, TPMSession>(); XmlDocument xdoc = new XmlDocument(); xdoc.Load(filename); XmlNode rootNode = xdoc.SelectSingleNode("TPMClientConfiguration"); XmlNodeList clientNodes = rootNode.SelectNodes("Context"); foreach(XmlNode node in clientNodes) { string connType = node.SelectSingleNode("Connection").Attributes.GetNamedItem("Type").Value; IDictionary<string, string> connSpecAttr = GetAttributesDictionary(node.SelectSingleNode("Connection").SelectSingleNode(connType)); ConnectionBuilderSettings settings = new ConnectionBuilderSettings(RequestSecret); FrontEndConnection conn = ConnectionFactory.CreateFrontEndConnection(connType, settings, connSpecAttr); if(conn == null) throw new Exception(string.Format("Could not establish connection off type {0}", connType)); conn.Connect(); ClientContext ctx = EndpointContext.CreateClientEndpointContext(conn); string auth = node.SelectSingleNode("Authentication").Attributes.GetNamedItem("Type").Value; ctx.AuthClient.SelectAuthentication(auth); if(ctx.AuthClient.Authenticate().Succeeded == false) throw new Exception(string.Format("Could not authenticate via {0}", auth)); foreach(XmlNode dev in node.SelectNodes("TPM")) { string device = dev.Attributes.GetNamedItem("device").Value; if(sessions.ContainsKey(device)) throw new Exception(string.Format("TPMSession {0} already established", device)); TPMSession tpm = ctx.TPMClient.SelectTPMDevice(device); sessions.Add(dev.Attributes.GetNamedItem("alias").Value, tpm); } } return sessions; }