Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pytss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from interface import tss_lib, ffi
import tspi_exceptions
import hashlib
import struct
import uuid


def uuid_to_tss_uuid(uuid):
Expand All @@ -20,6 +22,13 @@ def uuid_to_tss_uuid(uuid):

return tss_uuid

def tss_uuid_to_uuid(tss_uuid):
"""Converts a TSS UUID to a Python UUID"""
node = struct.unpack(">Q", ffi.buffer(tss_uuid.rgbNode, 6)[:].rjust(8, '\00'))[0]
return uuid.UUID(
fields=(tss_uuid.ulTimeLow, tss_uuid.usTimeMid, tss_uuid.usTimeHigh,
tss_uuid.bClockSeqHigh, tss_uuid.bClockSeqLow, node)
)

class TspiObject(object):
def __init__(self, context, ctype, tss_type, flags, handle=None):
Expand Down Expand Up @@ -576,3 +585,20 @@ def load_key_by_blob(self, srk, blob):
def get_tpm_object(self):
"""Returns the TspiTPM associated with this context"""
return self.tpm

def list_keys(self):
"""
Return a tuple of uuid.UUID instances and storagetype values for all
available keys on the TPM.
"""
count = ffi.new('UINT32 *')
key_info_value = ffi.new('TSS_KM_KEYINFO2**')
tss_lib.Tspi_Context_GetRegisteredKeysByUUID2(
self.context, 1, ffi.NULL, count, key_info_value)
values = []
for i in range(count[0]):
key_info = key_info_value[0][i]
values.append(
(tss_uuid_to_uuid(key_info.keyUUID), key_info.persistentStorageType)
)
return tuple(values)