예제 #1
0
        /// <summary>
        /// Increments the current counter value and returns the new counter value
        /// </summary>
        /// <returns></returns>
        public uint Increment()
        {
            Parameters incCounterParams = new Parameters();

            incCounterParams.AddPrimitiveType("counter_id", _counterId);
            return(_tpmSession.DoTPMCommandRequest(new TPMCommandRequest(TPMCommandNames.TPM_CMD_IncrementCounter, incCounterParams))
                   .Parameters.GetValueOf <TPMCounterValue>("counter_value").CounterValue);
        }
예제 #2
0
        /// <summary>
        /// Creates a new counter if possible.
        /// Creating a counter requires the owner password and also the secret_counter secret
        /// </summary>
        /// <param name="label">4 bytes to label the counter</param>
        /// <returns></returns>
        public CounterContext CreateCounter(byte[] label)
        {
            if (label.Length != 4)
            {
                throw new ArgumentException("label needs to be of size 4");
            }

            ProtectedPasswordStorage counterSecret = _tpmSession.RequestSecret(new HMACKeyInfo(HMACKeyInfo.HMACKeyType.CounterSecret, new Parameters()));

            if (counterSecret.Hashed == false)
            {
                counterSecret.Hash();
            }

            counterSecret.DecryptHash();

            Parameters createCounterParams = new Parameters();

            createCounterParams.AddPrimitiveType("secret", counterSecret.HashValue);
            createCounterParams.AddPrimitiveType("label", label);

            return(new CounterContext(_tpmSession,
                                      _tpmSession.DoTPMCommandRequest(new TPMCommandRequest(TPMCommandNames.TPM_CMD_CreateCounter, createCounterParams))
                                      .Parameters.GetValueOf <uint>("counter_id")
                                      ));
        }
예제 #3
0
        private TPMCommandResponse BuildDoVerifyRequest(string commandIdentifier, Parameters parameters)
        {
            TPMCommandRequest  versionRequest = new TPMCommandRequest(commandIdentifier, parameters);
            TPMCommandResponse response       = _tpmSession.DoTPMCommandRequest(versionRequest);

            if (response.Status == false)
            {
                throw new TPMRequestException("An unknown tpm error occured");
            }

            return(response);
        }
예제 #4
0
        public void Init(bool forEncryption, ICipherParameters parameters)
        {
            _forEncryption = forEncryption;

            if (forEncryption)
            {
                _encryptor = _keyHandle.PublicKey.CreateRSAEncrypter();

                Parameters bindParameters = new Parameters();
                bindParameters.AddPrimitiveType("type", "request_prefix");
                TPMCommandRequest bindPrefixRequest = new TPMCommandRequest(
                    TPMCommandNames.TPM_CMD_Bind, bindParameters);
                _prefix = _session.DoTPMCommandRequest(bindPrefixRequest).Parameters.GetValueOf <byte[]>("prefix");
            }
        }