aboutsummaryrefslogtreecommitdiffstats
path: root/tpm2-read-pcrs
blob: 9b30a7fa1bee317f82890d63faef7f2b26f0cea7 (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
#!/usr/bin/env python

from argparse import ArgumentParser
from argparse import FileType
import os
import sys
import tpm2


def main():
    parser = ArgumentParser(description='Create a storage root key')
    parser.add_argument('--debug',
                        action='store_true',
                        help='dump TPM commands and replies')
    parser.add_argument('--name-alg', dest='name_alg', metavar='NAMEALG',
                        help='hash algorithm',
                        type=tpm2.get_algorithm, default='sha1')

    args = parser.parse_args()

    flags = 0

    if args.debug:
        flags |= tpm2.Client.FLAG_DEBUG

    client = tpm2.Client(flags)

    try:
        for i in xrange(0, 16):
            h = client.read_pcr(i, bank_alg=args.name_alg)
            print("%02d: %s" % (i, h.encode('hex')))

    except tpm2.ProtocolError, e:
        sys.stderr.write(str(e) + os.linesep)
        sys.exit(1)

if __name__ == '__main__':
    main()