private GetCapability ( Cap capability, uint property, uint propertyCount, [ capabilityData ) : byte | ||
capability | Cap | |
property | uint | |
propertyCount | uint | |
capabilityData | [ | |
return | byte |
/// <summary> /// Check if this TPM implements the given command. /// The method sends the GetCapability command the first time it is called, /// and reuses its results during subsequent invocations. /// </summary> /// <param name="commandCode">The command code to check.</param> /// <returns>true if the given command is supported by this TPM instance.</returns> public bool IsImplemented(TpmCc commandCode) { if (ImplementedCommands == null || ImplementedCommands.Length == 0) { ICapabilitiesUnion caps; uint totalCommands = Tpm2.GetProperty(Tpm, Pt.TotalCommands); Tpm.GetCapability(Cap.Commands, (uint)TpmCc.First, totalCommands, out caps); ImplementedCommands = Globs.ConvertAll((caps as CcaArray).commandAttributes, cmdAttr => (TpmCc)(cmdAttr & CcAttr.commandIndexBitMask)) .ToArray(); Debug.Assert(ImplementedCommands.Length != 0); } return(ImplementedCommands.Contains(commandCode)); }
public static byte[] GetPcrProperty(Tpm2 tpm, PtPcr prop) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.PcrProperties, (uint)prop, 1, out caps); TaggedPcrSelect[] props = (caps as TaggedPcrPropertyArray).pcrProperty; if (props.Length == 0) { return(null); } if (props.Length != 1) { Globs.Throw("Unexpected return from GetCapability"); } return(props[0].pcrSelect); }
public static uint GetProperty(Tpm2 tpm, Pt tagToGet) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.TpmProperties, (uint)tagToGet, 1, out caps); var props = (TaggedTpmPropertyArray)caps; TaggedProperty[] arr = props.tpmProperty; if (arr.Length != 1) { throw new Exception("Unexpected return from GetCapability"); } uint val = arr[0].value; return(val); }
private TpmHandle[] GetLoadedEntities(Tpm2 tpm, Ht rangeToQuery) { const uint maxHandles = UInt32.MaxValue; ICapabilitiesUnion h; byte moreData = tpm.GetCapability(Cap.Handles, ((uint)rangeToQuery) << 24, maxHandles, out h); if (moreData != 0) { throw new NotImplementedException("Too much data returned"); } if (h.GetType() != typeof(HandleArray)) { throw new Exception("Incorrect type"); } var handles = (HandleArray)h; return(handles.handle); }
public static uint GetProperty(Tpm2 tpm, Pt prop) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.TpmProperties, (uint)prop, 1, out caps); var props = (TaggedTpmPropertyArray)caps; TaggedProperty[] arr = props.tpmProperty; if (arr.Length != 1) { Globs.Throw("Unexpected return from GetCapability"); if (arr.Length == 0) { return(0); } } uint val = arr[0].value; return(val); }
/// <summary> /// Executes the GetCapabilities functionality. After parsing arguments, the /// function connects to the selected TPM device and invokes the GetCapabilities /// command on that connection. If the command was successful, the retrieved /// capabilities are displayed. /// </summary> /// <param name="args">Arguments to this program.</param> static void Main(string[] args) { // // Parse the program arguments. If the wrong arguments are given or // are malformed, then instructions for usage are displayed and // the program terminates. // string tpmDeviceName; if (!ParseArguments(args, out tpmDeviceName)) { WriteUsage(); return; } try { // // Create the device according to the selected connection. // Tpm2Device tpmDevice; switch (tpmDeviceName) { case DeviceSimulator: tpmDevice = new TcpTpmDevice(DefaultSimulatorName, DefaultSimulatorPort); break; case DeviceWinTbs: tpmDevice = new TbsDevice(); break; default: throw new Exception("Unknown device selected."); } // // Connect to the TPM device. This function actually establishes the // connection. // tpmDevice.Connect(); // // Pass the device object used for communication to the TPM 2.0 object // which provides the command interface. // var tpm = new Tpm2(tpmDevice); if (tpmDevice is TcpTpmDevice) { // // If we are using the simulator, we have to do a few things the // firmware would usually do. These actions have to occur after // the connection has been established. // tpmDevice.PowerCycle(); tpm.Startup(Su.Clear); } // // Query different capabilities // ICapabilitiesUnion caps; tpm.GetCapability(Cap.Algs, 0, 1000, out caps); var algsx = (AlgPropertyArray)caps; Console.WriteLine("Supported algorithms:"); foreach (var alg in algsx.algProperties) { Console.WriteLine(" {0}", alg.alg.ToString()); } Console.WriteLine("Supported commands:"); tpm.GetCapability(Cap.TpmProperties, (uint)Pt.TotalCommands, 1, out caps); tpm.GetCapability(Cap.Commands, (uint)TpmCc.First + 1, TpmCc.Last - TpmCc.First + 1, out caps); var commands = (CcaArray)caps; List<TpmCc> implementedCc = new List<TpmCc>(); foreach (var attr in commands.commandAttributes) { var commandCode = (TpmCc)((uint)attr & 0x0000FFFFU); // // Filter placehoder(s) // if(commandCode == TpmCc.None) { continue; } implementedCc.Add(commandCode); Console.WriteLine(" {0}", commandCode.ToString()); } Console.WriteLine("Commands from spec not implemented:"); foreach (var cc in Enum.GetValues(typeof(TpmCc))) { if (!implementedCc.Contains((TpmCc)cc) && // // Fiter placeholder(s) // ((TpmCc)cc != TpmCc.None) && ((TpmCc)cc != TpmCc.First) && ((TpmCc)cc != TpmCc.Last) ) { Console.WriteLine(" {0}", cc.ToString()); } } // // As an alternative: call GetCapabilities more than once to obtain all values // byte more; var firstCommandCode = (uint)TpmCc.None; do { more = tpm.GetCapability(Cap.Commands, firstCommandCode, 10, out caps); commands = (CcaArray)caps; // // Commands are sorted; getting the last element as it will be the largest. // uint lastCommandCode = (uint)commands.commandAttributes[commands.commandAttributes.Length - 1] & 0x0000FFFFU; firstCommandCode = lastCommandCode; } while (more == 1); // // Read PCR attributes. Cap.Pcrs returns the list of PCRs which are supported // in different PCR banks. The PCR banks are identified by the hash algorithm // used to extend values into the PCRs of this bank. // tpm.GetCapability(Cap.Pcrs, 0, 255, out caps); PcrSelection[] pcrs = ((PcrSelectionArray)caps).pcrSelections; Console.WriteLine(); Console.WriteLine("Available PCR banks:"); foreach (PcrSelection pcrBank in pcrs) { var sb = new StringBuilder(); sb.AppendFormat("PCR bank for algorithm {0} has registers at index:", pcrBank.hash); sb.AppendLine(); foreach (uint selectedPcr in pcrBank.GetSelectedPcrs()) { sb.AppendFormat("{0},", selectedPcr); } Console.WriteLine(sb); } // // Read PCR attributes. Cap.PcrProperties checks for certain properties of each PCR register. // tpm.GetCapability(Cap.PcrProperties, 0, 255, out caps); Console.WriteLine(); Console.WriteLine("PCR attributes:"); TaggedPcrSelect[] pcrProperties = ((TaggedPcrPropertyArray)caps).pcrProperty; foreach (TaggedPcrSelect pcrProperty in pcrProperties) { if ((PtPcr)pcrProperty.tag == PtPcr.None) { continue; } uint pcrIndex = 0; var sb = new StringBuilder(); sb.AppendFormat("PCR property {0} supported by these registers: ", (PtPcr)pcrProperty.tag); sb.AppendLine(); foreach (byte pcrBitmap in pcrProperty.pcrSelect) { for (int i = 0; i < 8; i++) { if ((pcrBitmap & (1 << i)) != 0) { sb.AppendFormat("{0},", pcrIndex); } pcrIndex++; } } Console.WriteLine(sb); } // // Clean up. // tpm.Dispose(); } catch (Exception e) { Console.WriteLine("Exception occurred: {0}", e.Message); } Console.WriteLine("Press Any Key to continue."); Console.ReadLine(); }
private TpmHandle[] GetLoadedEntities(Tpm2 tpm, Ht rangeToQuery) { const uint maxHandles = UInt32.MaxValue; ICapabilitiesUnion h; byte moreData = tpm.GetCapability(Cap.Handles, ((uint)rangeToQuery) << 24, maxHandles, out h); if (moreData != 0) { throw new NotImplementedException("Too much data returned"); } if (h.GetType() != typeof (HandleArray)) { throw new Exception("Incorrect type"); } var handles = (HandleArray)h; return handles.handle; }
public static byte[] GetPcrProperty(Tpm2 tpm, PtPcr prop) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.PcrProperties, (uint)prop, 1, out caps); TaggedPcrSelect[] props = (caps as TaggedPcrPropertyArray).pcrProperty; if (props.Length == 0) { return null; } if (props.Length != 1) { Globs.Throw("Unexpected return from GetCapability"); } return props[0].pcrSelect; }
public static uint GetProperty(Tpm2 tpm, Pt prop) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.TpmProperties, (uint)prop, 1, out caps); var props = (TaggedTpmPropertyArray)caps; TaggedProperty[] arr = props.tpmProperty; if (arr.Length != 1) { Globs.Throw("Unexpected return from GetCapability"); if (arr.Length == 0) return 0; } uint val = arr[0].value; return val; }
public static uint GetProperty(Tpm2 tpm, Pt tagToGet) { ICapabilitiesUnion caps; tpm.GetCapability(Cap.TpmProperties, (uint)tagToGet, 1, out caps); var props = (TaggedTpmPropertyArray)caps; TaggedProperty[] arr = props.tpmProperty; if (arr.Length != 1) { throw new Exception("Unexpected return from GetCapability"); } uint val = arr[0].value; return val; }