-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathTestSamples-TpmSimCtl.cs
98 lines (81 loc) · 3.27 KB
/
TestSamples-TpmSimCtl.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See the LICENSE file in the project root for full license information.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Tpm2Lib;
using Tpm2Tester;
//
// This file contains examples of TPM 2.0 test routines
//
// Note that the names of the namespace and class(es) containing the tests can be any.
//
namespace Tpm2TestSuite
{
partial class Tpm2Tests
{
[Test(Profile.TPM20, Privileges.Special, Category.Startup, Special.NotThreadSafe
| Special.Platform | Special.PowerControl | Special.Locality | Special.PhysicalPresence)]
void TestTpmPlatformControls(Tpm2 tpm, TestContext testCtx)
{
//
// Locality control
//
tpm.Shutdown(Su.Clear);
tpm._GetUnderlyingDevice().PowerCycle();
foreach (var loc in new LocalityAttr[] { LocalityAttr.LocOne,
LocalityAttr.LocFour, LocalityAttr.ExtendedBit0 })
{
tpm._SetLocality(loc);
tpm._ExpectError(TpmRc.Locality)
.Startup(Su.Clear);
}
tpm._SetLocality(LocalityAttr.LocThree);
tpm.Startup(Su.Clear);
tpm.Shutdown(Su.State);
tpm._GetUnderlyingDevice().PowerCycle();
tpm.Startup(Su.State);
tpm.Shutdown(Su.Clear);
tpm._GetUnderlyingDevice().PowerCycle();
tpm._SetLocality(LocalityAttr.LocZero);
tpm.Startup(Su.Clear);
//
// Physical Presence control
//
// PpCommands() requires PP asserted
tpm._ExpectError(TpmRc.Pp)
.PpCommands(TpmRh.Platform, new TpmCc[0], new TpmCc[0]);
tpm._AssertPhysicalPresence()
.PpCommands(TpmRh.Platform, new TpmCc[0], new TpmCc[0]);
} // TestTpmPlatformControls
[Test(Profile.TPM20, Privileges.Admin, Category.Misc,
Special.Platform | Special.NotThreadSafe)]
void TestFailureMode(Tpm2 tpm, TestContext testCtx)
{
tpm._GetUnderlyingDevice().TestFailureMode();
tpm._ExpectError(TpmRc.Failure)
.SelfTest(1);
TpmRc testResult = TpmRc.None;
byte[] outData = tpm.GetTestResult(out testResult);
testCtx.Assert("TestResult", testResult == TpmRc.Failure);
testCtx.Assert("OutData", outData != null && outData.Length > 0);
// Make sure that selected capabilities can be retrieved even when TPM is in failure mode
Tpm2.GetProperty(tpm, Pt.Manufacturer);
Tpm2.GetProperty(tpm, Pt.VendorString1);
Tpm2.GetProperty(tpm, Pt.VendorTpmType);
Tpm2.GetProperty(tpm, Pt.FirmwareVersion1);
// Check if other commands fail as expected while in failure mode.
tpm._ExpectError(TpmRc.Failure)
.GetRandom(8);
// Bring TPM back to normal.
tpm._GetUnderlyingDevice().PowerCycle();
tpm.Startup(Su.Clear);
} // TestFailureMode
}
}