Skip to content

Conversation

@aidangarske
Copy link
Contributor

@aidangarske aidangarske commented Jan 6, 2026

Description

This PR adds initial SPDM (Security Protocol and Data Model) support for TPM 2.0 per TCG TPM 2.0 Library Specification v1.84 and the TCG simulator reference specs and code. Including policy commands and session information capabilities.

Overview

The implementation provides SPDM functionality to support secure communication channels between host and TPM int the future, focusing on the supported commands from the TCG simulator for now.

  • PolicyTransportSPDM (0x1A1): Adds secure channel restrictions to policy sessions
  • Policy_AC_SendSelect (0x196): Policy command for AC send selection (optional)
  • GetCapability SPDM Session Info: Retrieves active SPDM session information
  • Removed deprecated commands: AC_GetCapability (0x194) and AC_Send (0x195) per TCG spec

Main Functions Created

Core API Functions

  • wolfTPM2_PolicyTransportSPDM() - Add SPDM transport policy to session

    • Adds secure channel restrictions to policy sessions
    • Supports optional requester and TPM key name parameters
    • Uses session's authHash algorithm for policy digest calculation
  • wolfTPM2_GetCapability_SPDMSessionInfo() - Get active SPDM session information

    • Retrieves list of active SPDM sessions with key names
    • Returns TPML_SPDM_SESSION_INFO structure
  • wolfTPM2_GetACHandles() - Discover Authenticated Controller handles

    • Discovers AC handles via GetCapability(TPM_CAP_HANDLES)
    • Handles pagination for large handle lists

Internal Functions

  • TPM2_PolicyTransportSPDM() - Low-level policy command implementation
  • TPM2_Policy_AC_SendSelect() - Policy AC send select command
  • TPM2_Packet_Append/ParseSPDMSessionInfo() - Marshaling/unmarshaling for SPDM structures
  • TPM2_Packet_Append/ParseSPDMSessionInfoList() - List marshaling functions

Key Implementation Details

Structures Added

  • TPMS_SPDM_SESSION_INFO: Contains requester and TPM key names for SPDM sessions
  • TPML_SPDM_SESSION_INFO: List of SPDM session information entries
  • PolicyTransportSPDM_In: Input structure for PolicyTransportSPDM command

Marshaling Support

Custom marshaling/unmarshaling functions implemented for:

  • TPM2B_NAME structures (used in SPDM session info)
  • TPMS_SPDM_SESSION_INFO structures
  • TPML_SPDM_SESSION_INFO lists

Testing

All functionality tested with TCG TPM simulator and example code:

  • AC Handle Discovery: Verified discovery of AC handles via GetCapability
  • PolicyTransportSPDM: Tested policy command execution and validation
  • GetCapability SPDM Session Info: Verified session info retrieval
  • Unit Tests: Added comprehensive unit tests for all SPDM functions
  • Example Validation: Created tcg_spdm example with full test suite

Added test script (examples/spdm/test_tcg_spdm.sh) with selective testing via command-line options.

Updated .github/workflows/make-test-swtpm.yml with --enable-spdm flag.

TODO:

  • Test with actual hardware / TCG spec simulator

@aidangarske aidangarske self-assigned this Jan 6, 2026
@dgarske dgarske self-requested a review January 6, 2026 23:42
@dgarske dgarske self-assigned this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants