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 <syslog.h> 14#include <string.h> 15#include <netdb.h> 16 17#include "trousers/tss.h" 18#include "trousers_types.h" 19#include "tcs_tsp.h" 20#include "tcs_utils.h" 21#include "tcs_int_literals.h" 22#include "capabilities.h" 23#include "tcslog.h" 24#include "tcsd_wrap.h" 25#include "tcsd.h" 26#include "tcs_utils.h" 27#include "rpc_tcstp_tcs.h" 28 29 30TSS_RESULT 31tcs_wrap_SetOrdinalAuditStatus(struct tcsd_thread_data *data) 32{ 33 TCS_CONTEXT_HANDLE hContext; 34 TPM_AUTH ownerAuth; 35 UINT32 ulOrdinal; 36 TSS_BOOL bAuditState; 37 TSS_RESULT result; 38 39 if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm)) 40 return TCSERR(TSS_E_INTERNAL_ERROR); 41 42 LogDebugFn("thread %ld context %x", THREAD_ID, hContext); 43 44 if (getData(TCSD_PACKET_TYPE_UINT32, 1, &ulOrdinal, 0, &data->comm)) 45 return TCSERR(TSS_E_INTERNAL_ERROR); 46 47 if (getData(TCSD_PACKET_TYPE_BOOL, 2, &bAuditState, 0, &data->comm)) 48 return TCSERR(TSS_E_INTERNAL_ERROR); 49 50 if (getData(TCSD_PACKET_TYPE_AUTH, 3, &ownerAuth, 0, &data->comm)) 51 return TCSERR(TSS_E_INTERNAL_ERROR); 52 53 MUTEX_LOCK(tcsp_lock); 54 55 result = TCSP_SetOrdinalAuditStatus_Internal(hContext, &ownerAuth, ulOrdinal, bAuditState); 56 57 MUTEX_UNLOCK(tcsp_lock); 58 59 if (result == TSS_SUCCESS) { 60 initData(&data->comm, 1); 61 if (setData(TCSD_PACKET_TYPE_AUTH, 0, &ownerAuth, 0, &data->comm)) 62 return TCSERR(TSS_E_INTERNAL_ERROR); 63 } else 64 initData(&data->comm, 0); 65 66 data->comm.hdr.u.result = result; 67 68 return TSS_SUCCESS; 69} 70 71TSS_RESULT 72tcs_wrap_GetAuditDigest(struct tcsd_thread_data *data) 73{ 74 TCS_CONTEXT_HANDLE hContext; 75 UINT32 startOrdinal; 76 TPM_DIGEST auditDigest; 77 UINT32 counterValueSize; 78 BYTE *counterValue; 79 TSS_BOOL more; 80 UINT32 ordSize; 81 UINT32 *ordList; 82 TSS_RESULT result; 83 84 if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm)) 85 return TCSERR(TSS_E_INTERNAL_ERROR); 86 87 LogDebugFn("thread %ld context %x", THREAD_ID, hContext); 88 89 if (getData(TCSD_PACKET_TYPE_UINT32, 1, &startOrdinal, 0, &data->comm)) 90 return TCSERR(TSS_E_INTERNAL_ERROR); 91 92 MUTEX_LOCK(tcsp_lock); 93 94 result = TCSP_GetAuditDigest_Internal(hContext, startOrdinal, &auditDigest, &counterValueSize, &counterValue, 95 &more, &ordSize, &ordList); 96 97 MUTEX_UNLOCK(tcsp_lock); 98 99 if (result == TSS_SUCCESS) { 100 initData(&data->comm, 6); 101 if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &auditDigest, 0, &data->comm)) { 102 free(counterValue); 103 free(ordList); 104 return TCSERR(TSS_E_INTERNAL_ERROR); 105 } 106 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &counterValueSize, 0, &data->comm)) { 107 free(counterValue); 108 free(ordList); 109 return TCSERR(TSS_E_INTERNAL_ERROR); 110 } 111 if (setData(TCSD_PACKET_TYPE_PBYTE, 2, counterValue, counterValueSize, &data->comm)) { 112 free(counterValue); 113 free(ordList); 114 return TCSERR(TSS_E_INTERNAL_ERROR); 115 } 116 free(counterValue); 117 if (setData(TCSD_PACKET_TYPE_BOOL, 3, &more, 0, &data->comm)) { 118 free(ordList); 119 return TCSERR(TSS_E_INTERNAL_ERROR); 120 } 121 if (setData(TCSD_PACKET_TYPE_UINT32, 4, &ordSize, 0, &data->comm)) { 122 free(ordList); 123 return TCSERR(TSS_E_INTERNAL_ERROR); 124 } 125 if (setData(TCSD_PACKET_TYPE_PBYTE, 5, ordList, ordSize * sizeof(UINT32), &data->comm)) { 126 free(ordList); 127 return TCSERR(TSS_E_INTERNAL_ERROR); 128 } 129 free(ordList); 130 } else 131 initData(&data->comm, 0); 132 133 data->comm.hdr.u.result = result; 134 135 return TSS_SUCCESS; 136} 137 138TSS_RESULT 139tcs_wrap_GetAuditDigestSigned(struct tcsd_thread_data *data) 140{ 141 TCS_CONTEXT_HANDLE hContext; 142 TCS_KEY_HANDLE keyHandle; 143 TSS_BOOL closeAudit; 144 TPM_NONCE antiReplay; 145 TPM_AUTH privAuth, nullAuth, *pAuth; 146 UINT32 counterValueSize; 147 BYTE *counterValue; 148 TPM_DIGEST auditDigest; 149 TPM_DIGEST ordinalDigest; 150 UINT32 sigSize; 151 BYTE *sig; 152 TSS_RESULT result; 153 int i; 154 155 memset(&privAuth, 0, sizeof(TPM_AUTH)); 156 memset(&nullAuth, 0, sizeof(TPM_AUTH)); 157 158 if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm)) 159 return TCSERR(TSS_E_INTERNAL_ERROR); 160 161 LogDebugFn("thread %ld context %x", THREAD_ID, hContext); 162 163 if (getData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &data->comm)) 164 return TCSERR(TSS_E_INTERNAL_ERROR); 165 if (getData(TCSD_PACKET_TYPE_BOOL, 2, &closeAudit, 0, &data->comm)) 166 return TCSERR(TSS_E_INTERNAL_ERROR); 167 if (getData(TCSD_PACKET_TYPE_NONCE, 3, &antiReplay, 0, &data->comm)) 168 return TCSERR(TSS_E_INTERNAL_ERROR); 169 if (getData(TCSD_PACKET_TYPE_AUTH, 4, &privAuth, 0, &data->comm)) 170 return TCSERR(TSS_E_INTERNAL_ERROR); 171 172 if (memcmp(&nullAuth, &privAuth, sizeof(TPM_AUTH))) 173 pAuth = &privAuth; 174 else 175 pAuth = NULL; 176 177 MUTEX_LOCK(tcsp_lock); 178 179 result = TCSP_GetAuditDigestSigned_Internal(hContext, keyHandle, closeAudit, antiReplay, 180 pAuth, &counterValueSize, &counterValue, 181 &auditDigest, &ordinalDigest, 182 &sigSize, &sig); 183 184 MUTEX_UNLOCK(tcsp_lock); 185 186 if (result == TSS_SUCCESS) { 187 i = 0; 188 initData(&data->comm, 7); 189 if (pAuth) { 190 if (setData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &data->comm)) { 191 free(counterValue); 192 free(sig); 193 return TCSERR(TSS_E_INTERNAL_ERROR); 194 } 195 } 196 if (setData(TCSD_PACKET_TYPE_UINT32, i++, &counterValueSize, 0, &data->comm)) { 197 free(counterValue); 198 free(sig); 199 return TCSERR(TSS_E_INTERNAL_ERROR); 200 } 201 if (setData(TCSD_PACKET_TYPE_PBYTE, i++, counterValue, counterValueSize, &data->comm)) { 202 free(counterValue); 203 free(sig); 204 return TCSERR(TSS_E_INTERNAL_ERROR); 205 } 206 free(counterValue); 207 if (setData(TCSD_PACKET_TYPE_DIGEST, i++, &auditDigest, 0, &data->comm)) { 208 free(sig); 209 return TCSERR(TSS_E_INTERNAL_ERROR); 210 } 211 if (setData(TCSD_PACKET_TYPE_DIGEST, i++, &ordinalDigest, 0, &data->comm)) { 212 free(sig); 213 return TCSERR(TSS_E_INTERNAL_ERROR); 214 } 215 if (setData(TCSD_PACKET_TYPE_UINT32, i++, &sigSize, 0, &data->comm)) { 216 free(sig); 217 return TCSERR(TSS_E_INTERNAL_ERROR); 218 } 219 if (setData(TCSD_PACKET_TYPE_PBYTE, i++, sig, sigSize, &data->comm)) { 220 free(sig); 221 return TCSERR(TSS_E_INTERNAL_ERROR); 222 } 223 free(sig); 224 } else 225 initData(&data->comm, 0); 226 227 data->comm.hdr.u.result = result; 228 229 return TSS_SUCCESS; 230} 231