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. 2007 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 "tsplog.h" 20#include "hosttable.h" 21#include "tcsd_wrap.h" 22#include "rpc_tcstp_tsp.h" 23 24 25TSS_RESULT 26RPC_SetOrdinalAuditStatus_TP(struct host_table_entry *hte, 27 TPM_AUTH *ownerAuth, /* in/out */ 28 UINT32 ulOrdinal, /* in */ 29 TSS_BOOL bAuditState) /* in */ 30{ 31 TSS_RESULT result; 32 33 initData(&hte->comm, 4); 34 hte->comm.hdr.u.ordinal = TCSD_ORD_SETORDINALAUDITSTATUS; 35 LogDebugFn("TCS Context: 0x%x", hte->tcsContext); 36 37 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) 38 return TSPERR(TSS_E_INTERNAL_ERROR); 39 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &ulOrdinal, 0, &hte->comm)) 40 return TSPERR(TSS_E_INTERNAL_ERROR); 41 if (setData(TCSD_PACKET_TYPE_BOOL, 2, &bAuditState, 0, &hte->comm)) 42 return TSPERR(TSS_E_INTERNAL_ERROR); 43 if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm)) 44 return TSPERR(TSS_E_INTERNAL_ERROR); 45 46 result = sendTCSDPacket(hte); 47 48 if (result == TSS_SUCCESS) 49 result = hte->comm.hdr.u.result; 50 51 if (result == TSS_SUCCESS) { 52 if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) 53 result = TSPERR(TSS_E_INTERNAL_ERROR); 54 } 55 56 return result; 57} 58 59TSS_RESULT 60RPC_GetAuditDigest_TP(struct host_table_entry *hte, 61 UINT32 startOrdinal, /* in */ 62 TPM_DIGEST *auditDigest, /* out */ 63 UINT32 *counterValueSize, /* out */ 64 BYTE **counterValue, /* out */ 65 TSS_BOOL *more, /* out */ 66 UINT32 *ordSize, /* out */ 67 UINT32 **ordList) /* out */ 68{ 69 TSS_RESULT result; 70 71 initData(&hte->comm, 2); 72 hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGEST; 73 LogDebugFn("TCS Context: 0x%x", hte->tcsContext); 74 75 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) 76 return TSPERR(TSS_E_INTERNAL_ERROR); 77 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &startOrdinal, 0, &hte->comm)) 78 return TSPERR(TSS_E_INTERNAL_ERROR); 79 80 result = sendTCSDPacket(hte); 81 82 if (result == TSS_SUCCESS) 83 result = hte->comm.hdr.u.result; 84 85 if (result == TSS_SUCCESS) { 86 if (getData(TCSD_PACKET_TYPE_DIGEST, 0, auditDigest, 0, &hte->comm)) { 87 result = TSPERR(TSS_E_INTERNAL_ERROR); 88 goto done; 89 } 90 if (getData(TCSD_PACKET_TYPE_UINT32, 1, counterValueSize, 0, &hte->comm)) { 91 result = TSPERR(TSS_E_INTERNAL_ERROR); 92 goto done; 93 } 94 *counterValue = (BYTE *)malloc(*counterValueSize); 95 if (*counterValue == NULL) { 96 LogError("malloc of %u bytes failed.", *counterValueSize); 97 result = TSPERR(TSS_E_OUTOFMEMORY); 98 goto done; 99 } 100 if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *counterValue, *counterValueSize, &hte->comm)) { 101 free(*counterValue); 102 *counterValue = NULL; 103 result = TSPERR(TSS_E_INTERNAL_ERROR); 104 goto done; 105 } 106 if (getData(TCSD_PACKET_TYPE_BOOL, 3, more, 0, &hte->comm)) { 107 free(*counterValue); 108 *counterValue = NULL; 109 result = TSPERR(TSS_E_INTERNAL_ERROR); 110 goto done; 111 } 112 if (getData(TCSD_PACKET_TYPE_UINT32, 4, ordSize, 0, &hte->comm)) { 113 free(*counterValue); 114 *counterValue = NULL; 115 result = TSPERR(TSS_E_INTERNAL_ERROR); 116 goto done; 117 } 118 *ordList = (UINT32 *)malloc(*ordSize * sizeof(UINT32)); 119 if (*ordList == NULL) { 120 LogError("malloc of %u bytes failed.", *ordSize); 121 free(*counterValue); 122 *counterValue = NULL; 123 result = TSPERR(TSS_E_OUTOFMEMORY); 124 goto done; 125 } 126 if (getData(TCSD_PACKET_TYPE_PBYTE, 5, *ordList, *ordSize * sizeof(UINT32), &hte->comm)) { 127 free(*counterValue); 128 *counterValue = NULL; 129 free(*ordList); 130 *ordList = NULL; 131 result = TSPERR(TSS_E_INTERNAL_ERROR); 132 goto done; 133 } 134 } 135 136done: 137 return result; 138} 139 140TSS_RESULT 141RPC_GetAuditDigestSigned_TP(struct host_table_entry *hte, 142 TCS_KEY_HANDLE keyHandle, /* in */ 143 TSS_BOOL closeAudit, /* in */ 144 TPM_NONCE *antiReplay, /* in */ 145 TPM_AUTH *privAuth, /* in/out */ 146 UINT32 *counterValueSize, /* out */ 147 BYTE **counterValue, /* out */ 148 TPM_DIGEST *auditDigest, /* out */ 149 TPM_DIGEST *ordinalDigest, /* out */ 150 UINT32 *sigSize, /* out */ 151 BYTE **sig) /* out */ 152{ 153 TSS_RESULT result; 154 TPM_AUTH null_auth; 155 int i; 156 157 initData(&hte->comm, 5); 158 hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGESTSIGNED; 159 LogDebugFn("TCS Context: 0x%x", hte->tcsContext); 160 161 memset(&null_auth, 0, sizeof(TPM_AUTH)); 162 163 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm)) 164 return TSPERR(TSS_E_INTERNAL_ERROR); 165 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm)) 166 return TSPERR(TSS_E_INTERNAL_ERROR); 167 if (setData(TCSD_PACKET_TYPE_BOOL, 2, &closeAudit, 0, &hte->comm)) 168 return TSPERR(TSS_E_INTERNAL_ERROR); 169 if (setData(TCSD_PACKET_TYPE_NONCE, 3, antiReplay, 0, &hte->comm)) 170 return TSPERR(TSS_E_INTERNAL_ERROR); 171 if (privAuth) { 172 if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm)) 173 return TSPERR(TSS_E_INTERNAL_ERROR); 174 } 175 else { 176 if (setData(TCSD_PACKET_TYPE_AUTH, 4, &null_auth, 0, &hte->comm)) 177 return TSPERR(TSS_E_INTERNAL_ERROR); 178 } 179 180 result = sendTCSDPacket(hte); 181 182 if (result == TSS_SUCCESS) 183 result = hte->comm.hdr.u.result; 184 185 if (result == TSS_SUCCESS) { 186 i = 0; 187 if (privAuth) { 188 if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) { 189 result = TSPERR(TSS_E_INTERNAL_ERROR); 190 goto done; 191 } 192 } 193 if (getData(TCSD_PACKET_TYPE_UINT32, i++, counterValueSize, 0, &hte->comm)) { 194 result = TSPERR(TSS_E_INTERNAL_ERROR); 195 goto done; 196 } 197 *counterValue = (BYTE *)malloc(*counterValueSize); 198 if (*counterValue == NULL) { 199 LogError("malloc of %u bytes failed.", *counterValueSize); 200 result = TSPERR(TSS_E_OUTOFMEMORY); 201 goto done; 202 } 203 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *counterValue, *counterValueSize, &hte->comm)) { 204 free(*counterValue); 205 result = TSPERR(TSS_E_INTERNAL_ERROR); 206 goto done; 207 } 208 if (getData(TCSD_PACKET_TYPE_DIGEST, i++, auditDigest, 0, &hte->comm)) { 209 free(*counterValue); 210 result = TSPERR(TSS_E_INTERNAL_ERROR); 211 goto done; 212 } 213 if (getData(TCSD_PACKET_TYPE_DIGEST, i++, ordinalDigest, 0, &hte->comm)) { 214 free(*counterValue); 215 result = TSPERR(TSS_E_INTERNAL_ERROR); 216 goto done; 217 } 218 if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) { 219 free(*counterValue); 220 result = TSPERR(TSS_E_INTERNAL_ERROR); 221 goto done; 222 } 223 *sig = (BYTE *)malloc(*sigSize); 224 if (*sig == NULL) { 225 LogError("malloc of %u bytes failed.", *sigSize); 226 free(*counterValue); 227 result = TSPERR(TSS_E_OUTOFMEMORY); 228 goto done; 229 } 230 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) { 231 free(*counterValue); 232 free(*sig); 233 result = TSPERR(TSS_E_INTERNAL_ERROR); 234 goto done; 235 } 236 } 237 238done: 239 return result; 240} 241