UnitTest/TestSpdmRequester/TestSpdmRequesterGetMeasurement.c
void TestSpdmRequesterGetMeasurementCase22(void **state) {
  RETURN_STATUS        Status;
  SPDM_TEST_CONTEXT    *SpdmTestContext;
  SPDM_DEVICE_CONTEXT  *SpdmContext;
  UINT8                NumberOfBlock;
  UINT32               MeasurementRecordLength;
  UINT8                MeasurementRecord[MAX_SPDM_MEASUREMENT_RECORD_SIZE];
  UINT8                RequestAttribute;
  VOID                 *Data;
  UINTN                DataSize;
  VOID                 *Hash;
  UINTN                HashSize;
  UINTN                NumberOfMessages;
  #define TOTAL_MESSAGES 100

  SpdmTestContext = *state;
  SpdmContext = SpdmTestContext->SpdmContext;
  SpdmTestContext->CaseId = 0x16;
  SpdmContext->ConnectionInfo.Version.SpdmVersionCount = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MajorVersion = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MinorVersion = 1;
  SpdmContext->ConnectionInfo.ConnectionState = SpdmConnectionStateAuthenticated;
  SpdmContext->ConnectionInfo.Capability.Flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
  ReadResponderPublicCertificateChain (mUseHashAlgo, mUseAsymAlgo, &Data, &DataSize, &Hash, &HashSize);
  SpdmContext->Transcript.MessageM.BufferSize = 0;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementSpec = mUseMeasurementSpec;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementHashAlgo = mUseMeasurementHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseHashAlgo = mUseHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseAsymAlgo = mUseAsymAlgo;
  SpdmContext->ConnectionInfo.PeerUsedCertChainBufferSize = DataSize;
  CopyMem (SpdmContext->ConnectionInfo.PeerUsedCertChainBuffer, Data, DataSize);
  RequestAttribute = 0;

  MeasurementRecordLength = sizeof(MeasurementRecord);
  for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES; NumberOfMessages++) {
    Status = SpdmGetMeasurement (SpdmContext, NULL, RequestAttribute, 1, 0, &NumberOfBlock, &MeasurementRecordLength, MeasurementRecord);
    // It may fail due to Transcript.MessageM overflow
    if (Status == RETURN_SUCCESS) {
      assert_int_equal (SpdmContext->Transcript.MessageM.BufferSize, NumberOfMessages * (sizeof(SPDM_MESSAGE_HEADER) + sizeof(SPDM_MEASUREMENTS_RESPONSE) + sizeof(SPDM_MEASUREMENT_BLOCK_DMTF) + GetSpdmMeasurementHashSize (mUseMeasurementHashAlgo) + sizeof(UINT16)));
    } else {
      assert_int_equal (SpdmContext->Transcript.MessageM.BufferSize, 0);
      break;
    }
  }
  free(Data);
}
/**
  Test 22: request a large number of unsigned measurements before requesting a signature
  Expected Behavior: RETURN_SUCCESS return code and correct Transcript.MessageM.BufferSize while Transcript.MessageM has room; RETURN_DEVICE_ERROR otherwise
**/
Test 22: request a large number of unsigned measurements before requesting a signature
Expected Behavior: RETURN_SUCCESS return code and correct Transcript.MessageM.BufferSize while Transcript.MessageM has room; RETURN_DEVICE_ERROR otherwise
Test 22 : request a large number of unsigned measurements before requesting a signature Expected Behavior : RETURN_SUCCESS return code and correct Transcript . MessageM . BufferSize while Transcript . MessageM has room ; RETURN_DEVICE_ERROR otherwise
void TestSpdmRequesterGetMeasurementCase22(void **state) {
  RETURN_STATUS        Status;
  SPDM_TEST_CONTEXT    *SpdmTestContext;
  SPDM_DEVICE_CONTEXT  *SpdmContext;
  UINT8                NumberOfBlock;
  UINT32               MeasurementRecordLength;
  UINT8                MeasurementRecord[MAX_SPDM_MEASUREMENT_RECORD_SIZE];
  UINT8                RequestAttribute;
  VOID                 *Data;
  UINTN                DataSize;
  VOID                 *Hash;
  UINTN                HashSize;
  UINTN                NumberOfMessages;
  #define TOTAL_MESSAGES 100
  SpdmTestContext = *state;
  SpdmContext = SpdmTestContext->SpdmContext;
  SpdmTestContext->CaseId = 0x16;
  SpdmContext->ConnectionInfo.Version.SpdmVersionCount = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MajorVersion = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MinorVersion = 1;
  SpdmContext->ConnectionInfo.ConnectionState = SpdmConnectionStateAuthenticated;
  SpdmContext->ConnectionInfo.Capability.Flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
  ReadResponderPublicCertificateChain (mUseHashAlgo, mUseAsymAlgo, &Data, &DataSize, &Hash, &HashSize);
  SpdmContext->Transcript.MessageM.BufferSize = 0;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementSpec = mUseMeasurementSpec;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementHashAlgo = mUseMeasurementHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseHashAlgo = mUseHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseAsymAlgo = mUseAsymAlgo;
  SpdmContext->ConnectionInfo.PeerUsedCertChainBufferSize = DataSize;
  CopyMem (SpdmContext->ConnectionInfo.PeerUsedCertChainBuffer, Data, DataSize);
  RequestAttribute = 0;
  MeasurementRecordLength = sizeof(MeasurementRecord);
  for (NumberOfMessages = 1; NumberOfMessages <= TOTAL_MESSAGES; NumberOfMessages++) {
    Status = SpdmGetMeasurement (SpdmContext, NULL, RequestAttribute, 1, 0, &NumberOfBlock, &MeasurementRecordLength, MeasurementRecord);
    if (Status == RETURN_SUCCESS) {
      assert_int_equal (SpdmContext->Transcript.MessageM.BufferSize, NumberOfMessages * (sizeof(SPDM_MESSAGE_HEADER) + sizeof(SPDM_MEASUREMENTS_RESPONSE) + sizeof(SPDM_MEASUREMENT_BLOCK_DMTF) + GetSpdmMeasurementHashSize (mUseMeasurementHashAlgo) + sizeof(UINT16)));
    } else {
      assert_int_equal (SpdmContext->Transcript.MessageM.BufferSize, 0);
      break;
    }
  }
  free(Data);
}
void TestSpdmRequesterGetMeasurementCase22 ( void * * state ) { RETURN_STATUS Status ; SPDM_TEST_CONTEXT * SpdmTestContext ; SPDM_DEVICE_CONTEXT * SpdmContext ; UINT8 NumberOfBlock ; UINT32 MeasurementRecordLength ; UINT8 MeasurementRecord [ MAX_SPDM_MEASUREMENT_RECORD_SIZE ] ; UINT8 RequestAttribute ; VOID * Data ; UINTN DataSize ; VOID * Hash ; UINTN HashSize ; UINTN NumberOfMessages ; #define TOTAL_MESSAGES  100
 SpdmTestContext = * state ; SpdmContext = SpdmTestContext -> SpdmContext ; SpdmTestContext -> CaseId = 0x16 ; SpdmContext -> ConnectionInfo . Version . SpdmVersionCount = 1 ; SpdmContext -> ConnectionInfo . Version . SpdmVersion [ 0 ] . MajorVersion = 1 ; SpdmContext -> ConnectionInfo . Version . SpdmVersion [ 0 ] . MinorVersion = 1 ; SpdmContext -> ConnectionInfo . ConnectionState = SpdmConnectionStateAuthenticated ; SpdmContext -> ConnectionInfo . Capability . Flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG ; ReadResponderPublicCertificateChain ( mUseHashAlgo , mUseAsymAlgo , & Data , & DataSize , & Hash , & HashSize ) ; SpdmContext -> Transcript . MessageM . BufferSize = 0 ; SpdmContext -> ConnectionInfo . Algorithm . MeasurementSpec = mUseMeasurementSpec ; SpdmContext -> ConnectionInfo . Algorithm . MeasurementHashAlgo = mUseMeasurementHashAlgo ; SpdmContext -> ConnectionInfo . Algorithm . BaseHashAlgo = mUseHashAlgo ; SpdmContext -> ConnectionInfo . Algorithm . BaseAsymAlgo = mUseAsymAlgo ; SpdmContext -> ConnectionInfo . PeerUsedCertChainBufferSize = DataSize ; CopyMem ( SpdmContext -> ConnectionInfo . PeerUsedCertChainBuffer , Data , DataSize ) ; RequestAttribute = 0 ; MeasurementRecordLength = sizeof ( MeasurementRecord ) ; for ( NumberOfMessages = 1 ; NumberOfMessages <= TOTAL_MESSAGES ; NumberOfMessages ++ ) { Status = SpdmGetMeasurement ( SpdmContext , NULL , RequestAttribute , 1 , 0 , & NumberOfBlock , & MeasurementRecordLength , MeasurementRecord ) ; if ( Status == RETURN_SUCCESS ) { assert_int_equal ( SpdmContext -> Transcript . MessageM . BufferSize , NumberOfMessages * ( sizeof ( SPDM_MESSAGE_HEADER ) + sizeof ( SPDM_MEASUREMENTS_RESPONSE ) + sizeof ( SPDM_MEASUREMENT_BLOCK_DMTF ) + GetSpdmMeasurementHashSize ( mUseMeasurementHashAlgo ) + sizeof ( UINT16 ) ) ) ; } else { assert_int_equal ( SpdmContext -> Transcript . MessageM . BufferSize , 0 ) ; break ; } } free ( Data ) ; }
Test 22: request a large number of unsigned measurements before requesting a signature
Expected Behavior: RETURN_SUCCESS return code and correct Transcript.MessageM.BufferSize while Transcript.MessageM has room; RETURN_DEVICE_ERROR otherwise
Test 22 : request a large number of unsigned measurements before requesting a signature Expected Behavior : RETURN_SUCCESS return code and correct Transcript . MessageM . BufferSize while Transcript . MessageM has room ; RETURN_DEVICE_ERROR otherwise
// It may fail due to Transcript.MessageM overflow
