Пример #1
0
        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);
        }
Пример #2
0
 private void RaiseClientConnectedEvent(FrontEndConnection connection)
 {
     if (ClientConnected != null)
     {
         ClientConnected(connection);
     }
 }
Пример #3
0
 public EndpointContext(FrontEndConnection connection, PacketTransmitter packetTransmitter)
 {
     _connection              = connection;
     connection.Disconnected += HandleConnectionDisconnected;
     _packetTransmitter       = packetTransmitter;
     _packetTransmitter.RequestPacketReceived += OnRequestPacketReceived;
 }
Пример #4
0
        /// <summary>
        /// Creates a ClientContext for the specified connection
        /// </summary>
        public static ClientContext CreateClientEndpointContext(FrontEndConnection connection)
        {
            PacketTransmitter packetTransmitter = new PacketTransmitter(connection);
            ClientContext     ctx = new ClientContext(connection, packetTransmitter);

            packetTransmitter.StartTransmitting();
            return(ctx);
        }
Пример #5
0
 /// <summary>
 ///Is called once the client disconnects
 /// </summary>
 /// <param name="obj">A <see cref="FrontEndConnection"/></param>
 protected void HandleConnectionDisconnected(FrontEndConnection obj)
 {
     foreach (ISubsystem subsystem in _subsystems.Values)
     {
         subsystem.Dispose();
     }
     _subsystems.Clear();
 }
Пример #6
0
 private void intialize()
 {
     // tcp listener
     new Thread(() =>
     {
         Thread.CurrentThread.IsBackground = true;
         FrontEndConnection.connect();
     }).Start();
 }
Пример #7
0
        /// <summary>
        /// Creates a ServerContext for the specified connection
        /// </summary>
        public static ServerContext CreateServerEndpointContext(FrontEndConnection connection, IConnectionsConfiguration connectionConfig,
                                                                AccessControlList acl, IDictionary <string, TPMContext> tpmContexts)
        {
            PacketTransmitter packetTransmitter = new PacketTransmitter(connection);
            ServerContext     ctx = new ServerContext(connection, packetTransmitter, connectionConfig, acl, tpmContexts);

            packetTransmitter.StartTransmitting();
            return(ctx);
        }
Пример #8
0
        public ClientContext(FrontEndConnection connection, PacketTransmitter packetTransmitter)
            : base(connection, packetTransmitter)
        {
            _debugClient = new DebugClient(this);
            _authClient  = new AuthenticationClient(this);
            _tpmClient   = new TPMClient(this);

            RegisterSubsystem(new TPMClientSubsystem(this));

            _configured = true;
            _configuredEvent.Set();
        }
Пример #9
0
        public ServerContext(FrontEndConnection connection, PacketTransmitter packetTransmitter, IConnectionsConfiguration connectionConfig,
                             AccessControlList acl, IDictionary <string, TPMContext> tpmContexts)
            : base(connection, packetTransmitter)
        {
            _accessControlList = acl;
            _tpmContexts       = tpmContexts;

            RegisterSubsystem(new DebugSubsystem(this, connectionConfig));
            RegisterSubsystem(new AuthenticationSubsystem(this, connectionConfig));
            RegisterSubsystem(new TPMSubsystem(this, connectionConfig));
            _configured = true;
            _configuredEvent.Set();
        }
Пример #10
0
        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);
        }
Пример #11
0
        /// <summary>
        /// A new client connected to a listener
        /// </summary>
        /// <param name="connection">The connection to the client</param>
        private void HandleListenerClientConnected(FrontEndConnection connection)
        {
            _logger.InfoFormat("Client {0} connected", connection);
            ServerContext ctx;

            lock (_activeContexts)
            {
                ctx = EndpointContext.CreateServerEndpointContext(connection,
                                                                  (IConnectionsConfiguration)ConfigurationManager.GetSection("connections"),
                                                                  _accessControlList, _tpmContexts);
                _activeContexts.Add(ctx);
            }
            connection.Disconnected += delegate
            {
                lock (_activeContexts)
                {
                    _logger.InfoFormat("Client {0} disconnected", connection);
                    _activeContexts.Remove(ctx);
                }
            };
        }
Пример #12
0
 private void OnConnectionEstablished(FrontEndConnection connection)
 {
     _receiveThreadWaitEvent.Set();
 }
Пример #13
0
 public PacketTransmitter(FrontEndConnection connection)
 {
     _connection = connection;
     _connection.ConnectionEstablished += OnConnectionEstablished;
 }
 /// <summary>
 /// Checks if the AuthenticationMechanism is compatible with the specified connection instance
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public bool IsCompatibleWith(FrontEndConnection connection)
 {
     return(IsCompatibleWith(connection.GetType()));
 }