blob: 34f81b575e65a5e688f2dfb7d6a34212615a2a5f (
plain)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #!/usr/bin/env python3 # Copyright 2015 Canonical Ltd. # All rights reserved. # # Written by: # Zygmunt Krynicki <zygmunt.krynicki@canonical.com> """Collect information about all sysfs attributes related to TPM.""" import os import guacamole class tpm_sysfs_resource(guacamole.Command): """ Collect information about all sysfs attributes related to TPM. This program traverses all the TPM device nodes found in /sys/class/tpm/. Each present device is subsequently inspected by reading all readable files in /sys/class/tpm/*/device/* and presenting the data present there as subsequent RFC822 records. There is one record per TPM chip. In order to differentiate each chip, each record contains the field x-sysfs-device-name that stores the full sysfs directory name of the chip. @EPILOG@ Unreadable files (typically due to permissions) are silently skipped. """ def invoked(self, ctx): # This is found on 4.2 kernels sysfs_root_tpm = '/sys/class/tpm/' # This is found on 3.19 kernels sysfs_root_misc = '/sys/class/misc/' if os.path.isdir(sysfs_root_tpm): sysfs_root = sysfs_root_tpm elif os.path.isdir(sysfs_root_misc): sysfs_root = sysfs_root_misc else: return for tpm_id in sorted(os.listdir(sysfs_root)): if sysfs_root == sysfs_root_misc and not tpm_id.startswith('tpm'): continue print("x-sysfs-device-name: {}".format(tpm_id)) tpm_dirname = os.path.join(sysfs_root, tpm_id, 'device') for tpm_attr in sorted(os.listdir(tpm_dirname)): tpm_filename = os.path.join(tpm_dirname, tpm_attr) if not os.path.isfile(tpm_filename): continue if not os.access(tpm_filename, os.R_OK): continue with open(tpm_filename, 'rt', encoding='utf-8') as stream: tpm_data = stream.read() tpm_data = tpm_data.rstrip() if '\n' in tpm_data: print("{}:".format(tpm_attr)) for tpm_data_chunk in tpm_data.splitlines(): print(" {}".format(tpm_data_chunk)) else: print("{}: {}".format(tpm_attr, tpm_data)) print() if __name__ == "__main__": tpm_sysfs_resource().main()
|