Exemplo n.º 1
0
        private void HandleSecretRequest(SecretRequest request)
        {
            if (request.KeyInfo == null)
            {
                request.ProtectedPassword = Utils.ReadPassword(request.CustomHintText, this, false);
            }
            else if (request.KeyInfo.KeyType == HMACKeyInfo.HMACKeyType.OwnerSecret)
            {
                request.ProtectedPassword = Utils.ReadPassword("Server requests owner password:"******"Server requests srk password:"******"Server requests usage secret for key '{0}'",
                                                                             request.KeyInfo.Parameters.GetValueOf <string>("identifier")), this, false);
            }
            else if (request.KeyInfo.KeyType == HMACKeyInfo.HMACKeyType.SealAuth)
            {
                request.ProtectedPassword = Utils.ReadPassword(string.Format("Server requests auth for pending seal operation"), this, false);
            }
            else if (request.KeyInfo.KeyType == HMACKeyInfo.HMACKeyType.CounterSecret)
            {
                request.ProtectedPassword = Utils.ReadPassword(string.Format("Server requests auth for counter"), this, false);
            }
            else
            {
                throw new ArgumentException("Key type not supported by TPM console");
            }

            request.PasswordReady.Set();
        }
Exemplo n.º 2
0
        public ProtectedPasswordStorage AsyncSecretRequestCallback(HMACKeyInfo keyInfo)
        {
            _logger.DebugFormat("Async requesting secret '{0}'", keyInfo.KeyType);

            SecretRequest request = new SecretRequest(keyInfo);

            AddSecretRequest(request);
            request.PasswordReady.WaitOne();
            return(request.ProtectedPassword);
        }
Exemplo n.º 3
0
 public void AddSecretRequest(SecretRequest secretRequest)
 {
     lock (_secretRequests)
         _secretRequests.Enqueue(secretRequest);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the Console loop, returns on console exit
        /// </summary>
        public void Run()
        {
            bool          outputPrompt       = true;
            StringBuilder currentCommandLine = new StringBuilder();

            bool commandRunning = false;

            while (_runConsoleLoop)
            {
                if (commandRunning == false && outputPrompt)
                {
                    Out.Write(":> ");
                    outputPrompt = false;
                }

                while (commandRunning == false && Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey();

                    if (keyInfo.Key == ConsoleKey.Backspace)
                    {
                        if (currentCommandLine.Length > 0)
                        {
                            currentCommandLine.Remove(currentCommandLine.Length - 1, 1);
                        }
                    }
                    else if (keyInfo.Key == ConsoleKey.Enter)
                    {
                        _commandReady  = false;
                        commandRunning = true;
                        InterpretCommand(currentCommandLine.ToString(), false, false);

                        currentCommandLine.Remove(0, currentCommandLine.Length);
                        outputPrompt = true;
                    }
                    else
                    {
                        currentCommandLine.Append(keyInfo.KeyChar);
                    }
                }

                if (_commandReady)
                {
                    commandRunning = false;
                }

                SecretRequest secretRequest = null;
                lock (_secretRequests)
                {
                    if (_secretRequests.Count > 0)
                    {
                        secretRequest = _secretRequests.Dequeue();
                    }
                }

                if (secretRequest != null)
                {
                    HandleSecretRequest(secretRequest);
                    currentCommandLine.Remove(0, currentCommandLine.Length);
                }

                Thread.Sleep(10);
            }
        }