[34] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | # Copyright (C) International Business Machines Corp., 2006 |
---|
| 4 | # Author: Stefan Berger <stefanb@us.ibm.com> |
---|
| 5 | |
---|
| 6 | # Positive Test: create domain with virtual TPM attached at build time, |
---|
| 7 | # extend a pcr |
---|
| 8 | # check list of pcrs; suspend and resume the domain and |
---|
| 9 | # check list of pcrs again and validate extended pcr |
---|
| 10 | |
---|
| 11 | from XmTestLib import * |
---|
| 12 | from vtpm_utils import * |
---|
| 13 | import commands |
---|
| 14 | import os |
---|
| 15 | import os.path |
---|
| 16 | |
---|
| 17 | config = {"vtpm":"instance=1,backend=0"} |
---|
| 18 | domain = XmTestDomain(extraConfig=config) |
---|
| 19 | domName = domain.getName() |
---|
| 20 | consoleHistory = "" |
---|
| 21 | |
---|
| 22 | try: |
---|
| 23 | console = domain.start() |
---|
| 24 | except DomainError, e: |
---|
| 25 | if verbose: |
---|
| 26 | print e.extra |
---|
| 27 | vtpm_cleanup(domName) |
---|
| 28 | FAIL("Unable to create domain (%s)" % domName) |
---|
| 29 | |
---|
| 30 | try: |
---|
| 31 | console.sendInput("input") |
---|
| 32 | except ConsoleError, e: |
---|
| 33 | saveLog(console.getHistory()) |
---|
| 34 | vtpm_cleanup(domName) |
---|
| 35 | FAIL(str(e)) |
---|
| 36 | |
---|
| 37 | try: |
---|
| 38 | run = console.runCmd("mknod /dev/tpm0 c 10 224") |
---|
| 39 | except ConsoleError, e: |
---|
| 40 | saveLog(console.getHistory()) |
---|
| 41 | vtpm_cleanup(domName) |
---|
| 42 | FAIL("Error while creating /dev/tpm0") |
---|
| 43 | |
---|
| 44 | try: |
---|
| 45 | run = console.runCmd("echo -ne \"\\x00\\xc1\\x00\\x00\\x00\\x22\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\0xf\\x10\\x11\\x12\\x13\\x14\" > seq; cat seq > /dev/tpm0") |
---|
| 46 | except ConsoleError, e: |
---|
| 47 | saveLog(console.getHistory()) |
---|
| 48 | vtpm_cleanup(domName) |
---|
| 49 | FAIL("Error while extending PCR 0") |
---|
| 50 | |
---|
| 51 | try: |
---|
| 52 | run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") |
---|
| 53 | except ConsoleError, e: |
---|
| 54 | saveLog(console.getHistory()) |
---|
| 55 | vtpm_cleanup(domName) |
---|
| 56 | FAIL("No result from dumping the PCRs") |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | if re.search("No such file",run["output"]): |
---|
| 60 | vtpm_cleanup(domName) |
---|
| 61 | FAIL("TPM frontend support not compiled into (domU?) kernel") |
---|
| 62 | |
---|
| 63 | if not re.search("PCR-00:",run["output"]): |
---|
| 64 | saveLog(console.getHistory()) |
---|
| 65 | vtpm_cleanup(domName) |
---|
| 66 | FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"]) |
---|
| 67 | |
---|
| 68 | if not re.search("PCR-00: 1E A7 BD",run["output"]): |
---|
| 69 | saveLog(console.getHistory()) |
---|
| 70 | FAIL("Extend did not lead to expected result (1E A7 BD ...): \n%s" % run["output"]) |
---|
| 71 | |
---|
| 72 | consoleHistory = console.getHistory() |
---|
| 73 | domain.closeConsole() |
---|
| 74 | |
---|
| 75 | loop = 0 |
---|
| 76 | while loop < 3: |
---|
| 77 | try: |
---|
| 78 | status, ouptut = traceCommand("xm save %s %s.save" % |
---|
| 79 | (domName, domName), |
---|
| 80 | timeout=30) |
---|
| 81 | |
---|
| 82 | except TimeoutError, e: |
---|
| 83 | saveLog(consoleHistory) |
---|
| 84 | vtpm_cleanup(domName) |
---|
| 85 | FAIL(str(e)) |
---|
| 86 | |
---|
| 87 | if status != 0: |
---|
| 88 | saveLog(consoleHistory) |
---|
| 89 | vtpm_cleanup(domName) |
---|
| 90 | FAIL("xm save did not succeed") |
---|
| 91 | |
---|
| 92 | try: |
---|
| 93 | status, ouptut = traceCommand("xm restore %s.save" % |
---|
| 94 | (domName), |
---|
| 95 | timeout=30) |
---|
| 96 | except TimeoutError, e: |
---|
| 97 | os.remove("%s.save" % domName) |
---|
| 98 | saveLog(consoleHistory) |
---|
| 99 | vtpm_cleanup(domName) |
---|
| 100 | FAIL(str(e)) |
---|
| 101 | |
---|
| 102 | os.remove("%s.save" % domName) |
---|
| 103 | |
---|
| 104 | if status != 0: |
---|
| 105 | saveLog(consoleHistory) |
---|
| 106 | vtpm_cleanup(domName) |
---|
| 107 | FAIL("xm restore did not succeed") |
---|
| 108 | |
---|
| 109 | try: |
---|
| 110 | console = domain.getConsole() |
---|
| 111 | except ConsoleError, e: |
---|
| 112 | vtpm_cleanup(domName) |
---|
| 113 | FAIL(str(e)) |
---|
| 114 | |
---|
| 115 | try: |
---|
| 116 | run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") |
---|
| 117 | except ConsoleError, e: |
---|
| 118 | saveLog(console.getHistory()) |
---|
| 119 | vtpm_cleanup(domName) |
---|
| 120 | FAIL(str(e)) |
---|
| 121 | |
---|
| 122 | if not re.search("PCR-00:",run["output"]): |
---|
| 123 | saveLog(console.getHistory()) |
---|
| 124 | vtpm_cleanup(domName) |
---|
| 125 | FAIL("Virtual TPM is not working correctly on /dev/vtpm on backend side") |
---|
| 126 | |
---|
| 127 | if not re.search("PCR-00: 1E A7 BD",run["output"]): |
---|
| 128 | saveLog(console.getHistory()) |
---|
| 129 | vtpm_cleanup(domName) |
---|
| 130 | FAIL("Virtual TPM lost PCR 0 value: \n%s" % run["output"]) |
---|
| 131 | |
---|
| 132 | loop += 1 |
---|
| 133 | |
---|
| 134 | domain.closeConsole() |
---|
| 135 | |
---|
| 136 | domain.stop() |
---|
| 137 | |
---|
| 138 | vtpm_cleanup(domName) |
---|
| 139 | |
---|