ReadPublic() private method

private ReadPublic ( TpmHandle objectHandle, [ name, [ qualifiedName ) : TpmPublic
objectHandle TpmHandle
name [
qualifiedName [
return TpmPublic
Esempio n. 1
0
        TkVerified SignApproval(Tpm2 tpm, byte[] approvedPolicy, byte[] policyRef,
                                TpmHandle hSigKey, ISigSchemeUnion scheme = null)
        {
            byte[]    name, qname;
            TpmPublic pub = tpm.ReadPublic(hSigKey, out name, out qname);

            byte[] dataToSign = Globs.Concatenate(approvedPolicy, policyRef);
            byte[] aHash      = CryptoLib.HashData(pub.nameAlg, dataToSign);

            // Create an authorization certificate for the "approvedPolicy"
            var sig = tpm.Sign(hSigKey, aHash, scheme, new TkHashcheck());

            return(tpm.VerifySignature(hSigKey, aHash, sig));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the cached name of an entity referenced by this handle. If the
        /// name is not cached yet, retrieves it from the TPM (for a transient or
        /// persistent object, or NV index) or computes it (for session, PCR or
        /// permanent handles).
        /// </summary>
        public byte[] GetName(Tpm2 tpm)
        {
            Ht ht = GetType();

            if (_Name == null)
            {
                if (ht == Ht.NvIndex)
                {
                    tpm.NvReadPublic(this, out _Name);
                    return(_Name);
                }
                if (ht == Ht.Transient || ht == Ht.Persistent)
                {
                    byte[] qName;
                    tpm.ReadPublic(this, out _Name, out qName);
                    return(_Name);
                }
            }
            return(GetName());
        }
Esempio n. 3
0
 public byte[] GetName(Tpm2 tpm)
 {
     Ht ht = GetType();
     if (_Name == null)
     {
         if (ht == Ht.NvIndex)
         {
             tpm.NvReadPublic(this, out _Name);
             return _Name;
         }
         if (ht == Ht.Transient || ht == Ht.Persistent)
         {
             byte[] qName;
             tpm.ReadPublic(this, out _Name, out qName);
             return _Name;
         }
     }
     return GetName();
 }
Esempio n. 4
0
        public string GetHardwareDeviceId()
        {
            TpmHandle srkHandle = new TpmHandle(SRK_HANDLE);
            string hardwareDeviceId = "";
            Byte[] name;
            Byte[] qualifiedName;

            try
            {
                // Open the TPM
                Tpm2Device tpmDevice = new TbsDevice();
                tpmDevice.Connect();
                var tpm = new Tpm2(tpmDevice);

                // Read the URI from the TPM
                TpmPublic srk = tpm.ReadPublic(srkHandle, out name, out qualifiedName);

                // Dispose of the TPM
                tpm.Dispose();
            }
            catch
            {
                return hardwareDeviceId;
            }

            // Calculate the hardware device id for this logical device
            byte[] deviceId = CryptoLib.HashData(TpmAlgId.Sha256, BitConverter.GetBytes(logicalDeviceId), name);

            // Produce the output string
            foreach (byte n in deviceId)
            {
                hardwareDeviceId += n.ToString("x2");
            }
            return hardwareDeviceId;
        }