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-2006 8 * 9 */ 10 11#include <stdlib.h> 12#include <stdio.h> 13#include <string.h> 14#include <assert.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 "hosttable.h" 23#include "tcsd_wrap.h" 24#include "obj.h" 25#include "rpc_tcstp_tsp.h" 26 27 28TSS_RESULT 29RPC_DaaJoin_TP(struct host_table_entry *hte, 30 TPM_HANDLE handle, // in 31 BYTE stage, // in 32 UINT32 inputSize0, // in 33 BYTE* inputData0, // in 34 UINT32 inputSize1, // in 35 BYTE* inputData1, // in 36 TPM_AUTH* ownerAuth, // in/out 37 UINT32* outputSize, // out 38 BYTE** outputData) // out 39{ 40 TSS_RESULT result; 41 UINT32 i; 42 43 LogDebugFn("stage=%d", stage); 44 initData(&hte->comm, 8); 45 hte->comm.hdr.u.ordinal = TCSD_ORD_DAAJOIN; 46 LogDebugFn("TCS Context: 0x%x", hte->tcsContext); 47 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) 48 return TSPERR(TSS_E_INTERNAL_ERROR); 49 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm)) 50 return TSPERR(TSS_E_INTERNAL_ERROR); 51 if (setData(TCSD_PACKET_TYPE_BYTE, 2, &stage, 0, &hte->comm)) 52 return TSPERR(TSS_E_INTERNAL_ERROR); 53 if (setData(TCSD_PACKET_TYPE_UINT32, 3, &inputSize0, 0, &hte->comm)) 54 return TSPERR(TSS_E_INTERNAL_ERROR); 55 LogDebugFn("inputSize0=<network>=%d <host>=%d", inputSize0, inputSize0); 56 if (setData(TCSD_PACKET_TYPE_PBYTE, 4, inputData0, inputSize0, &hte->comm)) 57 return TSPERR(TSS_E_INTERNAL_ERROR); 58 if (setData(TCSD_PACKET_TYPE_UINT32, 5, &inputSize1, 0, &hte->comm)) 59 return TSPERR(TSS_E_INTERNAL_ERROR); 60 LogDebugFn("inputSize1=<network>=%d <host>=%d", inputSize1, inputSize1); 61 if (setData(TCSD_PACKET_TYPE_PBYTE, 6, inputData1, inputSize1, &hte->comm)) 62 return TSPERR(TSS_E_INTERNAL_ERROR); 63 if( ownerAuth) { 64 if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm)) 65 return TSPERR(TSS_E_INTERNAL_ERROR); 66 } 67 68 result = sendTCSDPacket(hte); 69 if (result == TSS_SUCCESS) 70 result = hte->comm.hdr.u.result; 71 72 if (result == TSS_SUCCESS) { 73 i = 0; 74 LogDebugFn("getData outputSize"); 75 76 if( ownerAuth) { 77 if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) { 78 result = TSPERR(TSS_E_INTERNAL_ERROR); 79 goto done; 80 } 81 } 82 if (getData(TCSD_PACKET_TYPE_UINT32, i++, outputSize, 0, &hte->comm)) { 83 result = TSPERR(TSS_E_INTERNAL_ERROR); 84 goto done; 85 } 86 *outputData = (BYTE *) malloc(*outputSize); 87 if (*outputData == NULL) { 88 LogError("malloc of %u bytes failed.", *outputSize); 89 result = TSPERR(TSS_E_OUTOFMEMORY); 90 goto done; 91 } 92 LogDebugFn("getData outputData (outputSize=%u)", *outputSize); 93 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outputData, *outputSize, &hte->comm)) { 94 free(*outputData); 95 *outputData = NULL; 96 result = TSPERR(TSS_E_INTERNAL_ERROR); 97 goto done; 98 } 99 } 100 101done: 102 LogDebugFn("result=%u", result); 103 return result; 104} 105 106TSS_RESULT 107RPC_DaaSign_TP(struct host_table_entry *hte, 108 TPM_HANDLE handle, // in 109 BYTE stage, // in 110 UINT32 inputSize0, // in 111 BYTE* inputData0, // in 112 UINT32 inputSize1, // in 113 BYTE* inputData1, // in 114 TPM_AUTH* ownerAuth, // in/out 115 UINT32* outputSize, // out 116 BYTE** outputData) // out 117{ 118 TSS_RESULT result; 119 UINT32 i; 120 121 LogDebugFn("stage=%d", stage); 122 initData(&hte->comm, 8); 123 hte->comm.hdr.u.ordinal = TCSD_ORD_DAASIGN; 124 LogDebugFn("TCS Context: 0x%x", hte->tcsContext); 125 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) 126 return TSPERR(TSS_E_INTERNAL_ERROR); 127 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm)) 128 return TSPERR(TSS_E_INTERNAL_ERROR); 129 if (setData(TCSD_PACKET_TYPE_BYTE, 2, &stage, 0, &hte->comm)) 130 return TSPERR(TSS_E_INTERNAL_ERROR); 131 if (setData(TCSD_PACKET_TYPE_UINT32, 3, &inputSize0, 0, &hte->comm)) 132 return TSPERR(TSS_E_INTERNAL_ERROR); 133 LogDebugFn("inputSize0=<network>=%d <host>=%d", inputSize0, inputSize0); 134 if (setData(TCSD_PACKET_TYPE_PBYTE, 4, inputData0, inputSize0, &hte->comm)) 135 return TSPERR(TSS_E_INTERNAL_ERROR); 136 if (setData(TCSD_PACKET_TYPE_UINT32, 5, &inputSize1, 0, &hte->comm)) 137 return TSPERR(TSS_E_INTERNAL_ERROR); 138 LogDebugFn("inputSize1=<network>=%d <host>=%d", inputSize1, inputSize1); 139 if (setData(TCSD_PACKET_TYPE_PBYTE, 6, inputData1, inputSize1, &hte->comm)) 140 return TSPERR(TSS_E_INTERNAL_ERROR); 141 if( ownerAuth) { 142 if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm)) 143 return TSPERR(TSS_E_INTERNAL_ERROR); 144 } 145 LogDebugFn("sendTCSDPacket: 0x%x", (int)hte); 146 result = sendTCSDPacket(hte); 147 // 148 if (result == TSS_SUCCESS) 149 result = hte->comm.hdr.u.result; 150 // 151 if (result == TSS_SUCCESS) { 152 i = 0; 153 LogDebugFn("getData outputSize"); 154 155 if( ownerAuth) { 156 if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm)) { 157 result = TSPERR(TSS_E_INTERNAL_ERROR); 158 goto done; 159 } 160 } 161 if (getData(TCSD_PACKET_TYPE_UINT32, i++, outputSize, 0, &hte->comm)) { 162 result = TSPERR(TSS_E_INTERNAL_ERROR); 163 goto done; 164 } 165 *outputData = (BYTE *) malloc(*outputSize); 166 if (*outputData == NULL) { 167 LogError("malloc of %u bytes failed.", *outputSize); 168 result = TSPERR(TSS_E_OUTOFMEMORY); 169 goto done; 170 } 171 LogDebugFn("getData outputData (outputSize=%d)", *outputSize); 172 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outputData, *outputSize, &hte->comm)) { 173 free(*outputData); 174 *outputData = NULL; 175 result = TSPERR(TSS_E_INTERNAL_ERROR); 176 goto done; 177 } 178 } 179 180done: 181 LogDebugFn("result=%u", result); 182 return result; 183} 184 185