File: admin.php

package info (click to toggle)
tss2 1045-3
  • links: PTS
  • area: main
  • in suites: sid
  • size: 6,868 kB
  • sloc: ansic: 58,589; sh: 5,124; php: 1,247; makefile: 380; cpp: 23
file content (340 lines) | stat: -rwxr-xr-x 10,297 bytes parent folder | download | duplicates (3)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!-- $Id: admin.php 900 2017-01-06 19:25:47Z kgoldman $ -->

<?php
/* (c) Copyright IBM Corporation 2016.						*/
/*										*/
/* All rights reserved.								*/
/* 										*/
/* Redistribution and use in source and binary forms, with or without		*/
/* modification, are permitted provided that the following conditions are	*/
/* met:										*/
/* 										*/
/* Redistributions of source code must retain the above copyright notice,	*/
/* this list of conditions and the following disclaimer.			*/
/* 										*/
/* Redistributions in binary form must reproduce the above copyright		*/
/* notice, this list of conditions and the following disclaimer in the		*/
/* documentation and/or other materials provided with the distribution.		*/
/* 										*/
/* Neither the names of the IBM Corporation nor the names of its		*/
/* contributors may be used to endorse or promote products derived from		*/
/* this software without specific prior written permission.			*/
/* 										*/
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS		*/
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT		*/
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR	*/
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT		*/
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,	*/
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT		*/
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,	*/
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY	*/
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT		*/
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE	*/
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.		*/
/********************************************************************************/
?>

<html>
<head>
<title>TSS 2.0 Demo Administration
<?php
echo gethostname();
?>
</title>
<link rel="stylesheet" type="text/css" href="demo.css">
</head>
<body>

<form method="post" action="admin.php">

<div id="header">
<img src="ibm.png" style="float:right;width:200px;height:70px">
<h2>IBM TSS Demo Administration - 
<?php
echo gethostname();
?>
</h2>
</div>

<?php
require '/var/www/html/tpm2/nav.html';
?>

<div id="section">

<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
    $command = $_POST['command'];
    $hic = $_POST['hic'];
    $hip = $_POST['hip'];
    $pwda = $_POST['pwda'];
    $pwdn1 = $_POST['pwdn1'];
    $pwdn2 = $_POST['pwdn2'];
    
    $retval == 0;
    // parameter checks
    if ($retval == 0) {
	if ($command == 'Change Password') {
	    if ($pwdn1 != $pwdn2) {
		echo "New passwords do not match";
		$retval = 1;
		$pwdn1 = $pwda;     // don't roll the old password
	    }
	}
	/* radio buttons, should never occur */
	if (strlen($hic) == 0) {
	    echo "Clock - authorization hierarchy must be specified<br>\n";
	    $retval = 1;
	}
	/* radio buttons, should never occur */
	if (strlen($hip) == 0) {
	    echo "Password - authorization hierarchy must be specified<br>\n";
	    $retval = 1;
	}
    }
    // construct the command
    if ($retval == 0) {
	switch ($command) {
	  case 'Change Password':
	  $commandStr = "/var/www/html/tpm2/hierarchychangeauth";
	    $commandStr .= " -hi " . $hip;
	    if (strlen($pwda) != 0) {
	        $commandStr .= " -pwda " . $pwda;
	    }
	    if (strlen($pwdn1) != 0) {
	        $commandStr .= " -pwdn " . $pwdn1;
	    }
	    break;

	  case 'Set TPM Date and Time':
	    $commandStr = "/var/www/html/tpm2/clockset";
            $commandStr .= " -hi " . $hic;
	    $currenttime = time();				// php time in sec
	    $commandStr .= " -time " . ($currenttime * 1000);	// TPM command in msec
	    break;

	  case 'SH disable':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he o -state 0";
	    break;
	  case 'SH enable':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he o -state 1";
	    break;
	  case 'EH disable':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he e -state 0";
	    break;
	  case 'EH enable':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he e -state 1";
	    break;
	  case 'phEnableNV clear':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he n -state o";
	    break;
	  case 'phEnableNV set':
	    $commandStr = "/var/www/html/tpm2/hierarchycontrol -hi p -he n -state 1";
	    break;
	  default:
	    echo ("Invalid command $command");
	    $retval = 1;
	    break;
	}
    }
    if ($retval == 0) {
	// uncomment for test and debug, permits view of TPM command
        //echo 'Command string: ' . $commandStr. "<br>\n"; $retval = 0;
        unset($output);
        exec ($commandStr, $output, $retval);
        if ($retval == 0) {
            ;
        }
        else {
            echo $commandStr . "<br>\n";
            for ($i = 0 ; $i < count($output) ; $i++) {
                echo $output[$i] . "<br>\n";
            }
        }
    }
}
     
echo "<h3>TPM Information</h3>";
unset($output);
exec ("/var/www/html/tpm2/getcapability -cap 6", $output, $retval);
//print_r($output);

$key = searchForValue("TPM_PT_MANUFACTURER", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
echo "Manufacturer: ";
$chars = str_split ($values[3], 2);
for ($i = 0 ; $i < count($chars) ; $i++) {
    echo chr(hexdec($chars[$i]));
}
echo "<br>\n";

echo "Vendor String: ";
$key = searchForValue("TPM_PT_VENDOR_STRING_1", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
$chars = str_split ($values[3], 2);
for ($i = 0 ; $i < count($chars) ; $i++) {
    echo chr(hexdec($chars[$i]));
}

$key = searchForValue("TPM_PT_VENDOR_STRING_2", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
$chars = str_split ($values[3], 2);
for ($i = 0 ; $i < count($chars) ; $i++) {
    echo chr(hexdec($chars[$i]));
}
echo "<br>\n";

$key = searchForValue("TPM_PT_REVISION", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
echo "Revision: " . hexdec($values[3]) . "<br>\n";

$key = searchForValue("TPM_PT_FIRMWARE_VERSION_1", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
echo "Firmware: " . $values[3];

$key = searchForValue("TPM_PT_FIRMWARE_VERSION_2", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
echo " " . $values[3];
echo "<br>\n";

unset($output);
exec ("/var/www/html/tpm2/readclock", $output, $retval);
$key = searchForValue("TPMS_TIME_INFO", $output);
$value = $output[$key];
$values = explode (" ", trim($value));
echo "TPM Time since startup: " . $values[2] . " msec<br>\n";

$key = searchForValue("  TPMS_CLOCK_INFO", $output);
$value = $output[$key];
$values = explode (" ", trim($value));				// TPM time in msec
echo "TPM Date and Time: " . date(DATE_RSS, ($values[2] / 1000));	// php time in sec

?>

<input type="submit" name="command" value="Set TPM Date and Time">
<input type="radio" name="hic" value="p"
     <?php if ($hic == "p") echo " checked"; ?>>Platform
<input type="radio" name="hic" value="o"
     <?php if (($hic == "o") || !isset($hic)) echo " checked"; ?>>Owner

<h3>TPM Status</h3>

<?php
unset($output);
exec ("/var/www/html/tpm2/getcapability -cap 6 -pr 200 -pc 1", $output, $retval);
$capitems = explode(" ", trim($output[2]));
$val = hexdec($capitems[3]);
if ($val & 0x0001) {
    echo "Owner auth set<br>\n";
}
else {
    echo "Owner auth clear<br>\n";
}
if ($val & 0x0002) {
    echo "Endorsement auth set<br>\n";
}
else {
    echo "Endorsement auth clear<br>\n";
}
if ($val & 0x0004) {
    echo "Lockout auth set<br>\n";
}
else {
    echo "Lockout auth clear<br>\n";
}
if ($val & 0x0100) {
    echo "TPM2_Clear disabled<br>\n";
}
else {
    echo "TPM2_Clear enabled<br>\n";
}
if ($val & 0x0200) {
    echo "In lockout<br>\n";
}
else {
    echo "Not in lockout<br>\n";
}
if ($val & 0x0400) {
    echo "TPM generated EPS<br>\n";
}
else {
    echo "EPS createed outside TPM<br>\n";
}
echo "<br>\n";
unset($output);
exec ("/var/www/html/tpm2/getcapability -cap 6 -pr 201 -pc 1", $output, $retval);
$capitems = explode(" ", trim($output[2]));
$val = hexdec($capitems[3]);
if ($val & 0x0001) {
    echo "Platform hierarchy enabled<br>\n";
}
else {
    echo "Platform hierarchy disabled<br>\n";
}
if ($val & 0x0002) {
    echo "Storage hierarchy enabled &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"SH disable\"><br>\n";
}
else {
    echo "Storage hierarchy disabled &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"SH enable\"><br>\n";
}
if ($val & 0x0004) {
    echo "Endorsement hierarchy enabled &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"EH disable\"><br>\n";
}
else {
    echo "Endorsement hierarchy disabled &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"EH enable\"><br>\n";
}
if ($val & 0x0008) {
    echo "phEnableNV set &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"phEnableNV clear\"><br>\n";
}
else {
    echo "phEnableNV clear &nbsp;&nbsp;&nbsp; <input type=\"submit\" name=\"command\" value=\"phEnableNV set\"><br>\n";
}
?>

<h3>TPM Random Number Generator</h3>

<?php
unset($output);
exec ("/var/www/html/tpm2/getrandom -by 16 -of rng.tmp", $output, $retval);
$rngbinary = file_get_contents ("rng.tmp");
$rngstring = bin2hex ($rngbinary);
echo "Random number: " . $rngstring. "<br>\n";
unlink ('rng.tmp');

function searchForValue($keyword, $arrayToSearch){
    foreach($arrayToSearch as $key => $arrayItem){
        if( stristr( $arrayItem, $keyword ) ){
            return $key;
        }
    }
}

?>

<h3>TPM Authorization</h3>

<input type="radio" name="hip" value="p"
     <?php if ($hip == "p") echo " checked"; ?>>Platform
<input type="radio" name="hip" value="o"
     <?php if (($hip == "o") || !isset($hip)) echo " checked"; ?>>Owner
<br>     
Old Password <input type="password" name="pwda" value="<?php echo $pwdn1; ?>"><br>
New Password <input type="password" name="pwdn1" value="<?php echo $pwdn1; ?>"><br>
New Password <input type="password" name="pwdn2" value="<?php echo $pwdn1; ?>"><br>

<input type="submit" name="command" value="Change Password"><br>

</div>

<?php
require '/var/www/html/tpm2/footer.html';
?>

</body>
</html>