Beispiel #1
0
        /// <summary>
        /// Handles a HMAC generation request from the server
        /// </summary>
        /// <param name="subsystem"></param>
        /// <param name="requestContext"></param>
        private void HandleGenerateHMACRequest(TPMClientSubsystem subsystem, RequestContext <GenerateHMACRequest, GenerateHMACResponse> requestContext)
        {
            TPMSession session = MyClientContext.TPMClient.FindSession(requestContext.Request.TpmSessionIdentifier);

            GenerateHMACResponse response = requestContext.CreateResponse();

            if (session == null)
            {
                _logger.WarnFormat("Received HMAC request for tpm session with id #{0}, but this id is not associated with an active session!",
                                   requestContext.Request.TpmSessionIdentifier);

                response.Succeeded = false;
                response.SetKnownErrorCode(GenerateHMACResponse.ErrorCodeEnum.TPMSessionNotFound);
                response.Execute();
                return;
            }

            _logger.DebugFormat("Requesting password: {0}", requestContext.Request.KeyInfo.KeyType);
            ProtectedPasswordStorage pw = session.RequestSecret(requestContext.Request.KeyInfo);

            if (pw == null)
            {
                response.Succeeded = false;
                response.SetKnownErrorCode(GenerateHMACResponse.ErrorCodeEnum.HMACSecretMissing);
                response.Execute();
                return;
            }

            HMACProvider hmacProvider = new HMACProvider(pw);

            response.Succeeded   = true;
            response.TpmAuthData = hmacProvider.Hash(requestContext.Request.HMACDataProviders);

            response.Execute();
        }
Beispiel #2
0
        /// <summary>
        /// Gets the key data (which is needed to load the key)
        /// </summary>
        /// <param name="subsystem"></param>
        /// <param name="requestContext"></param>
        private void HandleGetKeyDataRequest(TPMClientSubsystem subsystem, RequestContext <GetKeyDataRequest, GetKeyDataResponse> requestContext)
        {
            TPMSession session = MyClientContext.TPMClient.FindSession(requestContext.Request.TpmSessionIdentifier);

            GetKeyDataResponse response = requestContext.CreateResponse();

            if (session == null)
            {
                _logger.WarnFormat("Received HMAC request for tpm session with id #{0}, but this id is not associated with an active session!",
                                   requestContext.Request.TpmSessionIdentifier);

                response.Succeeded = false;
                response.SetKnownErrorCode(TPMClientSubsystemResponseBase.ErrorCodeEnum.TPMSessionNotFound);
                response.Execute();
                return;
            }

            if (session.Keystore.ContainsIdentifier(requestContext.Request.Identifier) == false)
            {
                response.SetKnownErrorCode(TPMClientSubsystemResponseBase.ErrorCodeEnum.KeyIdentifierMissing);
                response.Succeeded = false;
                response.Execute();
                return;
            }

            response.KeyData = session.Keystore.GetKeyBlob(requestContext.Request.Identifier);
            response.Execute();
        }