tpm20¶
TPMCommandBuilder
¶
Builds TPM 2.0 command headers and payloads.
Source code in wintermute/cartridges/tpm20.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
build_command(command_code, parameters=b'')
staticmethod
¶
Build a complete TPM 2.0 command buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_code
|
TPMCommands
|
The TPM command to encode. |
required |
parameters
|
bytes
|
Optional parameter bytes appended after the header. |
b''
|
Returns:
| Type | Description |
|---|---|
bytes
|
Complete command buffer ready to send to the TPM. |
Source code in wintermute/cartridges/tpm20.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
TPMCommands
¶
Bases: Enum
TPM 2.0 Command Codes
Source code in wintermute/cartridges/tpm20.py
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 | |
TPMTransport
¶
Base class for communicating with TPM via /dev/tpm0 (or simulator).
Attributes:
| Name | Type | Description |
|---|---|---|
device_path |
Path to the TPM device file. |
Source code in wintermute/cartridges/tpm20.py
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 | |
send_command(command_bytes)
¶
Send raw command bytes to the TPM and return the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_bytes
|
bytes
|
Raw TPM command buffer to write. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw response bytes read from the TPM device. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If communication with the TPM device fails. |
Source code in wintermute/cartridges/tpm20.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
TPM_register
¶
Bases: Enum
TPM Registers
Source code in wintermute/cartridges/tpm20.py
43 44 45 46 47 48 49 50 51 | |
tpm20
¶
Main interface for executing and auditing TPM 2.0 commands.
Attributes:
| Name | Type | Description |
|---|---|---|
transport |
Transport layer for TPM communication. |
Source code in wintermute/cartridges/tpm20.py
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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
execute(command, parameters=b'')
¶
Execute a TPM command with given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
TPMCommands
|
The TPM 2.0 command to execute. |
required |
parameters
|
bytes
|
Raw parameter bytes for the command. |
b''
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw response bytes from the TPM. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If the transport layer fails. |
Source code in wintermute/cartridges/tpm20.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
fuzz_command(command, iterations=100, max_payload_size=1024)
¶
Fuzz a TPM 2.0 command with randomised payloads.
Builds valid TPM 2.0 headers for command but appends malformed,
random-length byte payloads generated via :func:os.urandom. Each
iteration catches :class:TPMException, :class:TimeoutError, and
:class:OSError to detect kernel driver crashes or TPM interface
locks on /dev/tpm0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
TPMCommands
|
The TPM command code to target. |
required |
iterations
|
int
|
Number of fuzz iterations to run. |
100
|
max_payload_size
|
int
|
Maximum random payload length in bytes. |
1024
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys:
- |
Raises:
| Type | Description |
|---|---|
ValueError
|
If iterations < 1 or max_payload_size < 1. |
Source code in wintermute/cartridges/tpm20.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
get_random(num_bytes)
¶
Get random bytes from the TPM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_bytes
|
int
|
Number of random bytes to retrieve (1-64). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw TPM response containing the random bytes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If num_bytes is outside the 1-64 range. |
TPMException
|
If communication fails. |
Source code in wintermute/cartridges/tpm20.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
nv_read(nv_index, size, offset=0)
¶
Read data from an NVRAM index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nv_index
|
int
|
The NV index handle (e.g. 0x01500000). |
required |
size
|
int
|
Number of bytes to read. |
required |
offset
|
int
|
Byte offset within the NV index to start reading. |
0
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw TPM response containing the NV data. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If communication fails or access is denied. |
Source code in wintermute/cartridges/tpm20.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
nv_write(nv_index, data, offset=0)
¶
Write data to an NVRAM index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nv_index
|
int
|
The NV index handle. |
required |
data
|
bytes
|
Bytes to write into the NV area. |
required |
offset
|
int
|
Byte offset within the NV index. |
0
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw TPM response. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If communication fails or access is denied. |
Source code in wintermute/cartridges/tpm20.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
read_public(handle)
¶
Read the public area of an object in the TPM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
int
|
The TPM object handle to read. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw TPM response containing the public area. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If communication fails. |
Source code in wintermute/cartridges/tpm20.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
start_auth_session(session_type=1, auth_hash=11)
¶
Start an authorization session on the TPM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_type
|
int
|
Session type byte (0x00=HMAC, 0x01=policy, 0x03=trial). |
1
|
auth_hash
|
int
|
Algorithm ID for the session hash (default SHA-256 = 0x000B). |
11
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw TPM response containing the session handle. |
Raises:
| Type | Description |
|---|---|
TPMException
|
If communication fails. |
Source code in wintermute/cartridges/tpm20.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
test_da_lockout(max_attempts=5)
¶
Verify dictionary-attack lockout protection by sending deliberate bad auths.
Sends up to max_attempts DictionaryAttackLockReset commands with
empty (unauthenticated) parameters. A properly configured TPM should
reject these and eventually enter DA lockout mode. If no rejection is
observed, the DA policy may be misconfigured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_attempts
|
int
|
Number of intentionally bad auth attempts to send. |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys:
- |
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_attempts is less than 1. |
TPMException
|
If a transport-level error occurs (not an auth failure). |
Source code in wintermute/cartridges/tpm20.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
test_pcr_state(pcr_index)
¶
Check a PCR bank for brittle or predictable states.
Reads the specified PCR and analyses the digest for patterns that indicate a weak or uninitialised measurement chain (all-zeros, all-ones, or repeating-byte values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pcr_index
|
int
|
The PCR register index to inspect (0-23). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys:
- |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pcr_index is outside the 0-23 range. |
TPMException
|
If communication with the TPM fails. |
Source code in wintermute/cartridges/tpm20.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |