SlotTypeFromHandle() static private method

static private SlotTypeFromHandle ( TpmHandle h ) : SlotType
h TpmHandle
return SlotType
Exemplo n.º 1
0
        /// <summary>
        /// This TBS returns a random handle value in the desired handle range (ugh).
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="tpmHandle"></param>
        /// <returns></returns>
        private uint GetFreeHandle(Tbs.TbsContext owner, TpmHandle tpmHandle)
        {
            Tbs.SlotType neededType = Tbs.SlotTypeFromHandle(tpmHandle);
            if (neededType == Tbs.SlotType.NoSlot)
            {
                return(tpmHandle.handle);
            }

            int numTries = 0;

            while (true)
            {
                Ht   handleType      = tpmHandle.GetType();
                var  randomPos       = (uint)Globs.GetRandomInt((int)TpmHandle.GetRangeLength(tpmHandle.GetType()));
                uint candidateHandle = ((uint)handleType << 24) + randomPos;

                if (!OwnerHandleInUse(owner, candidateHandle))
                {
                    return(candidateHandle);
                }

                numTries++;
                if (numTries >= 1000)
                {
                    break;
                }
            }
            throw new Exception("Too many TBS contexts");
        }
Exemplo n.º 2
0
        internal ObjectContext GetContext(Tbs.TbsContext caller, TpmHandle callerHandle)
        {
            if (Tbs.SlotTypeFromHandle(callerHandle) == Tbs.SlotType.NoSlot)
            {
                // Indicates that this is a TPM resident object (NV-slot, primary-handle, PWAP-handle, etc.)
                var temp = new ObjectContext {
                    TheTpmHandle = callerHandle
                };
                return(temp);
            }
            ObjectContext x = ObjectContexts.Find(item => (item.Owner == caller) && item.OwnerHandle.handle == callerHandle.handle);

            // Note that x may be null
            return(x);
        }
Exemplo n.º 3
0
        internal ObjectContext CreateObjectContext(Tbs.TbsContext owner, TpmHandle tpmHandle)
        {
            Tbs.SlotType newSlotType = Tbs.SlotTypeFromHandle(tpmHandle);
            if (newSlotType == Tbs.SlotType.NoSlot)
            {
                throw new Exception("should not be here");
            }

            // Make a new slot context of the requisite type
            uint tbsHandle  = GetFreeHandle(owner, tpmHandle);
            var  newContext = new ObjectContext {
                OwnerHandle  = new TpmHandle(tbsHandle),
                TheTpmHandle = tpmHandle,
                TheSlotType  = newSlotType,
                LastUseCount = GetUseCount(),
                Loaded       = true,
                Owner        = owner
            };

            ObjectContexts.Add(newContext);
            return(newContext);
        }