1 2 /* 3 * Licensed Materials - Property of IBM 4 * 5 * trousers - An open source TCG Software Stack 6 * 7 * (C) Copyright International Business Machines Corp. 2004-2007 8 * 9 */ 10 11 #include <stdlib.h> 12 #include <stdio.h> 13 #include <string.h> 14 #include <inttypes.h> 15 16 #include "trousers/tss.h" 17 #include "trousers/trousers.h" 18 #include "trousers_types.h" 19 #include "spi_utils.h" 20 #include "capabilities.h" 21 #include "tsplog.h" 22 #include "obj.h" 23 24 25 #ifdef TSS_BUILD_TRANSPORT 26 TSS_RESULT 27 Transport_Quote(TSS_HCONTEXT tspContext, /* in */ 28 TCS_KEY_HANDLE keyHandle, /* in */ 29 TCPA_NONCE *antiReplay, /* in */ 30 UINT32 pcrDataSizeIn, /* in */ 31 BYTE * pcrDataIn, /* in */ 32 TPM_AUTH * privAuth, /* in, out */ 33 UINT32 * pcrDataSizeOut, /* out */ 34 BYTE ** pcrDataOut, /* out */ 35 UINT32 * sigSize, /* out */ 36 BYTE ** sig) /* out */ 37 { 38 TSS_RESULT result; 39 UINT32 handlesLen, dataLen, decLen; 40 TCS_HANDLE *handles, handle; 41 BYTE *dec = NULL; 42 TPM_DIGEST pubKeyHash; 43 Trspi_HashCtx hashCtx; 44 UINT64 offset; 45 BYTE *data; 46 47 48 if ((result = obj_context_transport_init(tspContext))) 49 return result; 50 51 LogDebugFn("Executing in a transport session"); 52 53 if ((result = obj_tcskey_get_pubkeyhash(keyHandle, pubKeyHash.digest))) 54 return result; 55 56 result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1); 57 result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash.digest); 58 if ((result |= Trspi_HashFinal(&hashCtx, pubKeyHash.digest))) 59 return result; 60 61 handlesLen = 1; 62 handle = keyHandle; 63 handles = &handle; 64 65 dataLen = sizeof(TCPA_NONCE) + pcrDataSizeIn; 66 if ((data = malloc(dataLen)) == NULL) { 67 LogError("malloc of %u bytes failed", dataLen); 68 return TSPERR(TSS_E_OUTOFMEMORY); 69 } 70 71 offset = 0; 72 Trspi_LoadBlob_NONCE(&offset, data, antiReplay); 73 Trspi_LoadBlob(&offset, pcrDataSizeIn, data, pcrDataIn); 74 75 if ((result = obj_context_transport_execute(tspContext, TPM_ORD_Quote, dataLen, data, 76 &pubKeyHash, &handlesLen, &handles, 77 privAuth, NULL, &decLen, &dec))) { 78 free(data); 79 return result; 80 } 81 free(data); 82 83 offset = 0; 84 Trspi_UnloadBlob_PCR_COMPOSITE(&offset, dec, NULL); 85 *pcrDataSizeOut = offset; 86 87 if ((*pcrDataOut = malloc(*pcrDataSizeOut)) == NULL) { 88 free(dec); 89 LogError("malloc of %u bytes failed", *pcrDataSizeOut); 90 *pcrDataSizeOut = 0; 91 return TSPERR(TSS_E_OUTOFMEMORY); 92 } 93 94 offset = 0; 95 Trspi_UnloadBlob(&offset, *pcrDataSizeOut, dec, *pcrDataOut); 96 Trspi_UnloadBlob_UINT32(&offset, sigSize, dec); 97 98 if ((*sig = malloc(*sigSize)) == NULL) { 99 free(*pcrDataOut); 100 *pcrDataOut = NULL; 101 *pcrDataSizeOut = 0; 102 free(dec); 103 LogError("malloc of %u bytes failed", *sigSize); 104 *sigSize = 0; 105 return TSPERR(TSS_E_OUTOFMEMORY); 106 } 107 Trspi_UnloadBlob(&offset, *sigSize, dec, *sig); 108 109 free(dec); 110 111 return result; 112 } 113 #endif 114 115